import { describe, expect, it } from "vitest"; import { ExtractLocalMetadataHints } from "./use-cases/extract-local-metadata-hints.js"; import { ScoreMetadataMatch } from "./use-cases/score-metadata-match.js"; describe("local metadata hints", () => { it("extracts title, author and year hints from a book without ISBN", () => { const hints = new ExtractLocalMetadataHints().fromMetadataAndFile( { title: "Harry Potter et le Prince de Sang Mele", author: null, description: null, isbn: null, language: null, publisher: null, publishedDate: null, coverPath: null }, "/library/Harry Potter et le Prince de Sang Mele (J. K. Rowling) 2005.epub" ); expect(hints).toMatchObject({ title: "Harry Potter et le Prince de Sang Mele", author: "J. K. Rowling", year: "2005", isbn: null }); }); }); describe("metadata match scoring", () => { it("keeps the best remote match for locally extracted title and author", () => { const best = new ScoreMetadataMatch().best( { title: "Harry Potter et le Prince de Sang Mele", author: "J. K. Rowling", year: "2005" }, [ { title: "Harry Potter et la chambre des secrets", author: "J. K. Rowling", publishedDate: "1998" }, { title: "Harry Potter et le Prince de sang-mêlé", author: "J.K. Rowling", publishedDate: "2005" } ] ); expect(best?.match.title).toBe("Harry Potter et le Prince de sang-mêlé"); expect(best?.score).toBeGreaterThan(0.7); }); });