Add resolver, server, PDF rendering and web app

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-18 09:46:46 -07:00
1 parent 6a7fcdc4b8
commit bdfdf581f3
59 files changed
+4088

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { openDb } from './db.ts';
test('insertPending is idempotent on isbn13', () => {
const db = openDb(':memory:');
const a = db.insertPending({ isbn13: '9781593278281', title: 'x' });
const b = db.insertPending({ isbn13: '9781593278281', title: 'y' });
assert.equal(a.created, true);
assert.equal(b.created, false);
assert.equal(b.book.id, a.book.id);
assert.equal(db.listBooks().length, 1);
});
test('books without isbn do not collide', () => {
const db = openDb(':memory:');
db.insertPending({ title: 'a' });
db.insertPending({ title: 'b' });
assert.equal(db.listBooks().length, 2);
});
test('listBooks orders by sort key, nulls last, then title', () => {
const db = openDb(':memory:');
db.insertPending({ title: 'Zed' });
db.insertPending({ title: 'Abe' });
db.insertPending({ title: 'B', sortKey: 'QA 76' });
db.insertPending({ title: 'A', sortKey: 'PS 12' });
assert.deepEqual(db.listBooks().map((b) => b.title), ['A', 'B', 'Abe', 'Zed']);
});
test('filters and search', () => {
const db = openDb(':memory:');
const a = db.insertPending({ title: 'Rust Book', authors: ['Klabnik, Steve'], inQueue: true }).book;
db.insertPending({ title: 'Other', status: 'needs_attention', inQueue: false });
assert.deepEqual(db.listBooks({ filter: 'queue' }).map((b) => b.id), [a.id]);
assert.equal(db.listBooks({ filter: 'attention' }).length, 1);
assert.equal(db.listBooks({ q: 'klabnik' }).length, 1);
});
test('updateBook round-trips fields', () => {
const db = openDb(':memory:');
const { book } = db.insertPending({ title: 't' });
const u = db.updateBook(book.id, { authors: ['A'], manualOverride: true, status: 'resolved', year: 2001 })!;
assert.deepEqual(u.authors, ['A']);
assert.equal(u.manualOverride, true);
assert.equal(u.year, 2001);
assert.equal(db.updateBook(999, { title: 'z' }), null);
assert.deepEqual(db.listPendingIds(), []);
assert.equal(db.deleteBook(book.id), true);
});
test('settings and cache', () => {
const db = openDb(':memory:');
assert.deepEqual(db.getSettings(), { offsetXmm: 0, offsetYmm: 0 });
db.putSettings({ offsetXmm: 1.5, offsetYmm: -2 });
assert.deepEqual(db.getSettings(), { offsetXmm: 1.5, offsetYmm: -2 });
assert.equal(db.cache.get('k'), null);
db.cache.set('k', 'v');
db.cache.set('k', 'w');
assert.equal(db.cache.get('k'), 'w');
});