TypeScript 61.9%
HTML 37.2%
SQL 0.7%
1import { describe, expect, it } from 'vitest';2import { readFileSync } from 'node:fs';3import path from 'node:path';4import { fileURLToPath } from 'node:url';5import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';6import { localMeta } from '../_lib/local-meta.js';7import createConnector, { buildIdFromHtml, currencyFromSymbol, parseAuctionJson, parsePastAuctions } from './index.js';89const dir = path.dirname(fileURLToPath(import.meta.url));10const connector = createConnector(localMeta(JSON.parse(readFileSync(path.join(dir, 'meta.json'), 'utf8'))));1112const ENTRY = { uuid: 'e33169b2', saleNumber: 'S26016', title: 'Important Multiples of Great Britain | S26016', department: 'Stamps', slug: '/auctions/gb-blocks-and-multiples', amsDate: '2026-07-30T13:30:00.000Z' };13const LIST = { pageProps: { auctionsListData: [{ title: 'Pokémon Summer Celebrations | E26010', saleNumber: 'E26010', date: '31 July 2026', amsDate: '2026-07-31T15:00:00.000Z', arrowLink: '/auctions/pokemon-summer-sale-e26010', auctionId: 'b46b7467', department: 'Trading Cards' }, { title: ENTRY.title, saleNumber: 'S26016', date: '30 July 2026 14.30 BST', amsDate: ENTRY.amsDate, arrowLink: ENTRY.slug, auctionId: ENTRY.uuid, department: 'Stamps' }] } };14const AUCTION = {15 pageProps: {16 amsData: { status: 'completed', premiums: [{ percent: 23, amount_over: 0 }] },17 auctionPageData: { attributes: { dateTime: '30 July 2026 14.30 BST' } },18 categories: [{ uuid: 'cat1', name: 'GB Stamps' }],19 lots: [20 { uuid: 'lot1', auction: { currency: { symbol: '£' }, status: 'completed' }, lot_no: '1', title: { en: 'SG 2 1840 1d black Plate 7 block mint' }, dynamic_fields: { en: { country: 'Great Britain' } }, images: [{ data: { original: { url: 'https://media.app.artisio.co/x/0001_original.jpg' } } }], low: '18000.00', high: '20000.00', start_price: '16000.00', hammer_price: '26000.00', financeItem: { hammer_price: '26000.00', premium: '5980.00', premium_tiers: [{ percent: 23, amount_over: 0 }] }, category_uuid: 'cat1', status: 'sold', session_date: '2026-07-30T13:30:00.000Z', country: 'Great Britain' },21 { uuid: 'lot4', auction: { currency: { symbol: '£' }, status: 'completed' }, lot_no: '4', title: { en: 'SG 7 1841 1d red-brown strip of 11 mint' }, images: [], low: '1000.00', high: '1200.00', start_price: '900.00', hammer_price: null, financeItem: null, category_uuid: 'cat1', status: 'unsold', session_date: '2026-07-30T13:30:00.000Z', country: 'Great Britain' },22 ],23 },24};2526describe('sgbaldwins', () => {27 runFixtureSuite(connector, it, expect);2829 it('reads the buildId, filters the past-auction list and parses lots with hammer + premium', () => {30 expect(buildIdFromHtml('<script id="__NEXT_DATA__" type="application/json">{"props":{},"page":"/","buildId":"QR6Ic5gmqCZAHXbcQV1E7"}</script>')).toBe('QR6Ic5gmqCZAHXbcQV1E7');31 const list = parsePastAuctions(LIST);32 expect(list.length).toBe(2);33 expect(list[1]).toEqual(ENTRY);34 const p = parseAuctionJson(AUCTION, ENTRY)!;35 expect(p.auction).toMatchObject({ status: 'completed', currencySymbol: '£', dateTimeText: '30 July 2026 14.30 BST', premiums: [{ percent: 23, amount_over: 0 }] });36 expect(p.lots[0]).toMatchObject({ lotNo: '1', hammerPrice: '26000.00', premium: '5980.00', status: 'sold', categoryName: 'GB Stamps', country: 'Great Britain', images: ['https://media.app.artisio.co/x/0001_original.jpg'] });37 expect(p.lots[1]!.hammerPrice).toBeNull();38 expect(currencyFromSymbol('£')).toBe('GBP');39 expect(currencyFromSymbol('$')).toBe('USD');40 });4142 it('normalises sold lots as GBP hammer sales with premium in metadata; unsold skipped', async () => {43 const p = parseAuctionJson(AUCTION, ENTRY)!;44 const payload = { kind: 'auction_lots' as const, auction: p.auction, url: 'https://sgbaldwins.com/auctions/gb-blocks-and-multiples', chunk: 0, totalLots: 2, lots: p.lots };45 const out = await connector.normalize({ url: payload.url, externalId: 'x', kind: 'sale', engine: 'api', fetchedAt: new Date('2026-09-08T00:00:00Z'), payload });46 expect(out.length).toBe(1);47 const s = out[0]!;48 if (s.kind !== 'sale') throw new Error('sale');49 expect(s).toMatchObject({ price: 26000, currency: 'GBP', buyerPremiumIncluded: false, lotNumber: '1', auctionHouse: "Stanley Gibbons Baldwin's", location: 'GB' });50 expect(s.saleDate.toISOString()).toBe('2026-07-30T00:00:00.000Z');51 expect(s.attributes).toMatchObject({ categorySlug: 'stamps', year: 1840, country: 'GB' });52 expect(s.attributes.identifiers).toEqual({ sgbaldwins_lot: 'lot1', sg_number: '2' });53 expect(s.attributes.metadata).toMatchObject({ estimate_low: 18000, estimate_high: 20000, buyer_premium_amount: 5980, buyer_premium_percent: 23, total_with_premium: 31980 });54 });5556 it('fixtures: stamps and coins auctions normalise to GBP hammer sales', async () => {57 for (const name of ['stamps-gb-blocks-s26016', 'coins-auction-131-c26005']) {58 const out = await connector.normalize(loadFixture('sgbaldwins', name).raw);59 expect(out.length).toBeGreaterThan(0);60 for (const r of out) if (r.kind === 'sale') expect(r).toMatchObject({ currency: 'GBP', buyerPremiumIncluded: false });61 }62 const coins = await connector.normalize(loadFixture('sgbaldwins', 'coins-auction-131-c26005').raw);63 expect(coins.every((r) => r.kind === 'sale' && r.attributes.categorySlug !== 'stamps')).toBe(true);64 });65});66