Book 1: ${link('https://www.amazon.com/gp/product/B000000101/')}
Book 2: ${link('https://www.amazon.com/dp/B000000102')}
WIP Book 3: ${link('https://www.patreon.com/sarahlin', 'Patreon')}
`;
describe('bounded Sarah Lin author audio discovery', () => {
it('reads five explicit Weirkey audio labels while keeping ebooks and an unrecorded sixth separate', () => {
const html = page(weirkey, ebookSection + audioSection(Array.from({ length: 5 }, (_, i) => row(i + 1)).join('') + 'Book 6: Will be recorded!'));
const leads = parseSarahLinAudioLeads(html, weirkey, source(weirkey));
expect(leads.map(lead => [lead.number, lead.asin])).toEqual([1, 2, 3, 4, 5].map(n => [n, asin(n)]));
expect(leads[0]).toEqual({ seriesId: weirkey.id, number: 1, asin: asin(1), url: audioUrl(1), sourceUrl: source(weirkey) });
expect(Object.keys(leads[0]).sort()).toEqual(['asin', 'number', 'seriesId', 'sourceUrl', 'url']);
expect(JSON.stringify(leads)).not.toMatch(/Narrator|2020|B000000101|B000000102/);
});
it('reads Street Cultivation audio labels without treating its completed ebook trilogy as three recordings', () => {
const html = page(street, `
A synthetic series introduction.
Completed Book 1: ${link('https://www.amazon.com/dp/B000000101')}
Completed Book 2: ${link('https://www.amazon.com/dp/B000000102')}
Completed Book 3: ${link('https://www.amazon.com/dp/B000000103')}
${row(1, street, 'https://www.audible.com/pd/Example-Audiobook/1541438200')}${row(2, street)}
Description: Synthetic source copy must not be returned. ${row(3, street)}`);
const leads = parseSarahLinAudioLeads(html, street, source(street));
expect(leads.map(lead => [lead.number, lead.asin])).toEqual([[1, '1541438200'], [2, asin(2)]]);
expect(leads[0].url).toBe('https://www.audible.com/pd/Example-Audiobook/1541438200');
expect(JSON.stringify(leads)).not.toContain('Synthetic source copy');
});
it('uses explicit numbers after reordering and does not fill missing volumes', () => {
const html = page(weirkey, audioSection(row(5) + row(2)));
expect(parseSarahLinAudioLeads(html, weirkey, source(weirkey)).map(lead => lead.number)).toEqual([2, 5]);
});
it('preserves inline formatting without joining links from a different line', () => {
const html = page(weirkey, `
${row(94)}`);
expect(parseSarahLinAudioLeads(html, weirkey, source(weirkey)).map(lead => lead.number)).toEqual([1]);
});
it('does not start a Street list in recommendations after the selected bibliography', () => {
const html = page(street, `Completed Book 1: ${link('https://www.amazon.com/dp/B000000101')}
Recommendations
${row(1, street)}`);
expect(() => parseSarahLinAudioLeads(html, street, source(street))).toThrow(/no explicitly numbered/);
});
it('stops at unrelated prose instead of continuing into another series block', () => {
const html = page(weirkey, audioSection(row(1) + '
Other stories from another series.
' + row(2)));
expect(parseSarahLinAudioLeads(html, weirkey, source(weirkey)).map(lead => lead.number)).toEqual([1]);
});
it('keeps planned audio, WIP, and collections out even when they contain product links', () => {
const html = page(weirkey, audioSection(row(1) + `Book 2: Will be recorded! ${link(audioUrl(2))}
WIP Book 3: ${link(audioUrl(3))} Books 1–3 omnibus: ${link(audioUrl(90))}
${row(4, weirkey, audioUrl(4), 'Box set')}${row(5)}`));
expect(parseSarahLinAudioLeads(html, weirkey, source(weirkey)).map(lead => lead.number)).toEqual([1, 5]);
});
it('deduplicates the same numbered identifier and removes link tracking', () => {
const html = page(weirkey, audioSection(row(1, weirkey, `${audioUrl(1)}?ref=example#sample`, 'Listen') + row(1)));
expect(parseSarahLinAudioLeads(html, weirkey, source(weirkey))).toEqual([
{ seriesId: weirkey.id, number: 1, asin: asin(1), url: audioUrl(1), sourceUrl: source(weirkey) }
]);
});
it('rejects different identifiers for one volume or one identifier assigned to two volumes', () => {
for (const rows of [row(1) + row(1, weirkey, audioUrl(2)), row(1) + row(2, weirkey, audioUrl(1))]) {
expect(() => parseSarahLinAudioLeads(page(weirkey, audioSection(rows)), weirkey, source(weirkey))).toThrow(/conflicting/);
}
});
it('rejects conflicting destination and displayed product identifiers', () => {
const html = page(weirkey, audioSection(row(1, weirkey, audioUrl(1), audioUrl(2))));
expect(() => parseSarahLinAudioLeads(html, weirkey, source(weirkey))).toThrow(/text and destination disagree/);
});
it('rejects merged volume rows instead of assigning both products to the first volume', () => {
const html = page(weirkey, audioSection(`Book 1: ${link(audioUrl(1))}Book 2: ${link(audioUrl(2))}`));
expect(() => parseSarahLinAudioLeads(html, weirkey, source(weirkey))).toThrow(/ambiguous surrounding text/);
});
it.each([
'https://www.amazon.com/dp/B000000001',
'https://www.audible.co.uk/pd/B000000001',
'https://www.audible.com.evil.example/pd/B000000001',
'https://reader:password@www.audible.com/pd/B000000001',
'http://www.audible.com/pd/B000000001',
'https://www.audible.com:8443/pd/B000000001',
'https://amzn.to/example',
'https://www.audible.com/series/B000000001',
'https://www.audible.com/pd/B000000001/extra'
])('rejects an unsupported, non-US, or unsafe audio destination: %s', href => {
expect(() => parseSarahLinAudioLeads(page(weirkey, audioSection(row(1, weirkey, href))), weirkey, source(weirkey))).toThrow(ReviewError);
});
it('requires actual anchors instead of turning raw URLs or planned recordings into leads', () => {
for (const rows of [`Book 1: ${audioUrl(1)}`, 'Book 1: Will be recorded!', 'Book 1: Coming soon']) {
expect(() => parseSarahLinAudioLeads(page(weirkey, audioSection(rows)), weirkey, source(weirkey))).toThrow(/no explicitly numbered/);
}
});
it('requires a unique audio section for Weirkey and never uses the ebook section', () => {
for (const contents of [ebookSection, audioSection(row(1)) + audioSection(row(2)), `