TalkingBot/chat-engine/tests/citations.test.js

32 lines
1.4 KiB
JavaScript

const { buildCitations } = require('../src/citations/build');
const { sampleBook } = require('./fixture');
describe('citation build', () => {
it('drops unknown pages, fills the chapter, and caps the list', () => {
const notes = [];
const items = buildCitations({
book: sampleBook(),
max: 2,
markers: [
{ kind: 'page', page: 99, pageEnd: 99 },
{ kind: 'chapter', chapterNo: 3 },
{ kind: 'page', page: 2, pageEnd: 2 },
{ kind: 'page', page: 4, pageEnd: 4 },
{ kind: 'chapter', chapterNo: 3 },
],
logger: { info(obj, msg) { notes.push(msg); }, warn() {} },
});
expect(notes).toContain('invalid_markers');
expect(items.map((item) => item.page)).toEqual([3, 2]);
expect(items[0]).toMatchObject({ chapterNo: 3, chapterTitle: 'Workshop' });
expect(items[0].verified).toBeUndefined();
});
it('uses the old parser for chat only when the fallback is on and no markers were emitted', () => {
const book = sampleBook();
expect(buildCitations({ book, markers: [], text: 'See (p. 2).', channel: 'chat', fallback: true })).toHaveLength(1);
expect(buildCitations({ book, markers: [], text: 'See (p. 2).', channel: 'voice', fallback: true })).toHaveLength(0);
expect(buildCitations({ book, markers: [], text: 'See (p. 2).', channel: 'chat', fallback: false })).toHaveLength(0);
});
});