import { describe, expect, it } from 'vitest'; import meta from './meta.json' with { type: 'json' }; import { localMeta } from '../../api/_lib/local-meta.js'; import { listFixtures, loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import createConnector, { parseItemMarkdown } from './index.js'; const connector = createConnector(localMeta(meta)); const SAMPLE = `Back # 2023 Bowman Chrome Prospect Autograph Purple Refractor Ludwing Espinoza \\#CPALE ## Baseball Cards Serial207/250 PSA10 Pop24 ## List price ### $45 Buy nowOffer ## LT Value $18 ### $12 - $29 PSA population ### Recent transactions [![eBay](https://x/e.png)\\ \\ AuctionAug 6, 2026\\ \\ $15](https://www.ebay.com/itm/278232527458) [![eBay](https://x/e.png)\\ \\ Best offerSep 3, 2024\\ \\ $20](https://www.ebay.com/itm/405178094963) View all Listings [![eBay](https://x/e.png)\\ \\ Fixed price\\ \\ $60\\ \\ live listing in eBay](https://www.ebay.com/itm/176907976889) `; describe('alt-xyz', () => { runFixtureSuite(connector, it, expect); it('parses item markdown', () => { const p = parseItemMarkdown(SAMPLE, 'abc')!; expect(p.title).toContain('Ludwing Espinoza #CPALE'); expect(p.category).toBe('Baseball Cards'); expect(p).toMatchObject({ grader: 'psa', grade: '10', pop: 24, listPrice: 45, listingKind: 'fixed_price', altValue: 18, altLow: 12, altHigh: 29, serial: '207/250' }); expect(p.transactions).toEqual([ { type: 'Auction', date: 'Aug 6, 2026', price: 15, url: 'https://www.ebay.com/itm/278232527458' }, { type: 'Best offer', date: 'Sep 3, 2024', price: 20, url: 'https://www.ebay.com/itm/405178094963' }, ]); }); it('normalises into observation + sales + listing', async () => { const raw = { url: 'https://alt.xyz/itm/abc', externalId: 'abc', kind: 'sale' as const, engine: 'firecrawl' as const, fetchedAt: new Date('2026-09-07T12:00:00Z'), payload: parseItemMarkdown(SAMPLE, 'abc') }; const out = await connector.normalize(raw); const kinds = out.map((r) => r.kind); expect(kinds.filter((k) => k === 'sale')).toHaveLength(2); expect(kinds).toContain('price_observation'); expect(kinds).toContain('listing'); const sale = out.find((r) => r.kind === 'sale'); if (sale && sale.kind === 'sale') { expect(sale.saleDate.toISOString()).toBe('2026-08-06T00:00:00.000Z'); expect(sale.attributes.categorySlug).toBe('baseball_cards'); expect(sale.grade.grader).toBe('psa'); } for (const name of listFixtures('alt-xyz')) { const fx = await connector.normalize(loadFixture('alt-xyz', name).raw); expect(fx.length).toBeGreaterThan(0); } }); });