合并
Change-Id: I19ca58c58a513cba20c162c9ed7cbab90e060bf6
diff --git a/src/api/helpComment.test.js b/src/api/helpComment.test.js
index 2b7be4c..a4a7d99 100644
--- a/src/api/helpComment.test.js
+++ b/src/api/helpComment.test.js
@@ -1,6 +1,6 @@
import MockAdapter from 'axios-mock-adapter';
import { api } from './auth'; // 添加api导入
-import { likePostComment, getCommentReplies, addCommentReply } from './helpComment';
+import { likePostComment, getCommentReplies, addCommentReply, deleteComment } from './helpComment';
describe('求助帖评论API', () => {
let mockAxios;
@@ -34,11 +34,53 @@
});
describe('addCommentReply - 添加评论回复', () => {
- it('应该正确发送回复内容', async () => {
- const testData = { content: '测试回复', author: 'user1' };
- mockAxios.onPost('/help/comments/789/replies', testData).reply(200, { code: 200 });
+ it('应该正确发送回复内容(无图片)', async () => {
+ const commentId = '789';
+ const replyData = {
+ authorId: 'user1',
+ content: '测试回复'
+ };
+
+ mockAxios.onPost(`/help/comments/${commentId}/replies`).reply(config => {
+ const data = config.data;
+ expect(data.get('authorId')).toBe(replyData.authorId);
+ expect(data.get('content')).toBe(replyData.content);
+ expect(data.has('image')).toBe(false);
+ return [200, { code: 200 }];
+ });
- const response = await addCommentReply('789', testData);
+ const response = await addCommentReply(commentId, replyData);
+ expect(response.status).toBe(200);
+ });
+ it('应该正确处理带图片的回复', async () => {
+ const commentId = '789';
+ const replyData = {
+ authorId: 'user1',
+ content: '测试回复',
+ image: new File(['content'], 'reply.jpg')
+ };
+
+ mockAxios.onPost(`/help/comments/${commentId}/replies`).reply(config => {
+ const data = config.data;
+ expect(data.get('image')).toBeInstanceOf(File);
+ return [200, { code: 200 }];
+ });
+
+ const response = await addCommentReply(commentId, replyData);
+ expect(response.status).toBe(200);
+ });
+ });
+ describe('deleteComment - 删除评论', () => {
+ it('应该正确发送删除请求', async () => {
+ const commentId = '101112';
+ const authorId = 'user1';
+
+ mockAxios.onDelete(`/help/comments/${commentId}`).reply(config => {
+ expect(config.params).toEqual({ authorId });
+ return [200, { code: 200 }];
+ });
+
+ const response = await deleteComment(commentId, authorId);
expect(response.status).toBe(200);
});
});