import { describe, expect, it } from 'vitest'; import { ConnectorMetaSchema } from '@rareindex/connectors'; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import metaJson from './meta.json' with { type: 'json' }; import createConnector, { categoryFor, parseLotsPage, parseResultsList, parseUkDate } from './index.js'; const connector = createConnector(ConnectorMetaSchema.parse(metaJson)); describe('historics', () => { runFixtureSuite(connector, it, expect); it('maps lots to GBP hammer sales dated by the sale', async () => { const fx = loadFixture('historics', 'lots-page'); const out = await connector.normalize(fx.raw); expect(out.length).toBeGreaterThan(0); for (const r of out) { if (r.kind !== 'sale') throw new Error('expected sale'); expect(r.currency).toBe('GBP'); expect(r.buyerPremiumIncluded).toBe(false); expect(r.attributes.identifiers.historics_lot).toMatch(/^\d+$/); expect(r.sourceUrl).toMatch(/^https:\/\/www\.historics\.co\.uk\/auction\/lot\//); expect(r.auctionHouse).toBe('Historics Auctioneers'); } }); it('parses dates, the results list and lot cards', () => { expect(parseUkDate('18th Jul, 2026 9:30')).toEqual(new Date(Date.UTC(2026, 6, 18))); expect(parseUkDate('6th Aug, 2026 19:30')).toEqual(new Date(Date.UTC(2026, 7, 6))); const list = `

The Summer Serenade; Windsorview Lakes

Date: 18th Jul, 2026 9:30 Sale number: A075 Lots: 194 blah

`; const a = parseResultsList(list); expect(a).toHaveLength(1); expect(a[0]).toMatchObject({ au: '107', slug: 'a075-the-summer-serenade-windsorview-lakes', saleNumber: 'A075', lotCount: 194, endedOn: '2026-07-18T00:00:00.000Z' }); const lots = `

Lot 101 - 1955 Phillips Panda Autocycle Offered without reserve

Sold £801

Lot 102 - 2006 Nissan Micra

Sold for an undisclosed fee

`; const l = parseLotsPage(lots); expect(l).toHaveLength(2); expect(l[0]).toMatchObject({ lotId: '20016', lotNo: '101', title: '1955 Phillips Panda Autocycle', subtitle: 'Offered without reserve', priceGbp: 801, image: 'https://storagegohistorics.goauction.co.uk/stock/19969-0-small.jpg' }); expect(l[1]!.priceGbp).toBeNull(); expect(categoryFor(a[0]!, '1955 Phillips Panda Autocycle')).toMatchObject({ vehicle: true }); expect(categoryFor({ ...a[0]!, saleNumber: 'W017' }, 'Porsche dealership sign')).toMatchObject({ categorySlug: 'automotive_memorabilia' }); expect(categoryFor({ ...a[0]!, saleNumber: 'W015' }, 'Registration number 1 ABC')).toMatchObject({ categorySlug: 'license_plates' }); }); });