21 lines
748 B
JavaScript
21 lines
748 B
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);
|
|
});
|