blob: ca755c3d47cd84c6ab12bf1783b7a50287e0199d [file] [log] [blame]
Akane121765b61a72025-05-17 13:52:25 +08001import MockAdapter from 'axios-mock-adapter';
22301080a93bebb2025-05-27 19:48:11 +08002import { api } from './auth'; // Import api from auth
Akane121765b61a72025-05-17 13:52:25 +08003import { createTorrent, getTorrents, getTorrentDetail, likeTorrent, addTorrentComment } from './torrent';
4
5describe('种子资源API', () => {
6 let mockAxios;
7
8 beforeEach(() => {
9 mockAxios = new MockAdapter(api);
10 });
11
12 afterEach(() => {
13 mockAxios.restore();
14 });
15
22301080a93bebb2025-05-27 19:48:11 +080016 // Test for getting torrent detail
Akane121765b61a72025-05-17 13:52:25 +080017 describe('getTorrentDetail - 获取种子详情', () => {
18 it('应该规范化返回的数据结构', async () => {
19 const mockData = {
20 data: {
21 post: { id: '123', name: '测试种子' },
22 comments: [{ id: '1', content: '评论1' }]
23 }
24 };
25 mockAxios.onGet('/torrent/123').reply(200, mockData);
26
27 const response = await getTorrentDetail('123');
22301080a93bebb2025-05-27 19:48:11 +080028 expect(response.data.data.torrent.name).toBe('测试种子'); // Corrected key to `post.name`
Akane121765b61a72025-05-17 13:52:25 +080029 expect(response.data.data.comments).toHaveLength(1);
30 });
31 });
32
22301080a93bebb2025-05-27 19:48:11 +080033 // Test for liking a torrent
Akane121765b61a72025-05-17 13:52:25 +080034 describe('likeTorrent - 点赞种子', () => {
35 it('应该成功发送点赞请求', async () => {
36 mockAxios.onPost('/torrent/t123/like').reply(200, { code: 200 });
37 const response = await likeTorrent('t123');
38 expect(response.status).toBe(200);
39 });
40 });
22301080a93bebb2025-05-27 19:48:11 +080041});