import { describe, expect, it } from 'vitest'; import { ConnectorMetaSchema } from '@rareindex/connectors'; import metaJson from './meta.json' with { type: 'json' }; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import createConnector, { parseCategoryPage, parseSpecimenPage } from './index.js'; const connector = createConnector(ConnectorMetaSchema.parse(metaJson)); describe('fossilera', () => { runFixtureSuite(connector, it, expect); it('emits one USD listing per unique specimen with the FossilEra item number', async () => { const fx = loadFixture('fossilera', 'dinosaur-teeth-p1'); const out = await connector.normalize(fx.raw); expect(out.length).toBeGreaterThanOrEqual(8); for (const l of out) { if (l.kind !== 'listing') throw new Error('expected listing'); expect(l.attributes.categorySlug).toBe('fossils'); expect(l.attributes.identifiers.fossilera_item).toMatch(/^\d+$/); expect(l.currency).toBe('USD'); expect(l.seller).toBe('FossilEra'); expect(l.sourceUrl).toMatch(/fossilera\.com\/fossils\//); expect(l.attributes.metadata.unique_specimen).toBe(true); } const reduced = out.find((l) => l.kind === 'listing' && l.attributes.metadata.previous_price_usd); expect(reduced).toBeTruthy(); }); it('parsers handle cards, reduced prices and specimen details', () => { const html = `
X Tooth #123
3.1" X Tooth - Montana
$300 $250
`; const p = parseCategoryPage(html, 'u', 'fossils'); expect(p.items).toHaveLength(1); expect(p.items[0]).toMatchObject({ item: '123', price: 250, oldPrice: 300, sold: false, title: '3.1" X Tooth - Montana', image: 'https://assets0.fossilera.com/x.jpg' }); const detail = `

Big Tooth

$1,000
SPECIES Tyrannosaurus rex
AGE Late Cretaceous
LOCATION Garfield County, Montana
FORMATION Hell Creek Formation
SIZE 3.95" tooth
ITEM #355472`; const d = parseSpecimenPage(detail, 'https://www.fossilera.com/fossils/big-tooth', 'fossils'); expect(d?.items[0]).toMatchObject({ item: '355472', price: 1000, species: 'Tyrannosaurus rex', formation: 'Hell Creek Formation', location: 'Garfield County, Montana', size: '3.95" tooth' }); }); });