Google Books joins Open Library and the Library of Congress as a source of title, authors, publisher and categories when no number is in hand. The similar-books tier widens its search step by step (other word forms, place and topic words from the subtitle and publisher, fewer words) when the first search finds no class, and needs at least two agreeing books before it accepts one. The result is marked approximate. Books with no number or an approximate one are looked up again at startup once the last lookup is a week old. An ISBN no catalogue knows that is within three digits of a book already here says it may be a misread of that book. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
41 lines
1.8 KiB
TypeScript
41 lines
1.8 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { emptyState, reduce, shelfOrder } from './store.ts';
|
|
import type { Book } from '../shared/types.ts';
|
|
|
|
function book(id: number, title: string, sortKey: string | null): Book {
|
|
return {
|
|
id, isbn13: null, lccn: null, title, subtitle: null, authors: [], publisher: null, year: null,
|
|
subjects: [], callNumber: null, sortKey, confidence: null, source: null, dewey: null,
|
|
status: 'resolved', attentionReason: null, manualOverride: false, inQueue: true,
|
|
printedAt: null, hierarchyTail: null, edition: null, lookedUpAt: null, createdAt: '', updatedAt: '',
|
|
};
|
|
}
|
|
|
|
test('upsert adds then replaces', () => {
|
|
let s = reduce(emptyState, { type: 'upsert', book: book(1, 'A', 'x') });
|
|
s = reduce(s, { type: 'upsert', book: book(1, 'A2', 'x') });
|
|
assert.equal(shelfOrder(s).length, 1);
|
|
assert.equal(shelfOrder(s)[0].title, 'A2');
|
|
});
|
|
|
|
test('delete removes', () => {
|
|
let s = reduce(emptyState, { type: 'upsert', book: book(1, 'A', 'x') });
|
|
s = reduce(s, { type: 'delete', id: 1 });
|
|
assert.equal(shelfOrder(s).length, 0);
|
|
assert.equal(shelfOrder(reduce(s, { type: 'delete', id: 99 })).length, 0);
|
|
});
|
|
|
|
test('replace swaps the whole set', () => {
|
|
let s = reduce(emptyState, { type: 'upsert', book: book(1, 'A', 'x') });
|
|
s = reduce(s, { type: 'replace', books: [book(2, 'B', 'y')] });
|
|
assert.deepEqual(shelfOrder(s).map(b => b.id), [2]);
|
|
});
|
|
|
|
test('shelf order: sort key, unparseable last, then title', () => {
|
|
let s = emptyState;
|
|
for (const b of [book(1, 'Zed', null), book(2, 'Beta', 'QA0002'), book(3, 'Alpha', null), book(4, 'Gamma', 'QA0001'), book(5, 'Delta', 'QA0002')])
|
|
s = reduce(s, { type: 'upsert', book: b });
|
|
assert.deepEqual(shelfOrder(s).map(b => b.id), [4, 2, 5, 3, 1]);
|
|
});
|