import { describe, expect, it } from 'vitest'; import { chatfieldSeriesLinks, parseBagwellBooks, parseChatfieldBook } from './author-adapters.js'; import { ReviewError, type SeedSeries } from './types.js'; describe('author bibliographies',()=>{ it('uses the author book number rather than a realm ordinal or paperback date',()=>{ const book=parseChatfieldBook('

The Sixth Realm Part 2 - The Ten Realms Series Book 7 - (Paperback)

PLEASE NOTE THAT YOU CANNOT PURCHASE THE PHYSICAL BOOK FROM THE STORE.

Two soldiers seek their next challenge.
Danger awaits beyond the gate.

'); expect(book).toMatchObject({title:'The Sixth Realm Part 2',number:7,format:'print',releaseDate:null,audioReleaseDate:null,narrator:null,links:[]}); expect(book.description).toBe('Two soldiers seek their next challenge.\nDanger awaits beyond the gate.'); }); it('rejects unrelated products and unnumbered store pages',()=>{ expect(()=>parseChatfieldBook('

Other Series Book 4

')).toThrow(ReviewError); expect(()=>parseChatfieldBook('

The Ten Realms Collection

')).toThrow(ReviewError); }); it('discovers only explicitly numbered books and ignores recommendations or offsite links',()=>{ const html='The Fourth Realm - The Ten Realms Series Book 4Other Series Book 1The Ten Realms Series Book 5'; expect(chatfieldSeriesLinks(html,'https://michaelchatfield.com/collections/the-ten-realms')).toEqual([{url:'https://michaelchatfield.com/products/realm',title:'The Fourth Realm - The Ten Realms Series Book 4'}]); }); const seed:SeedSeries={id:'awaken-online',title:'Awaken Online',author:'Travis Bagwell',authorAliases:['Travis Bagwell'],aliases:[],genres:['litrpg'],priority:1,sources:[]}; it('retains fractional side stories and excludes separate Tarot/MRI numbering',()=>{ const card=(label:string,title:string)=>`${label}

${title}

`; const books=parseBagwellBooks(card('AO #1','Catharsis')+card('Side Quest Riley AO #2.5','Retribution')+card('Tarot #T1','Ember')+card('MRI #1','Hollow'),seed); expect(books.map(b=>[b.number,b.title])).toEqual([[1,'Catharsis'],[2.5,'Retribution']]); expect(books.every(b=>!b.audioReleaseDate&&!b.links.length&&!b.description)).toBe(true); }); it('requires an explicit series binding and refuses conflicting same-volume titles',()=>{ expect(()=>parseBagwellBooks('',{...seed,title:'Another Series'})).toThrow(ReviewError); expect(()=>parseBagwellBooks('AO #1

First

AO #1

Second

',seed)).toThrow(ReviewError); }); });