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.9 KB · 43 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, { classify, trimItem, watchReference } from './index.js';67const connector = createConnector(ConnectorMetaSchema.parse(metaJson));89describe('pcarmarket', () => {10  runFixtureSuite(connector, it, expect);1112  it('maps sold items to USD auction sales without premium', async () => {13    const fx = loadFixture('pcarmarket', '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(r.currency).toBe('USD');19      expect(r.buyerPremiumIncluded).toBe(false);20      expect(r.attributes.identifiers.pcarmarket_id).toMatch(/^\d+$/);21      expect(r.sourceUrl).toMatch(/^https:\/\/www\.pcarmarket\.com\/auction\//);22      expect(r.saleDate.getTime()).toBeLessThan(Date.now());23    }24  });2526  it('classifies cars, watches and automobilia', () => {27    const car = trimItem({ id: 1, title: 'One-Owner 1983 Porsche 911SC Coupe', slug: 'x', vehicle: { id: 5, make: 'Porsche', model: '911SC', year: 1983, slug_model: 's' }, high_bid: 65000, end_date: '2026-09-04T15:00:07-04:00', status: 'Sold' })!;28    expect(classify(car)).toMatchObject({ kind: 'vehicle', categorySlug: 'automobiles', brand: 'Porsche' });29    const watch = trimItem({ id: 2, title: 'TAG Heuer Gulf Special Edition Watch Ref. CAVZ101 Full Set', slug: 'y', vehicle: null, high_bid: 1250, end_date: '2026-09-03T15:00:00-04:00', status: 'Sold' })!;30    expect(classify(watch)).toMatchObject({ kind: 'watch', categorySlug: 'other_watches' });31    expect(watchReference(watch.title)).toBe('CAVZ101');32    const rolex = trimItem({ id: 3, title: '2023 Rolex Daytona Panda Watch Ref. 116500LN Full Set', slug: 'z', vehicle: null, high_bid: 30000, end_date: '2026-09-03T15:00:00-04:00', status: 'Sold' })!;33    expect(classify(rolex)).toMatchObject({ kind: 'watch', categorySlug: 'rolex' });34    const sign = trimItem({ id: 4, title: 'No Reserve Illuminated Porsche Eye Chart Sign', slug: 'w', vehicle: null, high_bid: 250, end_date: '2026-09-03T15:00:00-04:00', status: 'Sold' })!;35    expect(classify(sign)).toMatchObject({ kind: 'memorabilia', categorySlug: 'automotive_memorabilia' });36  });3738  it('drops unsold and priceless items', async () => {39    const out = await connector.normalize({ url: 'u', externalId: null, kind: 'sale', engine: 'api', fetchedAt: new Date(), payload: { kind: 'results_page', page: 1, count: 1, items: [{ id: 9, title: '1990 Porsche 964', slug: 'a', vehicle: { make: 'Porsche', model: '964', year: 1990 }, high_bid: 50000, end_date: '2026-09-01T00:00:00Z', status: 'Reserve Not Met' }] } });40    expect(out).toHaveLength(0);41  });42});43