Akane1217 | 65b61a7 | 2025-05-17 13:52:25 +0800 | [diff] [blame] | 1 | import MockAdapter from 'axios-mock-adapter';
|
22301080 | a93bebb | 2025-05-27 19:48:11 +0800 | [diff] [blame] | 2 | import { api } from './auth'; // Import api from auth
|
Akane1217 | 65b61a7 | 2025-05-17 13:52:25 +0800 | [diff] [blame] | 3 | import { createTorrent, getTorrents, getTorrentDetail, likeTorrent, addTorrentComment } from './torrent';
|
| 4 |
|
| 5 | describe('种子资源API', () => {
|
| 6 | let mockAxios;
|
| 7 |
|
| 8 | beforeEach(() => {
|
| 9 | mockAxios = new MockAdapter(api);
|
| 10 | });
|
| 11 |
|
| 12 | afterEach(() => {
|
| 13 | mockAxios.restore();
|
| 14 | });
|
| 15 |
|
22301080 | a93bebb | 2025-05-27 19:48:11 +0800 | [diff] [blame] | 16 | // Test for getting torrent detail
|
Akane1217 | 65b61a7 | 2025-05-17 13:52:25 +0800 | [diff] [blame] | 17 | 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');
|
22301080 | a93bebb | 2025-05-27 19:48:11 +0800 | [diff] [blame] | 28 | expect(response.data.data.torrent.name).toBe('测试种子'); // Corrected key to `post.name`
|
Akane1217 | 65b61a7 | 2025-05-17 13:52:25 +0800 | [diff] [blame] | 29 | expect(response.data.data.comments).toHaveLength(1);
|
| 30 | });
|
| 31 | });
|
| 32 |
|
22301080 | a93bebb | 2025-05-27 19:48:11 +0800 | [diff] [blame] | 33 | // Test for liking a torrent
|
Akane1217 | 65b61a7 | 2025-05-17 13:52:25 +0800 | [diff] [blame] | 34 | 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 | });
|
22301080 | a93bebb | 2025-05-27 19:48:11 +0800 | [diff] [blame] | 41 | });
|