/ clis / douyin / videos.test.js
videos.test.js
 1  import { beforeEach, describe, expect, it, vi } from 'vitest';
 2  const { browserFetchMock } = vi.hoisted(() => ({
 3      browserFetchMock: vi.fn(),
 4  }));
 5  vi.mock('./_shared/browser-fetch.js', () => ({
 6      browserFetch: browserFetchMock,
 7  }));
 8  import { getRegistry } from '@jackwener/opencli/registry';
 9  import './videos.js';
10  describe('douyin videos', () => {
11      beforeEach(() => {
12          browserFetchMock.mockReset();
13      });
14      it('registers the videos command', () => {
15          const registry = getRegistry();
16          const values = [...registry.values()];
17          const cmd = values.find(c => c.site === 'douyin' && c.name === 'videos');
18          expect(cmd).toBeDefined();
19      });
20      it('parses the current creator work_list api shape', async () => {
21          const registry = getRegistry();
22          const command = [...registry.values()].find((cmd) => cmd.site === 'douyin' && cmd.name === 'videos');
23          expect(command?.func).toBeDefined();
24          if (!command?.func)
25              throw new Error('douyin videos command not registered');
26          browserFetchMock.mockResolvedValueOnce({
27              aweme_list: [
28                  {
29                      aweme_id: '7000000000000000001',
30                      desc: '测试视频标题',
31                      create_time: 1581571130,
32                      statistics: {
33                          play_count: 0,
34                          digg_count: 12,
35                      },
36                      status: {
37                          is_private: true,
38                      },
39                  },
40              ],
41          });
42          const rows = await command.func({}, { limit: 5, page: 1, status: 'all' });
43          expect(rows).toEqual([
44              {
45                  aweme_id: '7000000000000000001',
46                  title: '测试视频标题',
47                  status: 'private',
48                  play_count: 0,
49                  digg_count: 12,
50                  create_time: new Date(1581571130 * 1000).toLocaleString('zh-CN', { timeZone: 'Asia/Tokyo' }),
51              },
52          ]);
53      });
54  });