import { describe, expect, it } from 'vitest'; import type { NormalizedRecord } from '@rareindex/shared'; import { ConnectorMetaSchema } from '@rareindex/connectors'; import { listFixtures, loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import metaJson from './meta.json' with { type: 'json' }; import createConnector, { lotsFromJson, parseResultDetail, parseResultsIndex } from './index.js'; const meta = ConnectorMetaSchema.parse(metaJson); const connector = createConnector(meta); const attrsOf = (r: NormalizedRecord) => { if (!('attributes' in r)) throw new Error(`record kind ${r.kind} has no attributes`); return r.attributes; }; const INDEX = `
Auktion 1296
01.07.2026 14:00, Brussels
Auktion 1293

Asiatische Kunst

12.06.2026 10:00, Köln
`; const DETAIL = `
27.11.2015, 18:00|Moderne Kunst|Köln

Auktionsergebnisse zu Auktion 1059 - Moderne Kunst

Alle Ergebnisse beinhalten den Zuschlagspreis und das Aufgeld (ohne Gewähr).

`; const JSON_LOTS = { lots: [ { uid: 125134, number: 301, position: '', state: 'Z', hammerprice: 74400, hammerprice_type: 'B', estimate: 60000, estimate_to: 80000, title: 'Raoul Dufy', subtitle: "Le funiculaire à L'Estaque", description: 'Öl auf Leinwand 1908', link: 'https://www.lempertz.com/de/kataloge/lot/1059-1/301-raoul-dufy.html' }, { uid: 125272, number: 300, position: '', state: 'K', hammerprice: 0, estimate: 90000, estimate_to: 110000, title: 'Kees van Dongen', subtitle: 'Femme nue au lierre', link: '/de/kataloge/lot/1059-1/300-kees-van-dongen.html' }, { uid: 1, number: 12, position: 'A', state: 'V', hammerprice: 1200, estimate: 800, estimate_to: 1200, title: 'Rolex', subtitle: 'Datejust Ref. 16233, Stahl/Gold', link: '/x.html' }, ] }; describe('lempertz', () => { runFixtureSuite(connector, it, expect); it('fixtures: premium-inclusive EUR sales, unsold → auction_lot', async () => { let sales = 0; let lots = 0; for (const name of listFixtures('lempertz')) { for (const r of await connector.normalize(loadFixture('lempertz', name).raw)) { if (r.kind === 'sale') { sales++; expect(r.currency).toBe('EUR'); expect(r.buyerPremiumIncluded).toBe(true); expect(r.auctionHouse).toBe('Lempertz'); expect(r.attributes.identifiers.lempertz_lot).toMatch(/^\d+-\d+-.+\/\S+$/); expect(r.sourceUrl).toMatch(/^https:\/\/www\.lempertz\.com\//); } else if (r.kind === 'auction_lot') lots++; } } expect(sales).toBeGreaterThan(20); expect(lots).toBeGreaterThanOrEqual(0); }); it('parses the results index (German dates, city)', () => { const sales = parseResultsIndex(INDEX); expect(sales).toHaveLength(2); expect(sales[0]).toMatchObject({ id: '1296-1-african-and-oceanic-art', title: 'African and Oceanic Art', url: 'https://www.lempertz.com/de/auktionen/ergebnisse/detail/1296-1-african-and-oceanic-art.html', date: '2026-07-01T00:00:00.000Z', location: 'Brussels' }); expect(sales[0]!.extra.auction_no).toBe('1296'); expect(sales[1]!.date).toBe('2026-06-12T00:00:00.000Z'); }); it('parses the detail page header and the JSON lots', async () => { const d = parseResultDetail(DETAIL); expect(d).toMatchObject({ catalogueUid: '245', language: 'de', dateText: '27.11.2015, 18:00', location: 'Köln', premiumNote: true }); const sale = { id: '1059-1-moderne-kunst', title: 'Moderne Kunst', url: 'https://www.lempertz.com/de/auktionen/ergebnisse/detail/1059-1-moderne-kunst.html', date: '2015-11-27T00:00:00.000Z', location: 'Köln', extra: {} }; const lots = lotsFromJson(JSON_LOTS, sale); expect(lots).toHaveLength(3); expect(lots[0]).toMatchObject({ lotNo: '301', title: 'Raoul Dufy', subtitle: "Le funiculaire à L'Estaque", price: 74400, currency: 'EUR', premiumIncluded: true, estimateLow: 60000, estimateHigh: 80000, sold: true }); expect(lots[1]).toMatchObject({ lotNo: '300', price: null, sold: false, url: 'https://www.lempertz.com/de/kataloge/lot/1059-1/300-kees-van-dongen.html' }); expect(lots[2]).toMatchObject({ lotNo: '12A', extra: { under_reserve: true } }); const out = await connector.normalize({ url: sale.url, kind: 'sale', engine: 'api', fetchedAt: new Date(), payload: { kind: 'sale_results', url: sale.url, sale, page: 1, totalLots: 3, lots } }); expect(out.map((r) => r.kind)).toEqual(['sale', 'auction_lot', 'sale']); expect(attrsOf(out[0]!).categorySlug).toBe('contemporary_art'); expect(attrsOf(out[2]!).categorySlug).toBe('rolex'); expect(attrsOf(out[2]!).reference).toBe('16233'); if (out[0]!.kind === 'sale') expect(out[0]!.saleDate.toISOString()).toBe('2015-11-27T00:00:00.000Z'); expect(lotsFromJson({ error: true }, sale)).toEqual([]); }); });