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
58 lines
2.2 KiB
JavaScript
58 lines
2.2 KiB
JavaScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { getRegistry } from '@jackwener/opencli/registry';
|
|
|
|
const { wikiFetchMock } = vi.hoisted(() => ({ wikiFetchMock: vi.fn() }));
|
|
vi.mock('./utils.js', async () => {
|
|
const actual = await vi.importActual('./utils.js');
|
|
return { ...actual, wikiFetch: wikiFetchMock };
|
|
});
|
|
|
|
import './trending.js';
|
|
|
|
describe('wikipedia trending', () => {
|
|
beforeEach(() => {
|
|
wikiFetchMock.mockReset();
|
|
});
|
|
|
|
it('emits empty-string for missing description instead of a sentinel', async () => {
|
|
const command = getRegistry().get('wikipedia/trending');
|
|
expect(command?.func).toBeDefined();
|
|
wikiFetchMock.mockResolvedValueOnce({
|
|
mostread: {
|
|
articles: [
|
|
{ title: 'Has_Both', description: 'A real description', views: 100 },
|
|
{ title: 'Has_Title_Only', views: 25 },
|
|
],
|
|
},
|
|
});
|
|
const rows = await command.func({ limit: 5, lang: 'en' });
|
|
expect(rows).toHaveLength(2);
|
|
expect(rows[0]).toMatchObject({ title: 'Has_Both', description: 'A real description', views: 100 });
|
|
expect(rows[1].title).toBe('Has_Title_Only');
|
|
expect(rows[1].description).toBe('');
|
|
});
|
|
|
|
it('fails typed when a trending article is missing title identity', async () => {
|
|
const command = getRegistry().get('wikipedia/trending');
|
|
wikiFetchMock.mockResolvedValueOnce({
|
|
mostread: { articles: [{ views: 50 }] },
|
|
});
|
|
await expect(command.func({ limit: 5, lang: 'en' })).rejects.toMatchObject({ code: 'PARSE_ERROR' });
|
|
});
|
|
|
|
it('validates only rows selected by --limit', async () => {
|
|
const command = getRegistry().get('wikipedia/trending');
|
|
wikiFetchMock.mockResolvedValueOnce({
|
|
mostread: {
|
|
articles: [
|
|
{ title: 'Selected', views: 100 },
|
|
{ views: 50 },
|
|
],
|
|
},
|
|
});
|
|
await expect(command.func({ limit: 1, lang: 'en' })).resolves.toEqual([
|
|
{ rank: 1, title: 'Selected', description: '', views: 100 },
|
|
]);
|
|
});
|
|
});
|