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%
4.0 KB · 88 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import { readFileSync } from 'node:fs';3import path from 'node:path';4import { fileURLToPath } from 'node:url';5import { ConnectorMetaSchema } from '@rareindex/connectors';6import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';7import createConnector, { parseCalendar, parseLotsPage, rrCategory } from './index.js';89const dir = path.dirname(fileURLToPath(import.meta.url));10const meta = ConnectorMetaSchema.parse(JSON.parse(readFileSync(path.join(dir, 'meta.json'), 'utf8')));11const connector = createConnector(meta);1213const CAL = `## Space Exploration1415##### 10/16/20251617##### Realized $1,234,5671819[View Lots](https://www.rrauction.com/auctions/details/728-space-exploration)2021## Remarkable Rarities2223##### 9/20/20252425##### Realized $2,400,4562627[View Lots](https://www.rrauction.com/auctions/details/726-remarkable-rarities)28`;2930const LOTS = `[![Lot #8671 Campo del Cielo Iron Meteorite](https://cdn.rrauction.com/auction/728/preview/3506706_13.jpeg)](https://www.rrauction.com/auctions/lot-detail/350670607288671-campo-del-cielo-iron-meteorite-individual/?cat=0)3132[**8671\\. Campo del Cielo Iron Meteorite Individual**](https://www.rrauction.com/auctions/lot-detail/350670607288671-campo-del-cielo-iron-meteorite-individual/?cat=0 "Lot #8671. Campo del Cielo Iron Meteorite Individual")3334Sold For: $4,27335(w/BP)3637Estimate: $700+3839Auction #728 - October 16, 20254041Closed4243[![Lot #8579 ESA Flight Suit](https://cdn.rrauction.com/auction/728/preview/3505730_1.jpg)](https://www.rrauction.com/auctions/lot-detail/350573007288579-esa-european-space-agency-flight-suit/?cat=0)4445[**8579\\. ESA (European Space Agency) Flight Suit**](https://www.rrauction.com/auctions/lot-detail/350573007288579-esa-european-space-agency-flight-suit/?cat=0 "Lot #8579")4647Estimate: $500+4849Auction #728 - October 16, 202550`;5152describe('rr-auction', () => {53  runFixtureSuite(connector, it, expect);5455  it('parses the past calendar and lot gallery', () => {56    const auctions = parseCalendar(CAL);57    expect(auctions).toEqual([58      { id: '728', slug: 'space-exploration', title: 'Space Exploration', dateText: '10/16/2025', realizedText: '$1,234,567' },59      { id: '726', slug: 'remarkable-rarities', title: 'Remarkable Rarities', dateText: '9/20/2025', realizedText: '$2,400,456' },60    ]);61    const lots = parseLotsPage(LOTS, auctions[0]!, 1).lots;62    expect(lots.length).toBe(2);63    expect(lots[0]).toMatchObject({ lotNumber: '8671', title: 'Campo del Cielo Iron Meteorite Individual', estimateText: '$700+', auctionLine: 'October 16, 2025' });64    expect(lots[0]!.soldText).toContain('$4,273');65    expect(lots[1]!.soldText).toBeNull();66  });6768  it('normalises sold lots with BP flag, auction date and keyword categories', async () => {69    const auction = parseCalendar(CAL)[0]!;70    const out = await connector.normalize({ url: 'x', externalId: 'a', kind: 'sale', engine: 'firecrawl', fetchedAt: new Date('2026-09-07T00:00:00Z'), payload: parseLotsPage(LOTS, auction, 1) });71    expect(out.length).toBe(1);72    const s = out[0]!;73    if (s.kind !== 'sale') throw new Error('sale');74    expect(s).toMatchObject({ price: 4273, currency: 'USD', buyerPremiumIncluded: true, lotNumber: '8671', auctionHouse: 'RR Auction' });75    expect(s.saleDate.toISOString()).toBe('2025-10-16T00:00:00.000Z');76    expect(s.attributes.categorySlug).toBe('meteorites');77    expect(rrCategory('Space Exploration', 'Apollo 11 Flown Flag')).toBe('space');78    expect(rrCategory('Fine Autographs and Artifacts', 'Steve Jobs Signed Apple II Manual')).toBe('apple_collectibles');79    expect(rrCategory('Fine Autographs and Artifacts', 'Albert Einstein Signed Photograph')).toBe('autographs');80  });8182  it('fixture sales are dated by the auction and priced with premium', async () => {83    const out = await connector.normalize(loadFixture('rr-auction', 'lots-page').raw);84    expect(out.length).toBeGreaterThan(0);85    for (const r of out) if (r.kind === 'sale') expect(r.buyerPremiumIncluded).toBe(true);86  });87});88