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, { parseSoldPage } 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 SAMPLE = `Showing 26,189 lots - [![2013 Land Rover Discovery 4 5.0 V8](https://images.collectingcars.com/091453/AS-17-08-14.jpg?w=3840&q=75)\\\\ \\\\ Sold](https://collectingcars.com/for-sale/2013-land-rover-discovery-4-5-0l-v8-2) [Sold\\\\ \\\\ **2013 Land Rover Discovery 4 5.0 V8** \\\\ \\\\ Sold\\\\ \\\\ £17,000\\\\ \\\\ 06/09/2026\\\\ \\\\ ![United Kingdom](https://flagcdn.com/gb.svg)Gatwick](https://collectingcars.com/for-sale/2013-land-rover-discovery-4-5-0l-v8-2) - [![1997 Porsche 911 (993) Targa - Manual](https://images.collectingcars.com/091764/25-08-26-JJBB-06.jpg?w=3840&q=75)\\\\ \\\\ Sold](https://collectingcars.com/for-sale/1997-porsche-911-993-targa-17) [Sold\\\\ \\\\ **1997 Porsche 911 (993) Targa - Manual** \\\\ \\\\ 06/09/2026\\\\ Sign in to view sold price\\\\ \\\\ ![United Kingdom](https://flagcdn.com/gb.svg)Bristol](https://collectingcars.com/for-sale/1997-porsche-911-993-targa-17) `; describe('collecting-cars', () => { runFixtureSuite(connector, it, expect); it('keeps only lots whose price is public (never the sign-in-gated ones)', () => { const p = parseSoldPage(SAMPLE, 1); expect(p.total).toBe(26189); expect(p.items.length).toBe(1); expect(p.items[0]).toMatchObject({ slug: '2013-land-rover-discovery-4-5-0l-v8-2', priceText: '£17,000', dateText: '06/09/2026', country: 'United Kingdom', town: 'Gatwick' }); }); it('normalises with GBP, dd/mm/yyyy date and hammer semantics', async () => { const out = await connector.normalize({ url: 'https://collectingcars.com/sold', externalId: 'sold:1', kind: 'sale', engine: 'firecrawl', fetchedAt: new Date('2026-09-07T00:00:00Z'), payload: parseSoldPage(SAMPLE, 1) }); expect(out.length).toBe(1); const s = out[0]!; if (s.kind !== 'sale') throw new Error('sale expected'); expect(s).toMatchObject({ price: 17000, currency: 'GBP', buyerPremiumIncluded: false, auctionHouse: 'Collecting Cars', location: 'Gatwick, United Kingdom' }); expect(s.saleDate.toISOString()).toBe('2026-09-06T00:00:00.000Z'); expect(s.attributes).toMatchObject({ brand: 'Land Rover', year: 2013, categorySlug: 'automobiles' }); }); it('fixture records have currencies and dates', async () => { const out = await connector.normalize(loadFixture('collecting-cars', 'sold-page').raw); for (const r of out) if (r.kind === 'sale') expect(['GBP', 'EUR', 'AUD', 'USD', 'AED', 'CAD', 'NZD', 'CHF']).toContain(r.currency); }); });