TypeScript 61.9%
HTML 37.2%
SQL 0.7%
1import { describe, expect, it } from 'vitest';2import meta from './meta.json' with { type: 'json' };3import { localMeta } from '../_lib/local-meta.js';4import { listFixtures, loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';5import createConnector, { parseHistory, parseSetPage } from './index.js';67const connector = createConnector(localMeta(meta));89describe('mtggoldfish', () => {10 runFixtureSuite(connector, it, expect);1112 it('parses the embedded set JSON and history series', () => {13 const html = `<title>Limited Edition Alpha (LEA) Price Guide | MTGGoldfish</title><div data-x="{"cards":[{"name":"Black Lotus [LEA]","set":"LEA","display_name":"Black Lotus","rarity":"Rare","foil":false,"card_num":232,"finish":"regular","card_uuid":"u1","prices":{"paper":{"current_price":"12345.5"},"online":{"current_price":null}},"links":{"default":"/price/limited-edition-alpha/232/black-lotus"},"source_image_variants":{"672x938":"https://img/x.webp"}}],"view_type":"grid"}"></div>`;14 const { setName, cards } = parseSetPage(html);15 expect(setName).toBe('Limited Edition Alpha');16 expect(cards).toHaveLength(1);17 expect(cards[0]).toMatchObject({ set: 'LEA', display_name: 'Black Lotus', card_num: 232, paper: 12345.5, card_uuid: 'u1' });18 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]]);19 });2021 it('emits magic catalog items keyed like Scryfall (set code + collector number) with USD observations', async () => {22 const names = listFixtures('mtggoldfish');23 const card = names.find((n) => !n.includes('history')) ?? names[0]!;24 const out = await connector.normalize(loadFixture('mtggoldfish', card).raw);25 const c = out.find((r) => r.kind === 'catalog_item');26 if (!c || c.kind !== 'catalog_item') throw new Error('expected catalog item');27 expect(c.attributes.categorySlug).toBe('magic_the_gathering');28 expect(c.attributes.setCode).toMatch(/^[A-Z0-9]{2,6}$/);29 expect(c.attributes.number).toBeTruthy();30 for (const o of out) if (o.kind === 'price_observation') expect(o.currency).toBe('USD');31 const history = names.find((n) => n.includes('history'));32 if (history) {33 const h = await connector.normalize(loadFixture('mtggoldfish', history).raw);34 expect(h.length).toBeGreaterThan(10);35 const dates = h.map((r) => (r.kind === 'price_observation' ? r.observationDate.toISOString().slice(0, 10) : ''));36 expect(new Set(dates).size).toBe(dates.length);37 }38 });39});40