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

80 lines
3.2 KiB
JavaScript

import { describe, expect, it } from 'vitest';
import { Strategy, getRegistry } from '@jackwener/opencli/registry';
import './hot.js';
import './posts.js';
import './read.js';
import './search.js';
describe('tieba commands', () => {
it('registers all tieba commands as TypeScript adapters', () => {
const hot = getRegistry().get('tieba/hot');
const posts = getRegistry().get('tieba/posts');
const search = getRegistry().get('tieba/search');
const read = getRegistry().get('tieba/read');
expect(hot).toBeDefined();
expect(posts).toBeDefined();
expect(search).toBeDefined();
expect(read).toBeDefined();
expect(typeof hot?.func).toBe('function');
expect(typeof posts?.func).toBe('function');
expect(typeof search?.func).toBe('function');
expect(typeof read?.func).toBe('function');
});
it('keeps the intended browser strategies', () => {
const hot = getRegistry().get('tieba/hot');
const posts = getRegistry().get('tieba/posts');
const search = getRegistry().get('tieba/search');
const read = getRegistry().get('tieba/read');
expect(hot?.strategy).toBe(Strategy.PUBLIC);
expect(posts?.strategy).toBe(Strategy.COOKIE);
expect(search?.strategy).toBe(Strategy.COOKIE);
expect(read?.strategy).toBe(Strategy.COOKIE);
expect(hot?.browser).toBe(true);
expect(posts?.browser).toBe(true);
expect(search?.browser).toBe(true);
expect(read?.browser).toBe(true);
});
it('keeps the public limit contract at 20 items for list commands', () => {
const hot = getRegistry().get('tieba/hot');
const posts = getRegistry().get('tieba/posts');
const search = getRegistry().get('tieba/search');
expect(hot?.args.find((arg) => arg.name === 'limit')?.default).toBe(20);
expect(posts?.args.find((arg) => arg.name === 'limit')?.default).toBe(20);
expect(search?.args.find((arg) => arg.name === 'limit')?.default).toBe(20);
});
it('rejects tieba read results when navigation lands on the wrong page number', async () => {
const read = getRegistry().get('tieba/read');
expect(read).toBeDefined();
expect(typeof read?.func).toBe('function');
const run = read?.func;
if (!run)
throw new Error('tieba/read did not register a handler');
const page = {
goto: async () => undefined,
evaluate: async () => ({
pageMeta: {
pathname: '/p/10163164720',
pn: '1',
},
mainPost: {
title: '测试帖子',
author: '作者',
contentText: '正文',
structuredText: '',
visibleTime: '2026-03-29 12:00',
structuredTime: 0,
hasMedia: false,
},
replies: [],
}),
};
await expect(run(page, {
id: '10163164720',
page: 2,
limit: 5,
})).rejects.toMatchObject({
code: 'EMPTY_RESULT',
hint: expect.stringMatching(/requested page/i),
});
});
});