SPB Git forge

spb/rareindex

Public
54commits 1branches 0releases
7.1 MBsize
maindefault branch
10 days agolast push
TypeScript 61.9% HTML 37.2% SQL 0.7%
4.1 KB · 77 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import meta from './meta.json' with { type: 'json' };3import { localMeta } from '../../api/_lib/local-meta.js';4import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';5import createConnector, { certFromUrl, certUrl, parseSetLine, parseTagMarkdown } from './index.js';67const connector = createConnector(localMeta(meta));8const snapshotOf = (name: string) => (loadFixture('tag-cert', name).raw.payload as { snapshot: string }).snapshot;910describe('tag-cert', () => {11  runFixtureSuite(connector, it, expect);1213  it('builds and recognises TAG cert URLs', () => {14    expect(certUrl('v6153377')).toBe('https://my.taggrading.com/card/V6153377');15    expect(certFromUrl('https://my.taggrading.com/card/V6153377')).toBe('V6153377');16    expect(certFromUrl('https://tagd.co/V6153377')).toBe('V6153377');17    expect(certFromUrl('https://my.taggrading.com/pop-report/Pokemon/1999/WOTC')).toBeNull();18    expect(connector.urlPatterns.some((re) => re.test(certUrl('V6153377')))).toBe(true);19  });2021  it('parses the DIG report markdown: name, set line, TAG Score, grade, population, rank', () => {22    const page = parseTagMarkdown(snapshotOf('colmenarez-bowman-chrome'));23    expect(page).not.toBeNull();24    expect(page!.cert).toBe('V6153377');25    expect(page!.name).toBe('CARLOS COLMENAREZ');26    expect(page!.setLine).toBe('2021 BOWMAN CHROME #BCP-238');27    expect(page!.extraLines).toEqual(['PROSPECTS']);28    expect(page!.tagScore).toBe(943);29    expect(page!.grade).toBe('9');30    expect(page!.gradeLabel).toBe('MINT');31    expect(page!.atGrade).toBe(6);32    expect(page!.totalGraded).toBe(19);33    expect(page!.asOf).toBeInstanceOf(Date);34    expect(page!.gradedDate?.toISOString()).toBe('2022-08-09T00:00:00.000Z');35    expect(page!.rankByGrade).toBe('1ST');36    expect(page!.rankOverall).toBe('14TH');37    expect(page!.images.length).toBe(2);38    expect(parseSetLine('2021 BOWMAN CHROME #BCP-238')).toEqual({ year: 2021, set: 'Bowman Chrome', number: 'BCP-238' });39    expect(parseSetLine('1999 POKEMON BASE SET #4/102')).toEqual({ year: 1999, set: 'Pokemon Base Set', number: '4/102' });40  });4142  it('normalises to a catalog_item + population_report with total graded', async () => {43    const out = await connector.normalize(loadFixture('tag-cert', 'colmenarez-bowman-chrome').raw);44    const item = out.find((r) => r.kind === 'catalog_item');45    const pop = out.find((r) => r.kind === 'population_report');46    if (item?.kind === 'catalog_item') {47      expect(item.attributes).toMatchObject({ categorySlug: 'sports_cards', name: 'Carlos Colmenarez', set: 'Bowman Chrome', number: 'BCP-238', year: 2021, variant: 'PROSPECTS' });48      expect(item.attributes.identifiers).toEqual({ tag_cert: 'V6153377' });49      expect(item.grade).toEqual({ grader: 'tag', grade: '9', qualifier: null, certificationNumber: 'V6153377' });50      expect(item.attributes.metadata.tag_score).toBe(943);51      expect(item.confidence).toBeLessThan(0.9);52    } else throw new Error('catalog_item missing');53    if (pop?.kind === 'population_report') {54      expect(pop.byGrade).toEqual({ '9': 6, other: 13 });55      expect(pop.total).toBe(19);56      expect(pop.attributes.metadata.population_scope).toBe('grade_and_total');57      expect(pop.reportDate.getUTCFullYear()).toBeGreaterThanOrEqual(2026);58    } else throw new Error('population_report missing');59  });6061  it('parses a GEM MINT 10 copy of the same card', async () => {62    const out = await connector.normalize(loadFixture('tag-cert', 'card-t6113698').raw);63    const item = out.find((r) => r.kind === 'catalog_item');64    if (item?.kind === 'catalog_item') {65      expect(item.grade.grade).toBe('10');66      expect(item.rawTitle).toMatch(/GEM MINT/);67    }68  });6970  it('yields zero records for a not-found cert without throwing', async () => {71    const fx = loadFixture('tag-cert', 'not-found');72    expect(connector.classify((fx.raw.payload as { snapshot: string }).snapshot)).toBe('not_found');73    await expect(connector.normalize(fx.raw)).resolves.toEqual([]);74    expect(parseTagMarkdown('HomeAbout\nSubmit\nnothing here')).toBeNull();75  });76});77