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.6 KB · 59 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 from './index.js';6import { magicTreatments, streamGzipDataEntries } from '../_lib/wave4.js';7import { gzipSync } from 'node:zlib';89const connector = createConnector(localMeta(meta));1011describe('mtgjson', () => {12  runFixtureSuite(connector, it, expect);1314  it('emits scryfall-aligned variants and provider-dated observations', async () => {15    const names = listFixtures('mtgjson');16    const fx = loadFixture('mtgjson', names[0]!);17    const out = await connector.normalize(fx.raw);18    const cats = out.filter((r) => r.kind === 'catalog_item');19    const obs = out.filter((r) => r.kind === 'price_observation');20    expect(cats.length).toBeGreaterThanOrEqual(1);21    for (const c of cats) {22      if (c.kind !== 'catalog_item') continue;23      expect(c.attributes.identifiers.mtgjson_uuid).toBeTruthy();24      expect(c.attributes.identifiers.scryfall_id).toMatch(/^[0-9a-f-]{36}$/);25      expect(c.attributes.setCode).toMatch(/^[A-Z0-9]{2,6}$/);26    }27    for (const o of obs) {28      if (o.kind !== 'price_observation') continue;29      expect(['USD', 'EUR']).toContain(o.currency);30      expect(o.priceKind).toBe('market');31      expect((o.attributes.metadata as { provider: string }).provider).toBeTruthy();32      expect(o.observationDate.getTime()).toBeLessThanOrEqual(Date.now());33    }34  });3536  it('mirrors the scryfall treatment vocabulary', () => {37    expect(magicTreatments({ frameEffects: ['showcase'], promoTypes: [] })).toEqual(['Showcase']);38    expect(magicTreatments({ frameEffects: ['extendedart'], borderColor: 'borderless' })).toEqual(['Extended Art', 'Borderless']);39    expect(magicTreatments({})).toEqual([]);40  });4142  it('streams top-level data entries from a gzip JSON document', async () => {43    const doc = { meta: { date: '2026-09-06' }, data: { a: { paper: { tcgplayer: { retail: { normal: { '2026-09-06': 1.5 } } } } }, b: { paper: {} }, c: { x: [1, 2, { y: '}' }] } } };44    const gz = gzipSync(Buffer.from(JSON.stringify(doc)));45    const orig = globalThis.fetch;46    globalThis.fetch = (async () => new Response(gz, { status: 200 })) as typeof fetch;47    try {48      const seen: string[] = [];49      const n = await streamGzipDataEntries('https://example.test/x.json.gz', (k) => {50        seen.push(k);51      });52      expect(n).toBe(3);53      expect(seen).toEqual(['a', 'b', 'c']);54    } finally {55      globalThis.fetch = orig;56    }57  });58});59