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.3 KB · 74 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, splitCert } from './index.js';6import { ccgClassify, ccgParse } from '../_g2-grading-lib/ccg.js';78const connector = createConnector(localMeta(meta));9const snapshotOf = (name: string) => (loadFixture('ngc-cert', name).raw.payload as { snapshot: string }).snapshot;1011describe('ngc-cert', () => {12  runFixtureSuite(connector, it, expect);1314  it('builds and recognises NGC cert URLs (grade segment required)', () => {15    expect(splitCert('4627835-016/61')).toEqual({ number: '4627835-016', grade: '61' });16    expect(splitCert('4627835-016 61')).toEqual({ number: '4627835-016', grade: '61' });17    expect(splitCert('8444762-003:NGCDetails')).toEqual({ number: '8444762-003', grade: 'NGCDetails' });18    expect(splitCert('4627835-016')).toEqual({ number: '4627835-016', grade: null });19    expect(certUrl('4627835-016/61')).toBe('https://www.ngccoin.com/certlookup/4627835-016/61/');20    expect(certUrl('4627835-016')).toBe('https://www.ngccoin.com/certlookup/4627835-016/');21    expect(certFromUrl('https://www.ngccoin.com/certlookup/4627835-016/61/')).toBe('4627835-016/61');22    expect(certFromUrl('https://www.ngccoin.com/certlookup/8444762-003/NGCDetails/')).toBe('8444762-003/NGCDetails');23    expect(certFromUrl('https://www.ngccoin.uk/certlookup/4627835-016/61')).toBe('4627835-016/61');24    expect(certFromUrl('https://www.ngccoin.com/population-report/')).toBeNull();25    expect(connector.urlPatterns.some((re) => re.test(certUrl('4627835-016/61')))).toBe(true);26    expect(connector.certIdentifier('4627835-016/61')).toBe('4627835-016');27  });2829  it('parses description, grade, label, price guide and population stats', () => {30    const page = ccgParse(snapshotOf('draped-bust-eagle-ms61'));31    expect(page.fields).toMatchObject({ 'Cert #': '4627835-016', Description: '1795 13 LEAVES $10', Grade: 'MS 61', 'Grade Date': '2018-08-29', Label: 'NGC Standard Brown' });32    expect(page.atGrade).toBe(7);33    expect(page.popGradeKey).toBe('MS 61');34    expect(page.stats.some((s) => /^\$[\d,]+/.test(s))).toBe(true);35    expect(page.images.length).toBeGreaterThanOrEqual(2);36    expect(ccgClassify(snapshotOf('draped-bust-eagle-ms61'))).toBe('found');37  });3839  it('normalises to a coins catalog_item (bare cert identifier) + population_report', async () => {40    const out = await connector.normalize(loadFixture('ngc-cert', 'draped-bust-eagle-ms61').raw);41    const item = out.find((r) => r.kind === 'catalog_item');42    const pop = out.find((r) => r.kind === 'population_report');43    if (item?.kind === 'catalog_item') {44      expect(item.rawTitle).toBe('1795 13 LEAVES $10 NGC MS 61');45      expect(item.attributes).toMatchObject({ categorySlug: 'coins', name: '1795 13 LEAVES $10', year: 1795 });46      expect(item.attributes.identifiers).toEqual({ ngc_cert: '4627835-016' });47      expect(item.grade).toEqual({ grader: 'ngc', grade: 'MS61', qualifier: null, certificationNumber: '4627835-016' });48      expect(item.externalId).toBe('ngc:4627835-016');49      expect(item.attributes.metadata.ngc_price_guide_value_usd).toBe(165000);50    } else throw new Error('catalog_item missing');51    if (pop?.kind === 'population_report') {52      expect(pop.byGrade.MS61).toBe(7);53      expect(pop.sourceUrl).toMatch(/population-report/);54    } else throw new Error('population_report missing');55  });5657  it('handles an NGC Details grade (no numeric grade)', async () => {58    const out = await connector.normalize(loadFixture('ngc-cert', 'capped-bust-half-details').raw);59    const item = out.find((r) => r.kind === 'catalog_item');60    if (item?.kind === 'catalog_item') {61      expect(item.grade.grade).toBe('AU');62      expect(item.grade.qualifier).toMatch(/^Details/);63      expect(item.grade.certificationNumber).toBe('8444762-003');64      expect(item.attributes.year).toBe(1839);65    } else throw new Error('catalog_item missing');66  });6768  it('yields zero records for a not-found cert without throwing', async () => {69    const fx = loadFixture('ngc-cert', 'not-found');70    expect(ccgClassify((fx.raw.payload as { snapshot: string }).snapshot)).toBe('not_found');71    await expect(connector.normalize(fx.raw)).resolves.toEqual([]);72  });73});74