TypeScript 61.9%
HTML 37.2%
SQL 0.7%
1import { describe, expect, it } from 'vitest';2import { AssetAttributesSchema } from '@rareindex/shared';3import { buildCanonicalKey, composeTitle, deterministicIdentifiers } from './canonical-key.ts';4import { fuzzyCandidateScore } from './resolver.ts';56const charizardA = AssetAttributesSchema.parse({ categorySlug: 'pokemon', set: 'Base Set', number: '4/102', name: 'Charizard', variant: '1st Edition Holo', language: 'English', year: 1999, identifiers: { pokemontcg_id: 'base1-4' } });7const charizardB = AssetAttributesSchema.parse({ categorySlug: 'pokemon', setCode: 'base set', number: '#4/102', name: 'Charizard ', variant: '1st edition holo', language: 'english' });89describe('canonical key', () => {10 it('collides for the same card described differently', () => {11 expect(buildCanonicalKey(charizardA)).toBe(buildCanonicalKey(charizardB));12 expect(buildCanonicalKey(charizardA)).toBe('pokemon|base set|4/102|charizard|1st edition holo|english');13 });14 it('separates variants and languages', () => {15 const unlimited = { ...charizardA, variant: 'Unlimited Holo' };16 const jp = { ...charizardA, language: 'Japanese' };17 expect(buildCanonicalKey(unlimited)).not.toBe(buildCanonicalKey(charizardA));18 expect(buildCanonicalKey(jp)).not.toBe(buildCanonicalKey(charizardA));19 });20 it('uses references for watches and style codes for sneakers', () => {21 const w = AssetAttributesSchema.parse({ categorySlug: 'rolex', brand: 'Rolex', model: 'Daytona', reference: '116500LN', name: 'Cosmograph Daytona' });22 expect(buildCanonicalKey(w)).toBe('rolex|rolex|116500ln|');23 const s = AssetAttributesSchema.parse({ categorySlug: 'nike_jordan', brand: 'Jordan', name: 'Air Jordan 1 Retro High OG Chicago', identifiers: { style_code: '555088-101' } });24 expect(buildCanonicalKey(s)).toBe('nike_jordan|555088-101');25 });26 it('composes titles', () => {27 expect(composeTitle(charizardA)).toBe('Charizard #4/102 · Base Set 1st Edition Holo · (1999)');28 expect(deterministicIdentifiers({ pokemontcg_id: 'base1-4', junk: 'x' })).toEqual({ pokemontcg_id: 'base1-4' });29 });30 it('scores fuzzy candidates', () => {31 expect(fuzzyCandidateScore({ title: 'Charizard #4/102 · Base Set 1st Edition Holo · (1999)', number: '4/102', year: 1999, setName: 'Base Set' }, charizardA, 0.7)).toBeGreaterThan(0.7);32 expect(fuzzyCandidateScore({ title: 'Blastoise #2/102 · Base Set', number: '2/102', year: 1999, setName: 'Base Set' }, charizardA, 0.7)).toBe(0);33 });34});35