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 = `