import { describe, expect, it } from 'vitest'; import { findBestMatch } from './match'; const target = { title: 'Midnight City', artist: 'M83', durationMs: 243_000 }; describe('findBestMatch', () => { it('prefers the exact title with a matching duration', () => { const best = findBestMatch( [ { id: 'remix', title: 'Midnight City (Eric Prydz Remix)', artist: 'M83', durationMs: 400_000 }, { id: 'cover', title: 'Midnight City', artist: 'Party Machine', durationMs: 243_000 }, { id: 'real', title: 'Midnight City', artist: 'M83', durationMs: 244_000 }, ], target, ); expect(best?.id).toBe('real'); }); it('rejects other artists even with the same title', () => { expect(findBestMatch([{ title: 'Midnight City', artist: 'Some Cover Band' }], target)).toBeNull(); }); it('rejects durations more than 15s apart', () => { expect(findBestMatch([{ title: 'Midnight City', artist: 'M83', durationMs: 300_000 }], target)).toBeNull(); }); it('matches when either side lacks a duration', () => { expect(findBestMatch([{ title: 'Midnight City', artist: 'M83' }], { title: 'Midnight City', artist: 'M83' })).not.toBeNull(); }); it('tolerates featured-artist and remaster suffixes', () => { const best = findBestMatch([{ title: 'Midnight City - Remastered', artist: 'M83, Someone' }], target); expect(best).not.toBeNull(); }); });