32 lines
1.3 KiB
JavaScript
32 lines
1.3 KiB
JavaScript
import { test, expect } from 'bun:test';
|
|
import * as sc from './search-cache.js';
|
|
import { initDb } from './db.js';
|
|
|
|
await initDb();
|
|
const cards = (n) => Array.from({ length: n }, (_, i) => ({ id: 'v' + i, title: 't' + i }));
|
|
|
|
test('put/get round-trips, case-insensitive, capped at 200', async () => {
|
|
await sc.put('Hello World', cards(300));
|
|
const r = await sc.get('hello world');
|
|
expect(r.results.length).toBe(200);
|
|
expect(await sc.get('nope')).toBeNull();
|
|
});
|
|
|
|
test('trim evicts least-recently-used rows over the row cap', async () => {
|
|
for (let i = 0; i < 6; i++) await sc.put('q' + i, cards(3));
|
|
const dropped = await sc.trim({ maxRows: 3 });
|
|
expect(dropped).toBeGreaterThan(0);
|
|
expect((await sc.stats()).queries).toBe(3);
|
|
});
|
|
|
|
test('known videos are remembered and found by every word', async () => {
|
|
await sc.rememberVideos([
|
|
{ id: 'a1', title: 'Way Maker - Sinach', channel: 'Worship' },
|
|
{ id: 'b2', title: 'Way Maker (live)', channel: 'Other' },
|
|
{ id: 'c3', title: 'Goodness of God', channel: 'Worship' },
|
|
]);
|
|
expect((await sc.searchVideos('way maker')).map((c) => c.id).sort()).toEqual(['a1', 'b2']);
|
|
expect((await sc.searchVideos('maker worship')).map((c) => c.id)).toEqual(['a1']);
|
|
expect(await sc.searchVideos('100%')).toEqual([]);
|
|
});
|