import { describe, expect, it } from 'vitest'; import { readFileSync } from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { ConnectorMetaSchema } from '@rareindex/connectors'; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import createConnector, { parseLotsPage, parseResults } from './index.js'; const dir = path.dirname(fileURLToPath(import.meta.url)); const meta = ConnectorMetaSchema.parse(JSON.parse(readFileSync(path.join(dir, 'meta.json'), 'utf8'))); const connector = createConnector(meta); const RESULTS = `![](https://cdn.rmsothebys.com/a.webp) ‹› The Monterey Auction 13 - 15 August 2026 [View Results](https://rmsothebys.com/auctions/mo26/lots/) ![](https://cdn.rmsothebys.com/b.webp) ‹› Sealed July Bidding Closes 16 July 2026 [View Results](https://rmsothebys.com/auctions/s0726/lots/r0001-x/) `; const LOTS = `[![F-Racer Junior](https://cdn.rmsothebys.com/c.webp)](https://rmsothebys.com/auctions/mo25/lots/n0001-fracer-junior/) ![](https://rmsothebys.com/media/General/Flags/us.png)[**Monterey 2025** \\\\ F-Racer Junior\\\\ \\\\ Lot 101 \\| $24,000 USD\\\\ \\\\ Sold\\\\ \\\\ n0001 - \\\\ \\\\ Current bid: \\\\ \\\\ Final Bid: \\| Lot Sold Lot Closed\\\\ \\\\ Bid](https://rmsothebys.com/auctions/mo25/lots/n0001-fracer-junior/) [![1997 Porsche 911 Cup 3.8 RSR](https://cdn.rmsothebys.com/d.webp)](https://rmsothebys.com/auctions/mo25/lots/r0085-1997-porsche-911-cup-38-rsr/) ![](https://rmsothebys.com/media/General/Flags/us.png)[**Monterey 2025** \\\\ 1997 Porsche 911 Cup 3.8 RSR\\\\ \\\\ Lot 126 \\| Estimate Available Upon Request\\\\ \\\\ Not Sold\\\\ \\\\ r0085 - \\\\ \\\\ Bid](https://rmsothebys.com/auctions/mo25/lots/r0085-1997-porsche-911-cup-38-rsr/) `; describe('rm-sothebys', () => { runFixtureSuite(connector, it, expect); it('parses the results list and the lot grid', () => { const auctions = parseResults(RESULTS); expect(auctions[0]).toEqual({ code: 'mo26', name: 'The Monterey Auction', dateText: '13 - 15 August 2026' }); expect(auctions[1]).toMatchObject({ code: 's0726', name: 'Sealed July', dateText: '16 July 2026' }); const lots = parseLotsPage(LOTS, { code: 'mo25', name: 'Monterey 2025', dateText: '15 - 16 August 2025' }).lots; expect(lots.length).toBe(2); expect(lots[0]).toMatchObject({ slug: 'n0001-fracer-junior', title: 'F-Racer Junior', lotNumber: '101', priceText: '$24,000 USD', status: 'Sold' }); expect(lots[1]).toMatchObject({ lotNumber: '126', priceText: null, status: 'Not Sold' }); }); it('normalises sold lots with premium included and the auction start date', async () => { const out = await connector.normalize({ url: 'x', externalId: 'r', kind: 'sale', engine: 'firecrawl', fetchedAt: new Date('2026-09-07T00:00:00Z'), payload: parseLotsPage(LOTS, { code: 'mo25', name: 'Monterey 2025', dateText: '15 - 16 August 2025' }) }); expect(out.length).toBe(1); const s = out[0]!; if (s.kind !== 'sale') throw new Error('sale'); expect(s).toMatchObject({ price: 24000, currency: 'USD', buyerPremiumIncluded: true, lotNumber: '101', auctionHouse: "RM Sotheby's" }); expect(s.saleDate.toISOString()).toBe('2025-08-15T00:00:00.000Z'); }); it('fixture sales have currencies and lot numbers', async () => { const out = await connector.normalize(loadFixture('rm-sothebys', 'lots-page').raw); expect(out.length).toBeGreaterThan(0); for (const r of out) if (r.kind === 'sale') expect(r.lotNumber).toBeTruthy(); }); });