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, { classify, trimItem, watchReference } from './index.js'; const connector = createConnector(ConnectorMetaSchema.parse(metaJson)); describe('pcarmarket', () => { runFixtureSuite(connector, it, expect); it('maps sold items to USD auction sales without premium', async () => { const fx = loadFixture('pcarmarket', '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(r.currency).toBe('USD'); expect(r.buyerPremiumIncluded).toBe(false); expect(r.attributes.identifiers.pcarmarket_id).toMatch(/^\d+$/); expect(r.sourceUrl).toMatch(/^https:\/\/www\.pcarmarket\.com\/auction\//); expect(r.saleDate.getTime()).toBeLessThan(Date.now()); } }); it('classifies cars, watches and automobilia', () => { const car = trimItem({ id: 1, title: 'One-Owner 1983 Porsche 911SC Coupe', slug: 'x', vehicle: { id: 5, make: 'Porsche', model: '911SC', year: 1983, slug_model: 's' }, high_bid: 65000, end_date: '2026-09-04T15:00:07-04:00', status: 'Sold' })!; expect(classify(car)).toMatchObject({ kind: 'vehicle', categorySlug: 'automobiles', brand: 'Porsche' }); const watch = trimItem({ id: 2, title: 'TAG Heuer Gulf Special Edition Watch Ref. CAVZ101 Full Set', slug: 'y', vehicle: null, high_bid: 1250, end_date: '2026-09-03T15:00:00-04:00', status: 'Sold' })!; expect(classify(watch)).toMatchObject({ kind: 'watch', categorySlug: 'other_watches' }); expect(watchReference(watch.title)).toBe('CAVZ101'); const rolex = trimItem({ id: 3, title: '2023 Rolex Daytona Panda Watch Ref. 116500LN Full Set', slug: 'z', vehicle: null, high_bid: 30000, end_date: '2026-09-03T15:00:00-04:00', status: 'Sold' })!; expect(classify(rolex)).toMatchObject({ kind: 'watch', categorySlug: 'rolex' }); const sign = trimItem({ id: 4, title: 'No Reserve Illuminated Porsche Eye Chart Sign', slug: 'w', vehicle: null, high_bid: 250, end_date: '2026-09-03T15:00:00-04:00', status: 'Sold' })!; expect(classify(sign)).toMatchObject({ kind: 'memorabilia', categorySlug: 'automotive_memorabilia' }); }); it('drops unsold and priceless items', async () => { const out = await connector.normalize({ url: 'u', externalId: null, kind: 'sale', engine: 'api', fetchedAt: new Date(), payload: { kind: 'results_page', page: 1, count: 1, items: [{ id: 9, title: '1990 Porsche 964', slug: 'a', vehicle: { make: 'Porsche', model: '964', year: 1990 }, high_bid: 50000, end_date: '2026-09-01T00:00:00Z', status: 'Reserve Not Met' }] } }); expect(out).toHaveLength(0); }); });