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%
3.7 KB · 65 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';7import { parseNoteGrade } from '../_g2-grading-lib/text.js';89const connector = createConnector(localMeta(meta));10const snapshotOf = (name: string) => (loadFixture('pmg-cert', name).raw.payload as { snapshot: string }).snapshot;1112describe('pmg-cert', () => {13  runFixtureSuite(connector, it, expect);1415  it('builds and recognises PMG cert URLs (grade segment required)', () => {16    expect(splitCert('8067968-054/67')).toEqual({ number: '8067968-054', grade: '67' });17    expect(certUrl('8067968-054/67')).toBe('https://www.pmgnotes.com/certlookup/8067968-054/67/');18    expect(certUrl('8067968-054')).toBe('https://www.pmgnotes.com/certlookup/8067968-054/');19    expect(certFromUrl('https://www.pmgnotes.com/certlookup/8067968-054/67/')).toBe('8067968-054/67');20    expect(certFromUrl('https://www.pmgnotes.com/certlookup/8067968-054')).toBe('8067968-054');21    expect(certFromUrl('https://www.pmgnotes.com/population-report/')).toBeNull();22    expect(connector.urlPatterns.some((re) => re.test(certUrl('8067968-054/67')))).toBe(true);23    expect(connector.certIdentifier('8067968-054/67')).toBe('8067968-054');24  });2526  it('parses note description, Pick number, grade (+EPQ) and population', () => {27    const page = ccgParse(snapshotOf('bermuda-specimen-67epq'));28    expect(page.fields).toMatchObject({ 'PMG Cert': '8067968-054', 'Note #': 'BER31as', Region: 'BER', Grade: '67 EPQ', 'Grade Date': '2019-12-20', Comments: 'Exceptional Paper Quality' });29    expect(page.fields['Note Description']).toMatch(/^Bermuda, Monetary Authority/);30    expect(page.atGrade).toBe(7);31    expect(page.higher).toBe(1);32    expect(page.popGradeKey).toBe('67EPQ');33    expect(page.images.length).toBe(2);34    expect(ccgClassify(snapshotOf('bermuda-specimen-67epq'))).toBe('found');35  });3637  it('normalises to a banknotes catalog_item + population_report', async () => {38    const out = await connector.normalize(loadFixture('pmg-cert', 'bermuda-specimen-67epq').raw);39    const item = out.find((r) => r.kind === 'catalog_item');40    const pop = out.find((r) => r.kind === 'population_report');41    if (item?.kind === 'catalog_item') {42      expect(item.attributes).toMatchObject({ categorySlug: 'banknotes', year: 1974, country: 'Bermuda', region: 'BER' });43      expect(item.attributes.identifiers).toEqual({ pick_number: 'BER31as', pmg_cert: '8067968-054' });44      expect(item.grade).toEqual({ grader: 'pmg', grade: '67', qualifier: 'EPQ', certificationNumber: '8067968-054' });45      expect(item.attributes.metadata.serial_number).toMatch(/000000/);46    } else throw new Error('catalog_item missing');47    if (pop?.kind === 'population_report') {48      expect(pop.byGrade).toEqual({ '67 EPQ': 7, higher: 1 });49      expect(pop.total).toBe(8);50    } else throw new Error('population_report missing');51  });5253  it('a wrong grade in the URL is a not-found page → zero records, no throw', async () => {54    const fx = loadFixture('pmg-cert', 'wrong-grade-not-found');55    expect(ccgClassify((fx.raw.payload as { snapshot: string }).snapshot)).toBe('not_found');56    await expect(connector.normalize(fx.raw)).resolves.toEqual([]);57  });5859  it('parses PMG grade labels', () => {60    expect(parseNoteGrade('67 EPQ')).toMatchObject({ grade: '67', qualifier: 'EPQ' });61    expect(parseNoteGrade('58')).toMatchObject({ grade: '58', qualifier: null });62    expect(parseNoteGrade('Net 30')).toMatchObject({ grade: '30', qualifier: 'Net' });63  });64});65