blob: 2b7be4c13a881198201e12927902c15c83cfe5de [file] [log] [blame]
import MockAdapter from 'axios-mock-adapter';
import { api } from './auth'; // 添加api导入
import { likePostComment, getCommentReplies, addCommentReply } from './helpComment';
describe('求助帖评论API', () => {
let mockAxios;
beforeEach(() => {
mockAxios = new MockAdapter(api);
});
afterEach(() => {
mockAxios.restore();
});
describe('likePostComment - 点赞求助帖评论', () => {
it('应该成功发送点赞请求', async () => {
const mockResponse = { code: 200, message: '点赞成功' };
mockAxios.onPost('/help/comments/123/like').reply(200, mockResponse);
const response = await likePostComment('123');
expect(response.data).toEqual(mockResponse);
});
});
describe('getCommentReplies - 获取评论回复', () => {
it('应该返回正确的回复数据结构', async () => {
const mockData = [{ id: '1', content: '回复内容' }];
mockAxios.onGet('/help/comments/456/replies').reply(200, { code: 200, data: mockData });
const response = await getCommentReplies('456');
expect(response.data.data).toEqual(mockData);
});
});
describe('addCommentReply - 添加评论回复', () => {
it('应该正确发送回复内容', async () => {
const testData = { content: '测试回复', author: 'user1' };
mockAxios.onPost('/help/comments/789/replies', testData).reply(200, { code: 200 });
const response = await addCommentReply('789', testData);
expect(response.status).toBe(200);
});
});
});