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, { parseAuctionPage, 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 = `

Special Sales

07.05.2023

Torino

Catalogo

Risultati

Orologi

12.06.2026

Milano

Catalogo

`; const AUCTION = ` Orologi da polso | Aste Bolaffi
Lotto 1

ROLEX SUBMARINER REF. 5513

ROLEX SUBMARINER REF. 5513


Acciaio, anni '70, quadrante nero

Base asta: € 5.000 | Aggiudicato a : € 12.500

Lotto 2

OMEGA SPEEDMASTER

Base asta: € 2.000

`; describe('aste-bolaffi', () => { runFixtureSuite(connector, it, expect); it('fixtures: EUR results ("Aggiudicato a", premium basis unknown)', async () => { let sales = 0; for (const name of listFixtures('aste-bolaffi')) { for (const r of await connector.normalize(loadFixture('aste-bolaffi', name).raw)) { if (!('attributes' in r)) continue; expect(r.attributes.identifiers.bolaffi_lot).toMatch(/^\d+\/\S+$/); expect(r.sourceUrl).toMatch(/^https:\/\/www\.astebolaffi\.it\/it\/lot\/\d+\/\S+\/detail$/); if (r.kind === 'sale') { sales++; expect(r.currency).toBe('EUR'); expect(r.buyerPremiumIncluded).toBeNull(); expect(r.auctionHouse).toBe('Aste Bolaffi'); } } } expect(sales).toBeGreaterThan(5); }); it('parses the results index (Italian dates, departments) and an auction page (Italian prices, pagination)', async () => { const sales = parseResultsIndex(INDEX); expect(sales.map((s) => s.id)).toEqual(['1204', '3011']); expect(sales[0]).toMatchObject({ date: '2023-05-07T00:00:00.000Z', location: 'Torino, Italy', url: 'https://www.astebolaffi.it/it/auction/1204' }); expect(sales[0]!.extra.department).toBe('Special Sales'); expect(sales[1]!.title).toBe('Orologi — Asta 3011'); const p = parseAuctionPage(AUCTION, sales[1]!, 1)!; expect(p.hasMore).toBe(true); expect(parseAuctionPage(AUCTION, sales[1]!, 9)!.hasMore).toBe(false); expect(p.sale?.date).toBe('2026-06-12T00:00:00.000Z'); expect(p.lots).toHaveLength(2); expect(p.lots[0]).toMatchObject({ lotNo: '1', title: 'ROLEX SUBMARINER REF. 5513', price: 12500, currency: 'EUR', premiumIncluded: null, estimateLow: 5000, sold: true, url: 'https://www.astebolaffi.it/it/lot/3011/1/detail', image: 'https://www.astebolaffi.it/storage/lots/3011/1.jpg' }); expect(p.lots[0]!.description).toContain("Acciaio, anni '70"); expect(p.lots[1]).toMatchObject({ lotNo: '2', price: null, sold: false, estimateLow: 2000 }); 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 }, page: 1, totalLots: null, lots: p.lots } }); expect(out.map((r) => r.kind)).toEqual(['sale', 'auction_lot']); expect(attrsOf(out[0]!).categorySlug).toBe('rolex'); expect(attrsOf(out[0]!).reference).toBe('5513'); expect(attrsOf(out[1]!).categorySlug).toBe('omega'); expect(parseAuctionPage('x', sales[1]!, 1)).toBeNull(); }); });