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, { parseResultsPage, parseSoldText } from './index.js'; const connector = createConnector(ConnectorMetaSchema.parse(metaJson)); describe('the-market-bonhams', () => { runFixtureSuite(connector, it, expect); it('maps result cards to sales dated by the card', async () => { const fx = loadFixture('the-market-bonhams', 'results-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(['GBP', 'EUR', 'AUD', 'USD']).toContain(r.currency); expect(r.buyerPremiumIncluded).toBe(false); expect(['automobiles', 'motorcycles']).toContain(r.attributes.categorySlug); expect(r.attributes.identifiers.themarket_id).toMatch(/^[0-9a-f-]{36}$/); expect(r.sourceUrl).toMatch(/^https:\/\/www\.themarket\.co\.uk\/listings\//); } }); it('parses sold text and cards', () => { expect(parseSoldText('Sold for £56,000 on 17 Aug 2026')).toMatchObject({ amount: 56000, currency: 'GBP', date: new Date(Date.UTC(2026, 7, 17)) }); expect(parseSoldText('Sold for €25,100 on 05 Jan 2023')).toMatchObject({ amount: 25100, currency: 'EUR' }); expect(parseSoldText('Sold for A$41,000 on 1 Feb 2024')).toMatchObject({ amount: 41000, currency: 'AUD' }); expect(parseSoldText('Bid to £10,000')).toBeNull(); const html = `

Sold for £56,000 on 17 Aug 2026

1991 Range Rover Classic

£170k Restoration

THE MARKET HQ, GB
`; const cards = parseResultsPage(html); expect(cards).toHaveLength(1); expect(cards[0]).toMatchObject({ id: '4f12faa9-7308-4e71-a17f-e3ca8db972c3', title: '1991 Range Rover Classic', bids: 43, location: 'THE MARKET HQ, GB', image: 'https://cdn.themarket.co.uk/x/y.jpg' }); }); });