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%
2.5 KB · 40 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, { lotsUrl, trimLot } from './index.js';67const connector = createConnector(ConnectorMetaSchema.parse(metaJson));89describe('just-whisky', () => {10  runFixtureSuite(connector, it, expect);1112  it('maps reserve-met lots to GBP hammer sales', async () => {13    const fx = loadFixture('just-whisky', 'lots-page');14    const out = await connector.normalize(fx.raw);15    expect(out.length).toBeGreaterThan(0);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(['whisky', 'rum', 'cognac']).toContain(r.attributes.categorySlug);21      expect(r.attributes.identifiers.justwhisky_lot).toMatch(/^\d+$/);22      expect(r.sourceUrl).toMatch(/^https:\/\/www\.just-whisky\.co\.uk\/lot\//);23    }24  });2526  it('skips reserve-not-met lots and builds API urls', async () => {27    const met = trimLot({ id: 1, slug: 'port-ellen-1981-feis-ile-2008-1', reserve_met: true, hammer_price: '2750.00', bid_stats: { current_bid: 2750 }, seller_sheet: { auction: { id: 1160, end_date: '2026-07-20T19:00:00' } }, item: { title: 'Port Ellen 1981', subtitle: 'Feis Ile 2008', strength: { name: '54.7%' }, size: { name: '70 cl' } } })!;28    const notMet = trimLot({ id: 2, slug: 'springbank-36-2', reserve_met: false, hammer_price: null, bid_stats: { current_bid: 3150 }, seller_sheet: { auction: { id: 1160, end_date: '2026-07-20T19:00:00' } }, item: { title: 'Springbank 36 Years Old 1965' } })!;29    const out = await connector.normalize({ url: 'u', externalId: null, kind: 'sale', engine: 'api', fetchedAt: new Date(), payload: { kind: 'lots_page', url: 'u', page: 1, count: 2, lots: [met, notMet] } });30    expect(out).toHaveLength(1);31    const s = out[0]!;32    if (s.kind !== 'sale') throw new Error('sale');33    expect(s.price).toBe(2750);34    expect(s.saleDate.toISOString()).toBe('2026-07-20T19:00:00.000Z');35    expect(s.attributes.size).toBe('70cl');36    expect(s.attributes.year).toBe(1981);37    expect(lotsUrl(new Date(Date.UTC(2026, 6, 14)), new Date(Date.UTC(2026, 6, 21)), 2, 200)).toBe('https://www.just-whisky.co.uk/api/lots/?min_end_date=14%2F07%2F2026&max_end_date=21%2F07%2F2026&ordering=-price&page_size=200&page=2');38  });39});40