- Shared: link building, feed ordering, input schemas, API client - API unit: track matching, private-address blocking, token crypto, plan expiry, provider response parsing - API integration against Postgres and Redis: auth, follows and pins, now-playing state, webhooks, OAuth return URLs, realtime, rate limits - Tests use a dedicated *_test database and Redis DB, and refuse to wipe anything else; fetch is stubbed so they never hit the network - Pin Node to 22.13+ (.nvmrc), which Vite's native bindings require Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzFywujuH9TiuXbr9vjoX8
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
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();
|
|
});
|
|
});
|