import { describe, expect, it } from 'vitest'; import { readFileSync } from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import { localMeta } from '../../api/_lib/local-meta.js'; import createConnector, { parseGallery } from './index.js'; const dir = path.dirname(fileURLToPath(import.meta.url)); const meta = localMeta(JSON.parse(readFileSync(path.join(dir, 'meta.json'), 'utf8'))); const connector = createConnector(meta); const PAGE = `
1

Late 1930s Lou Gehrig Single-Signed Baseball (PSA)

Bids: 49
Opening Bid: $5,000
Status: Sold

SOLD FOR $92,050
2

Signed 1949 Bowman Baseball #82 Joe Page Card (PSA)

Bids: 0
Opening Bid: $300
Status: Unsold

`; describe('lelands', () => { runFixtureSuite(connector, it, expect); it('parses the gallery: auction dates, premium note, items and pagination', () => { const p = parseGallery(PAGE, 1); expect(p.auction.id).toBe('1008'); expect(p.auction.name).toContain('2026 Summer Classic'); expect(p.auction.endText).toBe('8/15/2026 10:00 PM EST'); expect(p.auction.premiumIncluded).toBe(true); expect(p.totalPages).toBe(5); expect(p.items[0]).toMatchObject({ itemId: '135734', bids: 49, openingBid: 5000, status: 'Sold', soldPrice: 92050, lotNumber: '1' }); expect(p.items[1]!.soldPrice).toBeNull(); }); it('normalises sold lots dated by the auction end with premium included', async () => { const out = await connector.normalize({ url: 'x', externalId: 'a', kind: 'sale', engine: 'firecrawl', fetchedAt: new Date('2026-09-07T00:00:00Z'), payload: parseGallery(PAGE, 1) }); expect(out.length).toBe(1); const s = out[0]!; if (s.kind !== 'sale') throw new Error('sale'); expect(s).toMatchObject({ price: 92050, currency: 'USD', buyerPremiumIncluded: true, auctionHouse: 'Lelands', lotNumber: '1' }); expect(s.saleDate.toISOString()).toBe('2026-08-15T00:00:00.000Z'); expect(s.attributes.categorySlug).toBe('sports_memorabilia'); }); it('emits nothing while the displayed auction is still open', async () => { const future = PAGE.replace('End: 8/15/2026', 'End: 8/15/2099'); expect(await connector.normalize({ url: 'x', externalId: 'a', kind: 'sale', engine: 'firecrawl', fetchedAt: new Date(), payload: parseGallery(future, 1) })).toEqual([]); }); it('fixture normalises', async () => { expect((await connector.normalize(loadFixture('lelands', 'gallery-page').raw)).length).toBeGreaterThan(0); }); });