SPB Git

spb/rareindex

Public
4.8 KB · 76 lines typescript
1import { describe, expect, it } from 'vitest';2import { getConnectorMeta } from '@rareindex/connectors';3import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';4import createConnector, { parseProductPage } from './index.js';56const connector = createConnector(getConnectorMeta('pricecharting'));78describe('pricecharting', () => {9  runFixtureSuite(connector, it, expect);1011  it('maps a video game page to catalog + guide values + eBay sales', async () => {12    const fx = loadFixture('pricecharting', 'nintendo-64__zelda-ocarina-of-time');13    const out = await connector.normalize(fx.raw);14    const catalog = out.find((r) => r.kind === 'catalog_item');15    expect(catalog).toBeTruthy();16    if (catalog?.kind !== 'catalog_item') throw new Error();17    expect(catalog.attributes.categorySlug).toBe('nintendo_games');18    expect(catalog.attributes.set).toBe('Nintendo 64');19    expect(catalog.attributes.name).toBe('Zelda Ocarina of Time');20    expect(catalog.attributes.identifiers.pricecharting_id).toBe('3977');21    expect(catalog.attributes.identifiers.upc).toMatch(/^\d{12}$/);22    const guides = out.filter((r) => r.kind === 'price_observation');23    expect(guides.map((g) => g.kind === 'price_observation' && g.condition.completeness)).toEqual(expect.arrayContaining(['loose', 'cib', 'sealed']));24    const sales = out.filter((r) => r.kind === 'sale');25    expect(sales.length).toBeGreaterThan(50);26    const s = sales[0];27    if (s?.kind !== 'sale') throw new Error();28    expect(s.currency).toBe('USD');29    expect(s.externalId).toMatch(/^ebay:\d+$/);30    expect(s.saleDate.getUTCFullYear()).toBeGreaterThanOrEqual(2024);31    expect(['loose', 'cib', 'sealed', 'box_only', 'manual_only', null]).toContain(s.condition.completeness);32  });3334  it('maps LEGO, Funko and comics pages to the right categories', async () => {35    const lego = await connector.normalize(loadFixture('pricecharting', 'lego-star-wars__cloud-city-10123').raw);36    const legoCat = lego.find((r) => r.kind === 'catalog_item');37    if (legoCat?.kind !== 'catalog_item') throw new Error();38    expect(legoCat.attributes.categorySlug).toBe('lego_sets');39    expect(legoCat.attributes.number).toBe('10123');40    expect(legoCat.attributes.identifiers.lego_set_number).toBe('10123');41    expect(legoCat.attributes.set).toBe('Star Wars');4243    const funko = await connector.normalize(loadFixture('pricecharting', 'funko-pop-marvel__spider-man-metallic-3').raw);44    const funkoCat = funko.find((r) => r.kind === 'catalog_item');45    if (funkoCat?.kind !== 'catalog_item') throw new Error();46    expect(funkoCat.attributes.categorySlug).toBe('funko');47    expect(funkoCat.attributes.name).toBe('Spider-Man');48    expect(funkoCat.attributes.variant).toBe('Metallic');49    expect(funkoCat.attributes.number).toBe('3');5051    const comic = await connector.normalize(loadFixture('pricecharting', 'comic-books-amazing-spider-man__amazing-spider-man-300-1988').raw);52    const comicCat = comic.find((r) => r.kind === 'catalog_item');53    if (comicCat?.kind !== 'catalog_item') throw new Error();54    expect(comicCat.attributes.categorySlug).toBe('marvel_comics');55    expect(comicCat.attributes.number).toBe('300');56    expect(comicCat.attributes.year).toBe(1988);57    const graded98 = comic.find((r) => r.kind === 'price_observation' && r.grade.grade === '9.8');58    expect(graded98).toBeTruthy();59  });6061  it('parses the product page HTML deterministically', () => {62    const html = `<html><body><h1 id="product_name">Super Mario 64 [Player's Choice] <a href="/console/nintendo-64">Nintendo 64</a></h1>63      <script>VGPC.product = { id: 3924, is_comic: false, is_lego_set: false, is_funko_pop: false, is_card: false };</script>64      <table id="price_data"><tbody><tr><td id="used_price"><span class="price js-price">$39.99</span></td><td id="complete_price"><span class="price js-price">$134.48</span></td><td id="new_price"><span class="price js-price">$1,628.37</span></td></tr></tbody></table>65      <div class="completed-auctions-used"><table><tbody><tr id="ebay-1"><td class="date">2026-09-05</td><td class="title"><a href="https://www.ebay.com/itm/1">Mario 64 cart</a></td><td class="numeric"><span class="js-price">$37.95</span></td></tr></tbody></table></div>66      <table><tr><td class="title">UPC:</td><td class="details">045496870010</td></tr></table></body></html>`;67    const p = parseProductPage(html, 'https://www.pricecharting.com/game/nintendo-64/super-mario-64');68    expect(p.title).toBe("Super Mario 64 [Player's Choice]");69    expect(p.consoleUri).toBe('nintendo-64');70    expect(p.productId).toBe('3924');71    expect(p.prices.map((x) => x.value)).toEqual([39.99, 134.48, 1628.37]);72    expect(p.sales).toEqual([{ tab: 'used', date: '2026-09-05', title: 'Mario 64 cart', price: 37.95, ebayId: '1', listedPrice: null }]);73    expect(p.details['UPC']).toBe('045496870010');74  });75});76
Files · d4cbf87a4d6431f74690ca22ffff043c6ca7da5d
Menu

Theme