import { describe, expect, it } from 'vitest'; import { getConnectorMeta } from '@rareindex/connectors'; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import createConnector, { lastUpdateDate, parseDescription } from './index.js'; const connector = createConnector(getConnectorMeta('pcgs-priceguide')); describe('pcgs-priceguide', () => { runFixtureSuite(connector, it, expect); it('maps rows to coin catalog items + per-grade guide values', async () => { const fx = loadFixture('pcgs-priceguide', 'morgan-dollar-ms'); const out = await connector.normalize(fx.raw); const cats = out.filter((r) => r.kind === 'catalog_item'); expect(cats.length).toBe(12); const first = cats[0]; if (first?.kind !== 'catalog_item') throw new Error(); expect(first.attributes.identifiers.pcgs_number).toMatch(/^\d+$/); expect(first.attributes.year).toBeGreaterThanOrEqual(1878); expect(first.attributes.country).toBe('US'); const obs = out.filter((r) => r.kind === 'price_observation'); expect(obs.length).toBeGreaterThan(50); for (const o of obs) { if (o.kind !== 'price_observation') throw new Error(); expect(o.grade.grader).toBe('pcgs'); expect(o.grade.grade).toMatch(/^[A-Z]{2,4}\d{1,2}\+?$/); expect(o.priceKind).toBe('guide_value'); expect(o.currency).toBe('USD'); expect(o.observationDate.toISOString().slice(0, 10)).toBe('2026-09-06'); } // plus grades are separate observations expect(obs.some((o) => o.kind === 'price_observation' && o.grade.grade?.endsWith('+'))).toBe(true); }); it('helpers', () => { expect(parseDescription('1878 8TF')).toEqual({ year: 1878, mintMark: null, variety: '8TF' }); expect(parseDescription('1893-S')).toEqual({ year: 1893, mintMark: 'S', variety: null }); expect(parseDescription('1921-D')).toEqual({ year: 1921, mintMark: 'D', variety: null }); expect(lastUpdateDate('09-06 10:59 PM EST', new Date('2026-09-07T05:00:00Z')).toISOString().slice(0, 10)).toBe('2026-09-06'); expect(lastUpdateDate('12-30 10:59 PM EST', new Date('2026-01-02T05:00:00Z')).toISOString().slice(0, 10)).toBe('2025-12-30'); expect(lastUpdateDate(null, new Date('2026-01-02T05:00:00Z')).toISOString()).toBe('2026-01-02T05:00:00.000Z'); }); });