/ clis / douyin / activities.test.js
activities.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 './activities.js';
10  describe('douyin activities registration', () => {
11      beforeEach(() => {
12          browserFetchMock.mockReset();
13      });
14      it('registers the activities command', () => {
15          const registry = getRegistry();
16          const cmd = [...registry.values()].find(c => c.site === 'douyin' && c.name === 'activities');
17          expect(cmd).toBeDefined();
18      });
19      it('has expected columns', () => {
20          const registry = getRegistry();
21          const cmd = [...registry.values()].find(c => c.site === 'douyin' && c.name === 'activities');
22          expect(cmd?.columns).toContain('activity_id');
23          expect(cmd?.columns).toContain('title');
24          expect(cmd?.columns).toContain('end_time');
25      });
26      it('uses COOKIE strategy', () => {
27          const registry = getRegistry();
28          const cmd = [...registry.values()].find(c => c.site === 'douyin' && c.name === 'activities');
29          expect(cmd?.strategy).toBe('cookie');
30      });
31      it('maps the current activity payload shape returned by creator center', async () => {
32          const registry = getRegistry();
33          const cmd = [...registry.values()].find(c => c.site === 'douyin' && c.name === 'activities');
34          expect(cmd?.func).toBeDefined();
35          if (!cmd?.func)
36              throw new Error('douyin activities command not registered');
37          browserFetchMock.mockResolvedValueOnce({
38              activity_list: [
39                  {
40                      activity_id: '200',
41                      activity_name: '超会玩派对',
42                      show_end_time: '2026.05.31',
43                  },
44              ],
45          });
46          const rows = await cmd.func({}, {});
47          expect(rows).toEqual([
48              {
49                  activity_id: '200',
50                  title: '超会玩派对',
51                  end_time: '2026.05.31',
52              },
53          ]);
54      });
55  });