blob: c4de6c5608c0a305f4307fd9f6dff4f4dc83d3ec [file] [log] [blame]
Akane121765b61a72025-05-17 13:52:25 +08001import MockAdapter from 'axios-mock-adapter';
2import { api } from './auth'; // 添加api导入
3import { 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
16 describe('createTorrent - 创建种子', () => {
17 it('应该发送完整的种子数据', async () => {
18 const torrentData = {
19 torrentName: '测试种子',
20 description: '描述内容',
21 username: 'user1',
22 category: '电影',
23 region: '美国',
24 resolution: '1080p',
25 subtitle: '中文字幕',
26 filePath: '/path/to/file'
27 };
28 mockAxios.onPost('/torrent', torrentData).reply(201, { code: 201 });
29
30 const response = await createTorrent(...Object.values(torrentData));
31 expect(response.status).toBe(201);
32 });
33 });
34
35 describe('getTorrentDetail - 获取种子详情', () => {
36 it('应该规范化返回的数据结构', async () => {
37 const mockData = {
38 data: {
39 post: { id: '123', name: '测试种子' },
40 comments: [{ id: '1', content: '评论1' }]
41 }
42 };
43 mockAxios.onGet('/torrent/123').reply(200, mockData);
44
45 const response = await getTorrentDetail('123');
46 expect(response.data.data.torrent.name).toBe('测试种子');
47 expect(response.data.data.comments).toHaveLength(1);
48 });
49 });
50
51 describe('likeTorrent - 点赞种子', () => {
52 it('应该成功发送点赞请求', async () => {
53 mockAxios.onPost('/torrent/t123/like').reply(200, { code: 200 });
54 const response = await likeTorrent('t123');
55 expect(response.status).toBe(200);
56 });
57 });
58});