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%
2.3 KB · 44 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import { getConnectorMeta } from '@rareindex/connectors';3import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';4import createConnector, { lastUpdateDate, parseDescription } from './index.js';56const connector = createConnector(getConnectorMeta('pcgs-priceguide'));78describe('pcgs-priceguide', () => {9  runFixtureSuite(connector, it, expect);1011  it('maps rows to coin catalog items + per-grade guide values', async () => {12    const fx = loadFixture('pcgs-priceguide', 'morgan-dollar-ms');13    const out = await connector.normalize(fx.raw);14    const cats = out.filter((r) => r.kind === 'catalog_item');15    expect(cats.length).toBe(12);16    const first = cats[0];17    if (first?.kind !== 'catalog_item') throw new Error();18    expect(first.attributes.identifiers.pcgs_number).toMatch(/^\d+$/);19    expect(first.attributes.year).toBeGreaterThanOrEqual(1878);20    expect(first.attributes.country).toBe('US');21    const obs = out.filter((r) => r.kind === 'price_observation');22    expect(obs.length).toBeGreaterThan(50);23    for (const o of obs) {24      if (o.kind !== 'price_observation') throw new Error();25      expect(o.grade.grader).toBe('pcgs');26      expect(o.grade.grade).toMatch(/^[A-Z]{2,4}\d{1,2}\+?$/);27      expect(o.priceKind).toBe('guide_value');28      expect(o.currency).toBe('USD');29      expect(o.observationDate.toISOString().slice(0, 10)).toBe('2026-09-06');30    }31    // plus grades are separate observations32    expect(obs.some((o) => o.kind === 'price_observation' && o.grade.grade?.endsWith('+'))).toBe(true);33  });3435  it('helpers', () => {36    expect(parseDescription('1878 8TF')).toEqual({ year: 1878, mintMark: null, variety: '8TF' });37    expect(parseDescription('1893-S')).toEqual({ year: 1893, mintMark: 'S', variety: null });38    expect(parseDescription('1921-D')).toEqual({ year: 1921, mintMark: 'D', variety: null });39    expect(lastUpdateDate('09-06 10:59 PM EST', new Date('2026-09-07T05:00:00Z')).toISOString().slice(0, 10)).toBe('2026-09-06');40    expect(lastUpdateDate('12-30 10:59 PM EST', new Date('2026-01-02T05:00:00Z')).toISOString().slice(0, 10)).toBe('2025-12-30');41    expect(lastUpdateDate(null, new Date('2026-01-02T05:00:00Z')).toISOString()).toBe('2026-01-02T05:00:00.000Z');42  });43});44