Files
wehub-resource-sync 9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

46 lines
2.0 KiB
JavaScript

import { beforeEach, describe, expect, it, vi } from 'vitest';
const { browserFetchMock } = vi.hoisted(() => ({
browserFetchMock: vi.fn(),
}));
vi.mock('./_shared/browser-fetch.js', () => ({
browserFetch: browserFetchMock,
}));
import { getRegistry } from '@jackwener/opencli/registry';
import './collections.js';
describe('douyin collections', () => {
beforeEach(() => {
browserFetchMock.mockReset();
});
it('registers the collections command', () => {
const registry = getRegistry();
const cmd = [...registry.values()].find(c => c.site === 'douyin' && c.name === 'collections');
expect(cmd).toBeDefined();
expect(cmd?.args.some(a => a.name === 'limit')).toBe(true);
});
it('has expected columns', () => {
const registry = getRegistry();
const cmd = [...registry.values()].find(c => c.site === 'douyin' && c.name === 'collections');
expect(cmd?.columns).toContain('mix_id');
expect(cmd?.columns).toContain('name');
expect(cmd?.columns).toContain('item_count');
});
it('uses COOKIE strategy', () => {
const registry = getRegistry();
const cmd = [...registry.values()].find(c => c.site === 'douyin' && c.name === 'collections');
expect(cmd?.strategy).toBe('cookie');
});
it('uses the current mix list request shape', async () => {
const registry = getRegistry();
const command = [...registry.values()].find((cmd) => cmd.site === 'douyin' && cmd.name === 'collections');
expect(command?.func).toBeDefined();
if (!command?.func)
throw new Error('douyin collections command not registered');
browserFetchMock.mockResolvedValueOnce({
mix_list: [],
});
const rows = await command.func({}, { limit: 12 });
expect(browserFetchMock).toHaveBeenCalledWith({}, 'GET', 'https://creator.douyin.com/web/api/mix/list/?status=0,1,2,3,6&count=12&cursor=0&should_query_new_mix=1&device_platform=web&aid=1128');
expect(rows).toEqual([]);
});
});