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, { parseLotsPage, parsePastAuctions, parseViewVars } 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 PAST = ``; const LOTS = ``; describe('bernaerts', () => { runFixtureSuite(connector, it, expect); it('fixtures: EUR hammer sales from the embedded AuctionMobility JSON', async () => { let sales = 0; for (const name of listFixtures('bernaerts')) { for (const r of await connector.normalize(loadFixture('bernaerts', name).raw)) { if (!('attributes' in r)) continue; expect(r.attributes.identifiers.bernaerts_lot).toMatch(/^4-[A-Z0-9]+\/\S+$/); expect(r.sourceUrl).toMatch(/^https:\/\/live\.bernaerts\.eu\//); if (r.kind === 'sale') { sales++; expect(r.currency).toBe('EUR'); expect(r.buyerPremiumIncluded).toBe(false); expect(r.auctionHouse).toBe('Bernaerts'); } } } expect(sales).toBeGreaterThan(10); }); it('parses viewVars, the past-auction list and a lots page (pagination from query_info)', async () => { expect(parseViewVars('
no
')).toBeNull(); const sales = parsePastAuctions(PAST); expect(sales).toHaveLength(1); expect(sales[0]).toMatchObject({ id: '4-KD099X', title: 'Modern vs. Classic (Lot 100-402)', url: 'https://live.bernaerts.eu/auctions/4-KD099X/modern-vs-classic-lot-100-402', date: '2026-03-31T12:00:00Z', location: 'Antwerp, Belgium' }); expect(sales[0]!.extra.total_hammer_price).toBe(411000); const p = parseLotsPage(LOTS, sales[0]!)!; expect(p.totalLots).toBe(298); expect(p.hasMore).toBe(true); expect(p.lots).toHaveLength(2); expect(p.lots[0]).toMatchObject({ lotNo: '100', price: 7000, currency: 'EUR', premiumIncluded: false, estimateLow: 3000, estimateHigh: 4000, sold: true, url: 'https://live.bernaerts.eu/lots/view/4-KDZAWS/a-shang-dynasty-wine-jug', image: 'https://images4-cdn.auctionmobility.com/x/0100.jpg', description: 'Bronze, H 28 cm.' }); expect(p.lots[1]).toMatchObject({ lotNo: '101A', price: null, sold: false }); const out = await connector.normalize({ url: sales[0]!.url, kind: 'sale', engine: 'api', fetchedAt: new Date(), payload: { kind: 'sale_results', url: sales[0]!.url, sale: sales[0]!, page: 1, totalLots: 298, lots: p.lots } }); expect(out.map((r) => r.kind)).toEqual(['sale', 'auction_lot']); expect(attrsOf(out[0]!).categorySlug).toBe('antiques'); expect(attrsOf(out[1]!).categorySlug).toBe('rolex'); expect(attrsOf(out[1]!).reference).toBe('5513'); if (out[0]!.kind === 'sale') expect(out[0]!.saleDate.toISOString()).toBe('2026-03-31T12:00:00.000Z'); expect(parseLotsPage('', sales[0]!)).toBeNull(); }); });