Each card now shows, under the call number, the Library of Congress outline levels for its class (from the published outline, down to the narrowest range) followed by the place or topic from the catalogue record's subject heading, one level per line. Existing books get the subject part filled in by a background job at startup that changes nothing else about them. The QR code and everything that read it are removed; the subjects line on the card is replaced by the tree. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { acceptRead, markEmitted, newReadState } from './readstate.ts';
|
|
|
|
const ISBN = '9780306406157';
|
|
|
|
test('a valid ISBN-13 is accepted on the first read', () => {
|
|
const r = acceptRead(newReadState(), ISBN, 0);
|
|
assert.equal(r.emit, ISBN);
|
|
assert.equal(r.reject, false);
|
|
});
|
|
|
|
test('the same ISBN is not repeated within 5 s, then is again', () => {
|
|
let r = acceptRead(newReadState(), ISBN, 0);
|
|
r = acceptRead(r.state, ISBN, 150);
|
|
assert.equal(r.emit, null);
|
|
assert.equal(r.reject, false);
|
|
r = acceptRead(r.state, ISBN, 4900);
|
|
assert.equal(r.emit, null);
|
|
r = acceptRead(r.state, ISBN, 5100);
|
|
assert.equal(r.emit, ISBN);
|
|
});
|
|
|
|
test('a 979 ISBN is accepted', () => {
|
|
assert.equal(acceptRead(newReadState(), '9791034305261', 0).emit, '9791034305261');
|
|
});
|
|
|
|
test('a UPC-A rejects once per 5 s', () => {
|
|
const upc = '036000291452';
|
|
let r = acceptRead(newReadState(), upc, 0);
|
|
assert.equal(r.reject, true);
|
|
assert.equal(r.emit, null);
|
|
r = acceptRead(r.state, upc, 150);
|
|
assert.equal(r.reject, false);
|
|
r = acceptRead(r.state, upc, 6000);
|
|
assert.equal(r.reject, true);
|
|
});
|
|
|
|
test('a 13-digit code without a 978/979 prefix, or with a bad check digit, rejects', () => {
|
|
assert.equal(acceptRead(newReadState(), '5012345678900', 0).reject, true);
|
|
assert.equal(acceptRead(newReadState(), '9780306406158', 0).reject, true);
|
|
});
|
|
|
|
test('markEmitted silences the loop for 5 s', () => {
|
|
const s = markEmitted(newReadState(), ISBN, 1000);
|
|
assert.equal(acceptRead(s, ISBN, 2000).emit, null);
|
|
assert.equal(acceptRead(s, ISBN, 6100).emit, ISBN);
|
|
});
|