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.0 KB · 23 lines typescript
Raw Blame History
1/** Targeted live fixture: Pokémon Base Set (group 604) cards with multiple price subtypes. */2import { saveFixture } from '@rareindex/connectors/testing';3import { trimProduct } from './index.js';4const UA = { 'user-agent': 'RareIndexBot/0.1 (+https://www.rareindex.io/about/data)' };5const get = async (u: string) => (await (await fetch(u, { headers: UA })).json()) as { results: Record<string, unknown>[] };6const stamp = (await (await fetch('https://tcgcsv.com/last-updated.txt', { headers: UA })).text()).trim();7const groups = await get('https://tcgcsv.com/tcgplayer/3/groups');8const group = groups.results.find((g) => g.groupId === 604)!;9const products = await get('https://tcgcsv.com/tcgplayer/3/604/products');10const prices = await get('https://tcgcsv.com/tcgplayer/3/604/prices');11const category = { slug: 'pokemon', franchise: 'Pokémon', brand: 'The Pokémon Company', language: 'English' };12for (const [name, match] of [['pokemon-base-charizard', /^Charizard/], ['pokemon-base-energy', /^Psychic Energy/]] as const) {13  const p = products.results.find((x) => match.test(String(x.name)))!;14  const product = trimProduct(p);15  const rows = prices.results.filter((r) => r.productId === product.productId);16  saveFixture('tcgcsv', name, {17    raw: { url: String(p.url), externalId: String(product.productId), kind: 'catalog_item', engine: 'api', fetchedAt: new Date(), payload: { categoryId: 3, category, group: { groupId: group.groupId, name: group.name, abbreviation: group.abbreviation, isSupplemental: group.isSupplemental, publishedOn: group.publishedOn, categoryId: 3 }, product, prices: rows, updatedAt: stamp } },18    expect: { minCount: 2, kinds: ['catalog_item', 'price_observation'], requiredFields: ['attributes.identifiers.tcgplayer_id', 'attributes.set', 'attributes.number'] },19    note: `Live capture ${new Date().toISOString().slice(0, 10)} — tcgcsv.com/tcgplayer/3/604 (Base Set), subtypes ${[...new Set(rows.map((r) => r.subTypeName))].join('/')}`,20  });21  console.log(name, product.productId, rows.map((r) => `${r.subTypeName}:${r.marketPrice}`).join(' '));22}23