import { describe, expect, it } from 'vitest'; import { readFileSync } from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { ConnectorMetaSchema } from '@rareindex/connectors'; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import createConnector, { parseAuctionList, parseCatalogPage, pbaCategory } from './index.js'; const dir = path.dirname(fileURLToPath(import.meta.url)); const meta = ConnectorMetaSchema.parse(JSON.parse(readFileSync(path.join(dir, 'meta.json'), 'utf8'))); const connector = createConnector(meta); const LIST = `- [![Sale 3034](https://pbagalleries.com/images/auction/617_m.jpg)](https://pbagalleries.com/auctions/info/id/667) - ###### [3034 Sale 3034: EC, MAD, PRE-CODE HORROR and R. CRUMB](https://pbagalleries.com/auctions/info/id/667) [Live](https://pbagalleries.com/auctions/info/id/667), [04/25/2024 11:00 AM PDT](https://pbagalleries.com/auctions/info/id/667), [Sale closed](https://pbagalleries.com/auctions/info/id/667) Lots: 429 `; const CATALOG = `- [![ADVENTURES INTO TERROR No. 43](https://pbagalleries.com/images/lot/5136/513638_m.jpg?ts=1)](https://pbagalleries.com/lot-details/index/catalog/667/lot/225917/ADVENTURES-INTO-TERROR-No-43-1st-Issue?url=%2Fauctions%2Fcatalog%2Fid%2F667) _[Lot #2](https://pbagalleries.com/lot-details/index/catalog/667/lot/225917/ADVENTURES-INTO-TERROR-No-43-1st-Issue?url=x)_ ## [ADVENTURES INTO TERROR \\#43 \\* CGC 4.5 \\* Russ Heath Cover](https://pbagalleries.com/lot-details/index/catalog/667/lot/225917/ADVENTURES-INTO-TERROR-No-43-1st-Issue?url=x) - Title ADVENTURES INTO TERROR No. 43 \\* 1st Issue - Publisher Atlas \\[Indicia: Cutlass Comics\\] - Date Published December, 1952 - Estimate$300 \\- $500 - Sold for$281.25 - StatusSold `; describe('pba-galleries', () => { runFixtureSuite(connector, it, expect); it('parses the auction list and a catalog page', () => { const auctions = parseAuctionList(LIST); expect(auctions).toEqual([{ catalogId: '667', saleNumber: '3034', title: 'Sale 3034: EC, MAD, PRE-CODE HORROR and R. CRUMB', dateText: '04/25/2024', lots: 429, closed: true }]); const page = parseCatalogPage(CATALOG, auctions[0]!, 1); expect(page.lots.length).toBe(1); expect(page.lots[0]).toMatchObject({ lotNumber: '2', lotId: '225917', soldText: '$281.25', status: 'Sold', estimateText: '$300 - $500' }); expect(page.lots[0]!.fields.Publisher).toContain('Atlas'); }); it('normalises with 25% premium included, comics category and issue number', async () => { const auction = parseAuctionList(LIST)[0]!; const out = await connector.normalize({ url: 'x', externalId: 'c', kind: 'sale', engine: 'firecrawl', fetchedAt: new Date('2026-09-07T00:00:00Z'), payload: parseCatalogPage(CATALOG, auction, 1) }); expect(out.length).toBe(1); const s = out[0]!; if (s.kind !== 'sale') throw new Error('sale'); expect(s).toMatchObject({ price: 281.25, currency: 'USD', buyerPremiumIncluded: true, lotNumber: '2', auctionHouse: 'PBA Galleries' }); expect(s.saleDate.toISOString()).toBe('2024-04-25T00:00:00.000Z'); expect(s.attributes).toMatchObject({ categorySlug: 'marvel_comics', number: '43', year: 1952 }); expect(s.grade).toMatchObject({ grader: 'cgc', grade: '4.5' }); expect(pbaCategory('Fine Books & Manuscripts', { title: 'Moby-Dick, first edition', fields: {} })).toBe('books'); expect(pbaCategory('Photographs', { title: 'Ansel Adams, Moonrise', fields: {} })).toBe('photography'); }); it('fixture sales are premium-inclusive USD', async () => { const out = await connector.normalize(loadFixture('pba-galleries', 'catalog-page').raw); expect(out.length).toBeGreaterThan(0); for (const r of out) if (r.kind === 'sale') expect(r.currency).toBe('USD'); }); });