import { describe, expect, it } from 'vitest'; import { ConnectorMetaSchema } from '@rareindex/connectors'; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import metaJson from './meta.json' with { type: 'json' }; import createConnector, { parseArchive, parseResultsPdf, wineFacts } from './index.js'; const connector = createConnector(ConnectorMetaSchema.parse(metaJson)); describe('hdh-wine', () => { runFixtureSuite(connector, it, expect); it('maps PDF rows to USD hammer sales, grouping multi-row lots', async () => { const fx = loadFixture('hdh-wine', 'results-pdf'); const out = await connector.normalize(fx.raw); expect(out.length).toBeGreaterThan(0); for (const r of out) { if (r.kind !== 'sale') throw new Error('expected sale'); expect(r.currency).toBe('USD'); expect(r.buyerPremiumIncluded).toBe(false); expect(['wine', 'whisky', 'cognac']).toContain(r.attributes.categorySlug); expect(r.attributes.identifiers.hdh_lot).toMatch(/:\d+/); expect(r.auctionHouse).toBe('Hart Davis Hart Wine Co.'); } }); it('parses the PDF table, header date and archive links', () => { const md = `## Aggregate: 3,892,330 August 27-28, 2026\n\n| Lot | Qty | Description | Estimate | Hammer | Aggregate |\n| --- | --- | --- | --- | --- | --- |\n| 1 | 6 | 1982 Château Ducru-Beaucaillou | 1,600 - 2,400 | 2,200 | 2,629.00 |\n| 5 | 1 | 2009 Château Cos d'Estournel | 500 - 750 | 900 | 1,075.50 |\n| 5 | 1 | 2010 Château Léoville Poyferré | | | |\n| 8 | 1 | 2009 Château d'Yquem (375ml) | 280 - 420 | 500 | 597.50 |\n`; const p = parseResultsPdf(md); expect(p.saleDate).toBe('2026-08-27T00:00:00.000Z'); expect(p.rows).toHaveLength(4); expect(p.rows[0]).toMatchObject({ lot: '1', qty: 6, hammer: 2200, aggregate: 2629 }); expect(p.rows[2]!.hammer).toBeNull(); expect(wineFacts('2009 Château d\'Yquem (375ml)')).toMatchObject({ vintage: 2009, size: '375ml', name: "Château d'Yquem", categorySlug: 'wine' }); expect(wineFacts('2017 La Tâche, Domaine de la Romanée-Conti')).toMatchObject({ producer: 'Domaine de la Romanée-Conti' }); const arch = parseArchive('**An Auction of Finest & Rarest Wines**\n\nJune 25 & 26, 2026\n\n**100% SOLD**\n\n[View auction results](https://hdhauctions.com/wp-content/uploads/2026/07/2606_AuctionResults_PDF.pdf)'); expect(arch).toHaveLength(1); expect(arch[0]).toMatchObject({ pdfUrl: 'https://hdhauctions.com/wp-content/uploads/2026/07/2606_AuctionResults_PDF.pdf', title: 'An Auction of Finest & Rarest Wines', dateText: 'June 25 & 26, 2026' }); }); it('groups a two-row lot into one bundle sale', async () => { const out = await connector.normalize({ url: 'https://hdhauctions.com/wp-content/uploads/2026/08/2608_AuctionResults.pdf', externalId: null, kind: 'sale', engine: 'firecrawl', fetchedAt: new Date(), payload: { kind: 'results_pdf', url: 'https://hdhauctions.com/wp-content/uploads/2026/08/2608_AuctionResults.pdf', auctionName: 'x', saleDate: '2026-08-27T00:00:00.000Z', rows: [{ lot: '5', qty: 1, description: "2009 Château Cos d'Estournel", estimate: '500 - 750', hammer: 900, aggregate: 1075.5 }, { lot: '5', qty: 1, description: '2010 Château Montrose', estimate: null, hammer: null, aggregate: null }] } }); expect(out).toHaveLength(1); const s = out[0]!; if (s.kind !== 'sale') throw new Error('sale'); expect(s.isBundle).toBe(true); expect(s.price).toBe(900); expect(s.lotNumber).toBe('5'); }); });