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.3 KB · 39 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import { ConnectorMetaSchema } from '@rareindex/connectors';3import { listFixtures, loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';4import metaJson from './meta.json' with { type: 'json' };5import createConnector, { categoryForAuction, parsePastAuctions, premiumFor } from './index.js';67const connector = createConnector(ConnectorMetaSchema.parse(metaJson));89describe('lyon-turnbull', () => {10  runFixtureSuite(connector, it, expect);1112  it('emits GBP hammer-price sales for sold lots and auction_lot records for unsold ones', async () => {13    const name = listFixtures('lyon-turnbull')[0]!;14    const fx = loadFixture('lyon-turnbull', name);15    const out = await connector.normalize(fx.raw);16    const sales = out.filter((r) => r.kind === 'sale');17    expect(sales.length).toBeGreaterThan(5);18    for (const r of sales) {19      if (r.kind !== 'sale') continue;20      expect(r.currency).toBe('GBP');21      expect(r.buyerPremiumIncluded).toBe(false);22      expect(r.auctionHouse).toBe('Lyon & Turnbull');23      expect(Array.isArray(r.attributes.metadata.premium_tiers)).toBe(true);24      if (r.attributes.metadata.premium_estimate !== null) expect(r.attributes.metadata.premium_estimate).toBeGreaterThan(0);25      expect(r.saleDate.getFullYear()).toBeGreaterThanOrEqual(2020);26    }27  });2829  it('helpers', () => {30    const html = `<script id="__NEXT_DATA__" type="application/json">${JSON.stringify({ props: { pageProps: { auctionsListData: [{ title: 'Scotland Collected ', saleNumber: '908', date: '19 & 20 August 2026', amsDate: '2026-08-19T09:00:00.000Z', arrowLink: '/auctions/scotland-collected-908' }] } } })}</script>`;31    expect(parsePastAuctions(html)).toEqual([{ saleNumber: '908', title: 'Scotland Collected', subtitle: null, date: '19 & 20 August 2026', amsDate: '2026-08-19T09:00:00.000Z', link: '/auctions/scotland-collected-908' }]);32    expect(categoryForAuction('Fine Jewellery')).toBe('jewelry');33    expect(categoryForAuction('1925: Celebrating Art Deco')).toBe('design_furniture');34    expect(categoryForAuction('Rare Books, Manuscripts, Maps & Photographs')).toBe('books');35    expect(premiumFor(10000, [{ percent: 27, amount_over: 0 }, { percent: 26, amount_over: 20000 }])).toBe(2700);36    expect(premiumFor(30000, [{ percent: 27, amount_over: 0 }, { percent: 26, amount_over: 20000 }])).toBe(8000);37  });38});39