SPB Git forge

spb/rareindex

Public
54commits 1branches 0releases
7.1 MBsize
maindefault branch
10 days agolast push
TypeScript 61.9% HTML 37.2% SQL 0.7%
2.8 KB · 40 lines typescript
Raw Blame History
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="{&quot;cards&quot;:[{&quot;name&quot;:&quot;Black Lotus [LEA]&quot;,&quot;set&quot;:&quot;LEA&quot;,&quot;display_name&quot;:&quot;Black Lotus&quot;,&quot;rarity&quot;:&quot;Rare&quot;,&quot;foil&quot;:false,&quot;card_num&quot;:232,&quot;finish&quot;:&quot;regular&quot;,&quot;card_uuid&quot;:&quot;u1&quot;,&quot;prices&quot;:{&quot;paper&quot;:{&quot;current_price&quot;:&quot;12345.5&quot;},&quot;online&quot;:{&quot;current_price&quot;:null}},&quot;links&quot;:{&quot;default&quot;:&quot;/price/limited-edition-alpha/232/black-lotus&quot;},&quot;source_image_variants&quot;:{&quot;672x938&quot;:&quot;https://img/x.webp&quot;}}],&quot;view_type&quot;:&quot;grid&quot;}"></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