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
69 lines
2.3 KiB
JavaScript
69 lines
2.3 KiB
JavaScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
const { mockApiGet } = vi.hoisted(() => ({
|
|
mockApiGet: vi.fn(),
|
|
}));
|
|
vi.mock('./utils.js', () => ({
|
|
apiGet: mockApiGet,
|
|
}));
|
|
import { getRegistry } from '@jackwener/opencli/registry';
|
|
import './dynamic.js';
|
|
describe('bilibili dynamic adapter', () => {
|
|
const command = getRegistry().get('bilibili/dynamic');
|
|
beforeEach(() => {
|
|
mockApiGet.mockReset();
|
|
});
|
|
it('maps desc text rows from the dynamic feed payload', async () => {
|
|
mockApiGet.mockResolvedValue({
|
|
data: {
|
|
items: [
|
|
{
|
|
id_str: '123',
|
|
modules: {
|
|
module_author: { name: 'Alice' },
|
|
module_dynamic: { desc: { text: 'hello world' } },
|
|
module_stat: { like: { count: 9 } },
|
|
},
|
|
},
|
|
],
|
|
},
|
|
});
|
|
const result = await command.func({}, { limit: 5 });
|
|
expect(mockApiGet).toHaveBeenCalledWith({}, '/x/polymer/web-dynamic/v1/feed/all', { params: {}, signed: false });
|
|
expect(result).toEqual([
|
|
{
|
|
id: '123',
|
|
author: 'Alice',
|
|
text: 'hello world',
|
|
likes: 9,
|
|
url: 'https://t.bilibili.com/123',
|
|
},
|
|
]);
|
|
});
|
|
it('falls back to archive title when desc text is absent', async () => {
|
|
mockApiGet.mockResolvedValue({
|
|
data: {
|
|
items: [
|
|
{
|
|
id_str: '456',
|
|
modules: {
|
|
module_author: { name: 'Bob' },
|
|
module_dynamic: { major: { archive: { title: 'Video title' } } },
|
|
module_stat: { like: { count: 3 } },
|
|
},
|
|
},
|
|
],
|
|
},
|
|
});
|
|
const result = await command.func({}, { limit: 5 });
|
|
expect(result).toEqual([
|
|
{
|
|
id: '456',
|
|
author: 'Bob',
|
|
text: 'Video title',
|
|
likes: 3,
|
|
url: 'https://t.bilibili.com/456',
|
|
},
|
|
]);
|
|
});
|
|
});
|