SPB Git forge

spb/rareindex

Public
54commits 1branches 0releases
7.1 MBsize
maindefault branch
10 days agolast push
TypeScript 61.9% HTML 37.2% SQL 0.7%
3.0 KB · 46 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import { ConnectorMetaSchema } from '@rareindex/connectors';3import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';4import metaJson from './meta.json' with { type: 'json' };5import createConnector, { parseAuctionList, parseLotPage, whiskyFacts } from './index.js';67const connector = createConnector(ConnectorMetaSchema.parse(metaJson));89describe('scotch-whisky-auctions', () => {10  runFixtureSuite(connector, it, expect);1112  it('maps lots to GBP hammer-price auction sales dated by the auction end', async () => {13    const fx = loadFixture('scotch-whisky-auctions', 'auction-page-1');14    const out = await connector.normalize(fx.raw);15    expect(out.length).toBeGreaterThanOrEqual(10);16    for (const r of out) {17      if (r.kind !== 'sale') throw new Error('expected sale');18      expect(r.currency).toBe('GBP');19      expect(r.buyerPremiumIncluded).toBe(false);20      expect(r.saleType).toBe('auction');21      expect(['whisky', 'rum', 'cognac']).toContain(r.attributes.categorySlug);22      expect(r.attributes.identifiers.swa_item).toMatch(/^\d+$/);23      expect(r.sourceUrl).toMatch(/^https:\/\/www\.scotchwhiskyauctions\.com\/auctions\/\d+-/);24    }25  });2627  it('parses list and lot pages', () => {28    const list = `<a href="/auctions/230-the-181st-auction/" class="auction"><h4>The 181st Auction</h4><h5>Ended July 12, 2026</h5><h6>There are 4926 lots in this auction</h6></a><a href="/auctions/232-the-183rd-auction/" class="auction"><h4>The 183rd Auction</h4><h5>Ends September 13, 2026</h5><h6>There are 4624 lots in this auction</h6></a>`;29    const auctions = parseAuctionList(list);30    expect(auctions).toHaveLength(2);31    expect(auctions[0]).toMatchObject({ id: '230', slug: 'the-181st-auction', ended: true, lotCount: 4926, endedOn: '2026-07-12T00:00:00.000Z' });32    expect(auctions[1]!.ended).toBe(false);33    const page = `<select><option>Page 1 of 247</option></select><div id="lots"><a href="/auctions/230-the-181st-auction/885566-on-a-saw-mill/" class="lot"><div class="aucimg" style="background-image: url('https://x/img.jpg');"></div><h4>Macallan 1989 18 Year Old Gran Reserva 70cl</h4><h6>Lot no 181-02514</h6><div><p class="sold">Sold for £1,250 in July 2026</p></div></a></div>`;34    const p = parseLotPage(page, 'u', auctions[0]!, 1);35    expect(p.totalPages).toBe(247);36    expect(p.lots[0]).toMatchObject({ itemId: '885566', lotNo: '181-02514', priceGbp: 1250, image: 'https://x/img.jpg' });37  });3839  it('extracts whisky facts without guessing', () => {40    expect(whiskyFacts('Macallan 1989 18 Year Old Gran Reserva 70cl')).toMatchObject({ brand: 'Macallan', age: 18, vintage: 1989, size: '70cl', categorySlug: 'whisky' });41    expect(whiskyFacts('Springbank 10 Year Old 75cl')).toMatchObject({ brand: 'Springbank', age: 10, vintage: null });42    expect(whiskyFacts('Appleton Estate 21 Year Old Rum')).toMatchObject({ categorySlug: 'rum', age: 21 });43    expect(whiskyFacts('Hennessy XO Cognac 1L')).toMatchObject({ categorySlug: 'cognac', size: '1L' });44  });45});46