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, { parseCatalogPage, parsePastAuctions, swannCategory } 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 = `
`; const CATALOG = ` `; describe('swann', () => { runFixtureSuite(connector, it, expect); it('parses the past-auction list and catalog cards', () => { const auctions = parsePastAuctions(LIST); expect(auctions).toEqual([{ slug: 'autographs_JCJOCA54V5', url: 'https://www.swanngalleries.com/auction-catalog/autographs_JCJOCA54V5', title: 'Autographs', dateText: 'Thursday, November 6, 2025', department: 'Autographs', saleNumber: '2719' }]); const page = parseCatalogPage(CATALOG, auctions[0]!, 1); expect(page.lots.length).toBe(2); expect(page.lots[0]).toMatchObject({ ref: 'C337D422B9', lotNumber: '2', soldText: '$1,188', premiumNote: true, passed: false, estimateText: '$600 - $900' }); expect(page.lots[1]).toMatchObject({ lotNumber: '1', soldText: null, passed: true }); }); it('normalises sold lots only, premium included, dated by the sale', async () => { const auction = parsePastAuctions(LIST)[0]!; const out = await connector.normalize({ url: 'x', externalId: 's', kind: 'sale', engine: 'api', 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: 1188, currency: 'USD', buyerPremiumIncluded: true, lotNumber: '2', auctionHouse: 'Swann Auction Galleries' }); expect(s.saleDate.toISOString()).toBe('2025-11-06T00:00:00.000Z'); expect(s.attributes.categorySlug).toBe('autographs'); expect(swannCategory('Photographs & Photobooks', 'Photographs', 'Ansel Adams')).toBe('photography'); expect(swannCategory('Vintage Posters', 'Posters', 'Casablanca one sheet')).toBe('movie_posters'); expect(swannCategory('Maps & Atlases', 'Maps', 'Blaeu, Americae')).toBe('maps'); }); it('fixture sales are USD with lot refs', async () => { const out = await connector.normalize(loadFixture('swann', 'catalog-page').raw); expect(out.length).toBeGreaterThan(0); for (const r of out) if (r.kind === 'sale') expect(r.attributes.identifiers.swann_lot_ref).toBeTruthy(); }); });