import { describe, expect, it } from 'vitest'; import meta from './meta.json' with { type: 'json' }; import { localMeta } from '../_lib/local-meta.js'; import { listFixtures, loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import createConnector, { parseHistory, parseSetPage } from './index.js'; const connector = createConnector(localMeta(meta)); describe('mtggoldfish', () => { runFixtureSuite(connector, it, expect); it('parses the embedded set JSON and history series', () => { const html = `Limited Edition Alpha (LEA) Price Guide | MTGGoldfish
`; const { setName, cards } = parseSetPage(html); expect(setName).toBe('Limited Edition Alpha'); expect(cards).toHaveLength(1); expect(cards[0]).toMatchObject({ set: 'LEA', display_name: 'Black Lotus', card_num: 232, paper: 12345.5, card_uuid: 'u1' }); expect(parseHistory('var d = "";\nd += "2010-11-02, 3102.99\\n";\nd += "2010-11-03, 3110\\n";')).toEqual([['2010-11-02', 3102.99], ['2010-11-03', 3110]]); }); it('emits magic catalog items keyed like Scryfall (set code + collector number) with USD observations', async () => { const names = listFixtures('mtggoldfish'); const card = names.find((n) => !n.includes('history')) ?? names[0]!; const out = await connector.normalize(loadFixture('mtggoldfish', card).raw); const c = out.find((r) => r.kind === 'catalog_item'); if (!c || c.kind !== 'catalog_item') throw new Error('expected catalog item'); expect(c.attributes.categorySlug).toBe('magic_the_gathering'); expect(c.attributes.setCode).toMatch(/^[A-Z0-9]{2,6}$/); expect(c.attributes.number).toBeTruthy(); for (const o of out) if (o.kind === 'price_observation') expect(o.currency).toBe('USD'); const history = names.find((n) => n.includes('history')); if (history) { const h = await connector.normalize(loadFixture('mtggoldfish', history).raw); expect(h.length).toBeGreaterThan(10); const dates = h.map((r) => (r.kind === 'price_observation' ? r.observationDate.toISOString().slice(0, 10) : '')); expect(new Set(dates).size).toBe(dates.length); } }); });