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, { parseAuctionSnapshot, parsePastSales, parseSalePage } 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 = `

juillet 2026

Online Only

Design Online

Bijoux & Horlogerie

`; const SALE = `

Bijoux & Horlogerie

Résultat (Frais de vente inclus)
01

CARTIER, Paris

Années 1900-10
Estimation
6 000 / 8 000 €
Résultat
23 878 €
02

FRÈRES ROCHAT, Suisse

Vers 1810
Estimation
30 000 / 40 000 €
`; describe('piasa', () => { runFixtureSuite(connector, it, expect); it('fixtures: EUR premium-inclusive results', async () => { let sales = 0; for (const name of listFixtures('piasa')) { for (const r of await connector.normalize(loadFixture('piasa', name).raw)) { if (!('attributes' in r)) continue; expect(r.attributes.identifiers.piasa_lot).toMatch(/^[a-z0-9_-]+\/\S+$/); expect(r.sourceUrl).toMatch(/^https:\/\/www\.piasa\.fr\/fr\/products\//); if (r.kind === 'sale') { sales++; expect(r.currency).toBe('EUR'); expect(r.buyerPremiumIncluded).toBe(true); expect(r.auctionHouse).toBe('PIASA'); } } } expect(sales).toBeGreaterThan(5); }); it('parses the past-sales index, the Livewire snapshot and the inlined product cards', async () => { const sales = parsePastSales(INDEX); expect(sales.map((s) => s.id)).toEqual(['design-online-t2442', 'bijoux-horlogerie_20260218']); expect(sales[0]).toMatchObject({ title: 'Design Online', url: 'https://www.piasa.fr/fr/auctions/design-online-t2442', location: 'Online' }); expect(parseAuctionSnapshot(SALE)).toMatchObject({ startDate: '2026-02-13 18:00', endDate: '2026-02-23 18:00', place: 'Online', number: '2381', status: 'finished' }); const p = parseSalePage(SALE, sales[1]!)!; expect(p.hasMore).toBe(false); expect(p.sale).toMatchObject({ date: '2026-02-23T00:00:00.000Z', location: 'Online' }); expect(p.lots).toHaveLength(2); expect(p.lots[0]).toMatchObject({ lotNo: '01', title: 'CARTIER, Paris', subtitle: 'Années 1900-10', price: 23878, currency: 'EUR', premiumIncluded: true, estimateLow: 6000, estimateHigh: 8000, sold: true, url: 'https://www.piasa.fr/fr/products/cartier-paris-1-2381-fr', image: 'https://www.piasa.fr/image/resized/abc/320/480' }); expect(p.lots[1]).toMatchObject({ lotNo: '02', price: null, sold: false, estimateLow: 30000, estimateHigh: 40000 }); const out = await connector.normalize({ url: sales[1]!.url, kind: 'sale', engine: 'api', fetchedAt: new Date(), payload: { kind: 'sale_results', url: sales[1]!.url, sale: { ...sales[1]!, ...p.sale, extra: { ...sales[1]!.extra, ...p.sale!.extra } }, page: 1, totalLots: 2, lots: p.lots } }); expect(out.map((r) => r.kind)).toEqual(['sale', 'auction_lot']); if (out[0]!.kind === 'sale') expect(out[0]!.saleDate.toISOString()).toBe('2026-02-23T00:00:00.000Z'); expect(['jewelry', 'other_watches']).toContain(attrsOf(out[0]!).categorySlug); expect(parseSalePage('x', sales[1]!)).toBeNull(); }); });