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, { parseAuctionList, parseLotPage, whiskyFacts } from './index.js'; const connector = createConnector(ConnectorMetaSchema.parse(metaJson)); describe('scotch-whisky-auctions', () => { runFixtureSuite(connector, it, expect); it('maps lots to GBP hammer-price auction sales dated by the auction end', async () => { const fx = loadFixture('scotch-whisky-auctions', 'auction-page-1'); const out = await connector.normalize(fx.raw); expect(out.length).toBeGreaterThanOrEqual(10); for (const r of out) { if (r.kind !== 'sale') throw new Error('expected sale'); expect(r.currency).toBe('GBP'); expect(r.buyerPremiumIncluded).toBe(false); expect(r.saleType).toBe('auction'); expect(['whisky', 'rum', 'cognac']).toContain(r.attributes.categorySlug); expect(r.attributes.identifiers.swa_item).toMatch(/^\d+$/); expect(r.sourceUrl).toMatch(/^https:\/\/www\.scotchwhiskyauctions\.com\/auctions\/\d+-/); } }); it('parses list and lot pages', () => { const list = `

The 181st Auction

Ended July 12, 2026
There are 4926 lots in this auction

The 183rd Auction

Ends September 13, 2026
There are 4624 lots in this auction
`; const auctions = parseAuctionList(list); expect(auctions).toHaveLength(2); expect(auctions[0]).toMatchObject({ id: '230', slug: 'the-181st-auction', ended: true, lotCount: 4926, endedOn: '2026-07-12T00:00:00.000Z' }); expect(auctions[1]!.ended).toBe(false); const page = `

Macallan 1989 18 Year Old Gran Reserva 70cl

Lot no 181-02514

Sold for £1,250 in July 2026

`; const p = parseLotPage(page, 'u', auctions[0]!, 1); expect(p.totalPages).toBe(247); expect(p.lots[0]).toMatchObject({ itemId: '885566', lotNo: '181-02514', priceGbp: 1250, image: 'https://x/img.jpg' }); }); it('extracts whisky facts without guessing', () => { expect(whiskyFacts('Macallan 1989 18 Year Old Gran Reserva 70cl')).toMatchObject({ brand: 'Macallan', age: 18, vintage: 1989, size: '70cl', categorySlug: 'whisky' }); expect(whiskyFacts('Springbank 10 Year Old 75cl')).toMatchObject({ brand: 'Springbank', age: 10, vintage: null }); expect(whiskyFacts('Appleton Estate 21 Year Old Rum')).toMatchObject({ categorySlug: 'rum', age: 21 }); expect(whiskyFacts('Hennessy XO Cognac 1L')).toMatchObject({ categorySlug: 'cognac', size: '1L' }); }); });