diff --git a/packages/danmaku/src/match.test.ts b/packages/danmaku/src/match.test.ts index 13b6b47..ab1c299 100644 --- a/packages/danmaku/src/match.test.ts +++ b/packages/danmaku/src/match.test.ts @@ -29,4 +29,51 @@ describe("rankCandidates", () => { const r = rankCandidates(list); expect(r.highConfidence).toBe(false); }); + it("empty candidates are not high confidence", () => { + const r = rankCandidates([]); + expect(r.highConfidence).toBe(false); + expect(r.candidates).toEqual([]); + }); + it("score gap >= default lead (0.15) is high confidence", () => { + const list = [ + { episodeId: 2, animeId: 1, animeTitle: "Show", episodeTitle: null, imageUrl: "img" }, + { episodeId: 1, animeId: 1, animeTitle: "Show", episodeTitle: "01", imageUrl: null }, + ]; + const r = rankCandidates(list); + expect(r.highConfidence).toBe(true); + expect(r.candidates[0]?.episodeId).toBe(1); + }); + it("custom lead is honored", () => { + const list = [ + { episodeId: 2, animeId: 1, animeTitle: "Show", episodeTitle: null, imageUrl: "img" }, + { episodeId: 1, animeId: 1, animeTitle: "Show", episodeTitle: "01", imageUrl: null }, + ]; + expect(rankCandidates(list, { lead: 0.5 }).highConfidence).toBe(false); + expect(rankCandidates(list, { lead: 0.3 }).highConfidence).toBe(true); + }); + it("returns candidates sorted by score desc", () => { + const hi = { + episodeId: 1, + animeId: 1, + animeTitle: "A", + episodeTitle: "01", + imageUrl: "img", + }; + const mid = { + episodeId: 2, + animeId: 1, + animeTitle: "B", + episodeTitle: "02", + imageUrl: null, + }; + const low = { + episodeId: 3, + animeId: null, + animeTitle: null, + episodeTitle: null, + imageUrl: "x", + }; + const r = rankCandidates([low, mid, hi]); + expect(r.candidates.map((c) => c.episodeId)).toEqual([1, 2, 3]); + }); });