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.0 KB · 68 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 } from './index.js';6import { ccgClassify, ccgParse } from '../_g2-grading-lib/ccg.js';7import { cardCategoryFromText, parseCardGrade } from '../_g2-grading-lib/text.js';89const connector = createConnector(localMeta(meta));10const snapshotOf = (name: string) => (loadFixture('cgc-cards-cert', name).raw.payload as { snapshot: string }).snapshot;1112describe('cgc-cards-cert', () => {13  runFixtureSuite(connector, it, expect);1415  it('builds and recognises CGC Cards cert URLs', () => {16    expect(certUrl('4340250003')).toBe('https://www.cgccards.com/certlookup/4340250003/');17    expect(certFromUrl('https://www.cgccards.com/certlookup/4340250003/')).toBe('4340250003');18    expect(certFromUrl('https://www.cgccards.com/CERTLOOKUP/4340250003/0_0/')).toBe('4340250003');19    expect(certFromUrl('https://www.cgccomics.com/certlookup/1134755001/')).toBeNull();20    expect(connector.urlPatterns.some((re) => re.test(certUrl('4340250003')))).toBe(true);21  });2223  it('parses the card fields, grade and the "Coming Soon" population placeholder', () => {24    const page = ccgParse(snapshotOf('lances-charizard'));25    expect(page.fields).toMatchObject({ 'Cert #': '4340250003', 'Card Name': "Lance's Charizard", Game: 'Pokémon', Year: '2001', Language: 'Japanese', 'Card Number': '097/141', Grade: 'MINT+ 9.5' });26    expect(page.atGrade).toBeNull();27    expect(page.higher).toBe(0);28    expect(page.images.length).toBe(2);29    expect(ccgClassify(snapshotOf('lances-charizard'))).toBe('found');30  });3132  it('normalises to a pokemon catalog_item without a population report', async () => {33    const out = await connector.normalize(loadFixture('cgc-cards-cert', 'lances-charizard').raw);34    expect(out.map((r) => r.kind)).toEqual(['catalog_item']);35    const item = out[0]!;36    if (item.kind === 'catalog_item') {37      expect(item.attributes).toMatchObject({ categorySlug: 'pokemon', name: "Lance's Charizard", number: '097', year: 2001, language: 'Japanese', franchise: 'Pokémon' });38      expect(item.attributes.identifiers).toEqual({ cgc_cert: '4340250003' });39      expect(item.grade).toEqual({ grader: 'cgc', grade: '9.5', qualifier: null, certificationNumber: '4340250003' });40      expect(item.attributes.metadata.total_in_set).toBe('141');41      expect(item.attributes.metadata.population_note).toMatch(/Coming Soon/);42      expect(item.imageUrls.length).toBe(2);43    }44  });4546  it('keeps odd test-slab text verbatim (edge case) and still yields a valid record', async () => {47    const out = await connector.normalize(loadFixture('cgc-cards-cert', 'test-slab-1').raw);48    expect(out.length).toBe(1);49    if (out[0]!.kind === 'catalog_item') expect(out[0]!.grade.grade).toBe('10');50  });5152  it('yields zero records for a not-found cert without throwing', async () => {53    const fx = loadFixture('cgc-cards-cert', 'not-found');54    expect(ccgClassify((fx.raw.payload as { snapshot: string }).snapshot)).toBe('not_found');55    await expect(connector.normalize(fx.raw)).resolves.toEqual([]);56  });5758  it('parses CGC Cards grade labels and categories', () => {59    expect(parseCardGrade('MINT+ 9.5')).toMatchObject({ grade: '9.5' });60    expect(parseCardGrade('PRISTINE 10')).toMatchObject({ grade: '10' });61    expect(parseCardGrade('GEM MINT 10')).toMatchObject({ grade: '10' });62    expect(cardCategoryFromText('Pokémon Pokémon VS Lance\'s Charizard')).toEqual({ slug: 'pokemon', confident: true });63    expect(cardCategoryFromText('Basketball 2019 Panini Prizm Zion Williamson', 'sports_cards')).toEqual({ slug: 'basketball_cards', confident: true });64    expect(cardCategoryFromText('2021 Bowman Chrome Prospects')).toEqual({ slug: 'sports_cards', confident: false });65    expect(cardCategoryFromText('Unknown Game Card')).toEqual({ slug: 'trading_cards', confident: false });66  });67});68