blob: 2b7be4c13a881198201e12927902c15c83cfe5de [file] [log] [blame]
Akane121765b61a72025-05-17 13:52:25 +08001import MockAdapter from 'axios-mock-adapter';
2import { api } from './auth'; // 添加api导入
3import { likePostComment, getCommentReplies, addCommentReply } from './helpComment';
4
5describe('求助帖评论API', () => {
6 let mockAxios;
7
8 beforeEach(() => {
9 mockAxios = new MockAdapter(api);
10 });
11
12 afterEach(() => {
13 mockAxios.restore();
14 });
15
16 describe('likePostComment - 点赞求助帖评论', () => {
17 it('应该成功发送点赞请求', async () => {
18 const mockResponse = { code: 200, message: '点赞成功' };
19 mockAxios.onPost('/help/comments/123/like').reply(200, mockResponse);
20
21 const response = await likePostComment('123');
22 expect(response.data).toEqual(mockResponse);
23 });
24 });
25
26 describe('getCommentReplies - 获取评论回复', () => {
27 it('应该返回正确的回复数据结构', async () => {
28 const mockData = [{ id: '1', content: '回复内容' }];
29 mockAxios.onGet('/help/comments/456/replies').reply(200, { code: 200, data: mockData });
30
31 const response = await getCommentReplies('456');
32 expect(response.data.data).toEqual(mockData);
33 });
34 });
35
36 describe('addCommentReply - 添加评论回复', () => {
37 it('应该正确发送回复内容', async () => {
38 const testData = { content: '测试回复', author: 'user1' };
39 mockAxios.onPost('/help/comments/789/replies', testData).reply(200, { code: 200 });
40
41 const response = await addCommentReply('789', testData);
42 expect(response.status).toBe(200);
43 });
44 });
45});