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.6 KB · 53 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import { readFileSync } from 'node:fs';3import path from 'node:path';4import { fileURLToPath } from 'node:url';5import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';6import { localMeta } from '../_lib/local-meta.js';7import createConnector, { dlrcGrade, LotSchema } from './index.js';89const dir = path.dirname(fileURLToPath(import.meta.url));10const connector = createConnector(localMeta(JSON.parse(readFileSync(path.join(dir, 'meta.json'), 'utf8'))));1112const LOT = {13  auctionId: 24, lotId: 9580, lotNumber: 7001, totalBids: 2, lotCurrentBid: 265500, lotClosesAt: '2023-09-18T00:00:00Z', soldInAuction: true, id: 752042, itemType: 'US_COIN',14  name: '1793 1/2C NGC/CAC Poor 01', shortDescription: 'First Year Half Cent', description: 'A rare coin in exciting, lowball condition!', seriesName: 'Liberty Cap Half Cent', groupName: 'Half-Cents and Cents', categoryName: 'U.S. Coins',15  certificationNumber: '6460687001', gradingService: 'NGC', grade: 1, fullGrade: 'PO1BN', isPlus: false, isCac: true, isEPQ: false, price: null, salePrice: 265500, status: 'SOLD',16  catalogEntry: { id: 3915, pcgsNumber: 1000, title: '1793 1/2C, BN', denomination: '1/2C', coinDate: 1793, mintMark: 'P', designation: 'BN', majorVariety: '', dieVariety: '', strikeType: 'MS', mintage: 35334, numistaTypeId: null, kmNumber: null, categoryName: 'Liberty Cap Half Cent' },17  images: [{ thumbnailUrl: 'https://d2lj9qe62mju4a.cloudfront.net/inventory/3/752042/a.jpg?width=256&height=256', url: 'https://d2lj9qe62mju4a.cloudfront.net/inventory/3/752042/a.jpg' }],18};19const UNSOLD = { ...LOT, id: 1, lotId: 2, salePrice: null, lotCurrentBid: 1000, soldInAuction: false, status: 'AVAILABLE' };2021describe('dlrc', () => {22  runFixtureSuite(connector, it, expect);2324  it('maps grading service / full grade / CAC / details into the grade block', () => {25    expect(dlrcGrade(LotSchema.parse(LOT))).toEqual({ grader: 'ngc', grade: 'PO1BN', qualifier: 'CAC', certificationNumber: '6460687001' });26    expect(dlrcGrade({ gradingService: 'ANACS', fullGrade: 'VG8BN', grade: 8, isPlus: false, isCac: false, certificationNumber: null, name: '1804 1/2C ANACS VG Details (Plain 4, No Stems, Damaged)' })).toMatchObject({ grader: 'anacs', grade: 'VG8BN', qualifier: 'VG Details (Plain 4, No Stems, Damaged)' });27    expect(dlrcGrade({ gradingService: 'PCGS', fullGrade: 'MS65', grade: 65, isPlus: true, isCac: false, certificationNumber: '12345678', name: '1881-S $1 PCGS MS65+' }).grade).toBe('MS65+');28  });2930  it('normalises sold lots: cents → dollars, no buyer premium, cert + PCGS number identifiers, unsold skipped', async () => {31    const payload = { kind: 'past_auction_page' as const, url: 'https://api.collectiblesshowcase.com/consumer/inventory/past/auction?auctions=24&pageNumber=1&pageSize=100', auctionId: 24, auctionTitle: 'Test', pageNumber: 1, totalPages: 1, totalItems: 2, lots: [LOT, UNSOLD] };32    const out = await connector.normalize({ url: payload.url, externalId: 'x', kind: 'sale', engine: 'api', fetchedAt: new Date('2026-09-08T00:00:00Z'), payload });33    expect(out.length).toBe(1);34    const s = out[0]!;35    if (s.kind !== 'sale') throw new Error('sale');36    expect(s).toMatchObject({ price: 2655, currency: 'USD', buyerPremiumIncluded: true, lotNumber: '7001', auctionHouse: 'David Lawrence Rare Coins', sourceUrl: 'https://www.davidlawrence.com/inventory/752042', isBundle: false });37    expect(s.saleDate.toISOString()).toBe('2023-09-18T00:00:00.000Z');38    expect(s.grade).toEqual({ grader: 'ngc', grade: 'PO1BN', qualifier: 'CAC', certificationNumber: '6460687001' });39    expect(s.attributes).toMatchObject({ categorySlug: 'coins', year: 1793, country: 'US', series: 'Liberty Cap Half Cent', variant: 'P mint' });40    expect(s.attributes.identifiers).toEqual({ dlrc_inventory_id: '752042', pcgs_number: '1000', ngc_cert: '6460687001' });41    expect(s.attributes.metadata).toMatchObject({ mintage: 35334, denomination: '1/2C', designation: 'BN' });42    expect(s.imageUrls).toEqual(['https://d2lj9qe62mju4a.cloudfront.net/inventory/3/752042/a.jpg']);43  });4445  it('fixture pages normalise to USD sales with grades', async () => {46    const out = await connector.normalize(loadFixture('dlrc', 'auction-337-page-1').raw);47    expect(out.length).toBeGreaterThan(3);48    for (const r of out) if (r.kind === 'sale') expect(r).toMatchObject({ currency: 'USD', buyerPremiumIncluded: true });49    const legacy = await connector.normalize(loadFixture('dlrc', 'archive-page-legacy-lots').raw);50    expect(legacy.some((r) => r.kind === 'sale' && r.saleDate.getUTCFullYear() < 2020)).toBe(true);51  });52});53