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.6 KB · 37 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, { parseResultsPage, parseSoldText } from './index.js';67const connector = createConnector(ConnectorMetaSchema.parse(metaJson));89describe('the-market-bonhams', () => {10  runFixtureSuite(connector, it, expect);1112  it('maps result cards to sales dated by the card', async () => {13    const fx = loadFixture('the-market-bonhams', 'results-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(['GBP', 'EUR', 'AUD', 'USD']).toContain(r.currency);19      expect(r.buyerPremiumIncluded).toBe(false);20      expect(['automobiles', 'motorcycles']).toContain(r.attributes.categorySlug);21      expect(r.attributes.identifiers.themarket_id).toMatch(/^[0-9a-f-]{36}$/);22      expect(r.sourceUrl).toMatch(/^https:\/\/www\.themarket\.co\.uk\/listings\//);23    }24  });2526  it('parses sold text and cards', () => {27    expect(parseSoldText('Sold for £56,000 on 17 Aug 2026')).toMatchObject({ amount: 56000, currency: 'GBP', date: new Date(Date.UTC(2026, 7, 17)) });28    expect(parseSoldText('Sold for €25,100 on 05 Jan 2023')).toMatchObject({ amount: 25100, currency: 'EUR' });29    expect(parseSoldText('Sold for A$41,000 on 1 Feb 2024')).toMatchObject({ amount: 41000, currency: 'AUD' });30    expect(parseSoldText('Bid to £10,000')).toBeNull();31    const html = `<a href="/listings/range-rover/classic/4f12faa9-7308-4e71-a17f-e3ca8db972c3" data-qa="listing card"><div class="listing-card"><div class="listing-card__image"><img src="https://cdn.themarket.co.uk/x/y.jpg?optimizer=image"/></div><div class="listing-card__heading"><p class="heading-text">Sold for £56,000 on 17 Aug 2026</p></div><div class="listing-card__content"><h3 class="listing-title">1991 Range Rover Classic</h3><p class="listing-intro">£170k Restoration</p><span class="icon-text listing-location"><span class="text">THE MARKET HQ, GB</span></span></div><div class="listing-card__footer"><p class="bids-count footer__item">43 bids</p></div></div></a>`;32    const cards = parseResultsPage(html);33    expect(cards).toHaveLength(1);34    expect(cards[0]).toMatchObject({ id: '4f12faa9-7308-4e71-a17f-e3ca8db972c3', title: '1991 Range Rover Classic', bids: 43, location: 'THE MARKET HQ, GB', image: 'https://cdn.themarket.co.uk/x/y.jpg' });35  });36});37