Recherche de fiches par nom peu fiable : sans ISBN, les providers étaient interrogés avec des titres bruts peu discriminants. - extraction de hints locaux (titre/auteur/année/isbn du fichier et du nom de fichier) persistés dans books.local_metadata_json - nouveau use-case ScoreMetadataMatch : tri des résultats par score de correspondance avant sélection du meilleur candidat - providers (google-books, open-library, bnf, local) durcis et nourris par les hints ; colonne + index local_metadata_json avec migrations idempotentes (création et rebuild legacy) - web : nettoyage de la description de la fiche livre (cleanBookDescription, white-space pre-line) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
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);
|
|
});
|
|
});
|