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.8 KB · 78 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 { ConnectorMetaSchema } from '@rareindex/connectors';6import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';7import createConnector, { parseAuctionList, parseCatalogPage, pbaCategory } from './index.js';89const dir = path.dirname(fileURLToPath(import.meta.url));10const meta = ConnectorMetaSchema.parse(JSON.parse(readFileSync(path.join(dir, 'meta.json'), 'utf8')));11const connector = createConnector(meta);1213const LIST = `- [![Sale 3034](https://pbagalleries.com/images/auction/617_m.jpg)](https://pbagalleries.com/auctions/info/id/667)14- ###### [3034 Sale 3034: EC, MAD, PRE-CODE HORROR and R. CRUMB](https://pbagalleries.com/auctions/info/id/667)1516[Live](https://pbagalleries.com/auctions/info/id/667),17[04/25/2024 11:00 AM PDT](https://pbagalleries.com/auctions/info/id/667),18[Sale closed](https://pbagalleries.com/auctions/info/id/667)1920Lots: 42921`;2223const 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)2425_[Lot #2](https://pbagalleries.com/lot-details/index/catalog/667/lot/225917/ADVENTURES-INTO-TERROR-No-43-1st-Issue?url=x)_2627## [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)2829  - Title3031    ADVENTURES INTO TERROR No. 43 \\* 1st Issue3233  - Publisher3435    Atlas \\[Indicia: Cutlass Comics\\]3637  - Date Published3839    December, 19524041  - Estimate$300 \\- $50042  - Sold for$281.2543  - StatusSold44`;4546describe('pba-galleries', () => {47  runFixtureSuite(connector, it, expect);4849  it('parses the auction list and a catalog page', () => {50    const auctions = parseAuctionList(LIST);51    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 }]);52    const page = parseCatalogPage(CATALOG, auctions[0]!, 1);53    expect(page.lots.length).toBe(1);54    expect(page.lots[0]).toMatchObject({ lotNumber: '2', lotId: '225917', soldText: '$281.25', status: 'Sold', estimateText: '$300 - $500' });55    expect(page.lots[0]!.fields.Publisher).toContain('Atlas');56  });5758  it('normalises with 25% premium included, comics category and issue number', async () => {59    const auction = parseAuctionList(LIST)[0]!;60    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) });61    expect(out.length).toBe(1);62    const s = out[0]!;63    if (s.kind !== 'sale') throw new Error('sale');64    expect(s).toMatchObject({ price: 281.25, currency: 'USD', buyerPremiumIncluded: true, lotNumber: '2', auctionHouse: 'PBA Galleries' });65    expect(s.saleDate.toISOString()).toBe('2024-04-25T00:00:00.000Z');66    expect(s.attributes).toMatchObject({ categorySlug: 'marvel_comics', number: '43', year: 1952 });67    expect(s.grade).toMatchObject({ grader: 'cgc', grade: '4.5' });68    expect(pbaCategory('Fine Books & Manuscripts', { title: 'Moby-Dick, first edition', fields: {} })).toBe('books');69    expect(pbaCategory('Photographs', { title: 'Ansel Adams, Moonrise', fields: {} })).toBe('photography');70  });7172  it('fixture sales are premium-inclusive USD', async () => {73    const out = await connector.normalize(loadFixture('pba-galleries', 'catalog-page').raw);74    expect(out.length).toBeGreaterThan(0);75    for (const r of out) if (r.kind === 'sale') expect(r.currency).toBe('USD');76  });77});78