import { describe, expect, it } from 'vitest'; import { getConnectorMeta } from '@rareindex/connectors'; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import createConnector, { parseModelPage } from './index.js'; const connector = createConnector(getConnectorMeta('chrono24')); describe('chrono24', () => { runFixtureSuite(connector, it, expect); it('maps a Rolex Daytona model page to listings', async () => { const fx = loadFixture('chrono24', 'rolex__daytona--mod2'); const out = await connector.normalize(fx.raw); expect(out.length).toBeGreaterThan(20); const l = out[0]; if (l?.kind !== 'listing') throw new Error(); expect(l.attributes.categorySlug).toBe('rolex'); expect(l.attributes.brand).toBe('Rolex'); expect(l.attributes.model).toBe('Daytona'); expect(l.listingType).toBe('fixed_price'); expect(l.price).toBeGreaterThan(1000); expect(l.currency).toBe('USD'); expect(l.sourceUrl).toMatch(/--id\d+\.htm$/); expect(l.attributes.identifiers.chrono24_id).toMatch(/^\d+$/); const withRef = out.filter((r) => r.kind === 'listing' && r.attributes.reference); expect(withRef.length).toBeGreaterThan(out.length / 2); }); it('parses the AggregateOffer JSON-LD', () => { const html = ``; const p = parseModelPage(html, 'https://www.chrono24.com/rolex/daytona--mod2.htm'); expect(p.brand).toBe('Rolex'); expect(p.model).toBe('Daytona'); expect(p.offers).toEqual([{ name: 'Rolex Daytona 116500LN Panda 40mm Full Set 2019', price: 31495, currency: 'USD', url: 'https://www.chrono24.com/rolex/daytona--id48341690.htm', image: 'https://img.chrono24.com/a.jpg' }]); }); it('derives reference, year, size and completeness from the offer name', async () => { const raw = { url: 'https://www.chrono24.com/rolex/daytona--mod2.htm', externalId: null, kind: 'listing' as const, engine: 'scrapfly' as const, fetchedAt: new Date('2026-09-07T00:00:00Z'), payload: { kind: 'model_page', url: 'https://www.chrono24.com/rolex/daytona--mod2.htm', brand: 'Rolex', model: 'Daytona', breadcrumb: [], totalListings: 1, offers: [{ name: 'Rolex Daytona 116500LN Panda 40mm Full Set 2019 Unworn', price: 31495, currency: 'USD', url: 'https://www.chrono24.com/rolex/daytona--id1.htm', image: null }] } }; const [l] = await connector.normalize(raw); if (l?.kind !== 'listing') throw new Error(); expect(l.attributes.reference).toBe('116500LN'); expect(l.attributes.year).toBe(2019); expect(l.attributes.size).toBe('40mm'); expect(l.condition.completeness).toBe('full_set'); expect(l.condition.condition).toBe('unworn'); }); });