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%
5.1 KB · 83 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import { getConnectorMeta } from '@rareindex/connectors';3import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';4import createConnector, { parseGoldinDisplayDate, parseGoldinGrade, soldPageUrl } from './index.js';5import { classifyGoldinTitle, isBundleTitle, parseCardAttributes } from './classify.js';67const connector = createConnector(getConnectorMeta('goldin'));89describe('goldin connector', () => {10  runFixtureSuite(connector, it, expect);1112  it('applies buyer premium and keeps the hammer price', async () => {13    const fx = loadFixture('goldin', 'pokemon-sold-page');14    const out = await connector.normalize(fx.raw);15    const lot = (fx.raw.payload as { lots: Array<{ lot_id: string; current_price: number; buyer_premium: number; title: string; end_timestamp: string }> }).lots[0]!;16    const rec = out.find((r) => r.kind === 'sale' && r.externalId === lot.lot_id);17    expect(rec && rec.kind === 'sale').toBe(true);18    if (!rec || rec.kind !== 'sale') return;19    expect(rec.price).toBeCloseTo(lot.current_price * (1 + lot.buyer_premium / 100), 2);20    expect(rec.buyerPremiumIncluded).toBe(true);21    expect(rec.attributes.metadata.hammer_price).toBe(lot.current_price);22    expect(rec.saleDate.toISOString().slice(0, 19)).toBe(new Date(lot.end_timestamp).toISOString().slice(0, 19));23    expect(rec.currency).toBe('USD');24    expect(rec.auctionHouse).toBe('Goldin');25    expect(rec.sourceUrl).toMatch(/^https:\/\/goldin\.co\/item\//);26    expect(rec.attributes.categorySlug).toBe('pokemon');27  });2829  it('extracts grades from Goldin titles', async () => {30    const fx = loadFixture('goldin', 'pokemon-sold-page');31    const out = await connector.normalize(fx.raw);32    const graded = out.flatMap((r) => (r.kind === 'sale' && /PSA GEM MT 10/.test(r.rawTitle) ? [r] : []));33    expect(graded.length).toBeGreaterThan(0);34    for (const g of graded) expect(g.grade).toMatchObject({ grader: 'psa', grade: '10' });35  });3637  it('skips placeholder future end dates and unsold lots', async () => {38    const fx = loadFixture('goldin', 'pokemon-sold-page');39    const payload = structuredClone(fx.raw.payload) as { lots: Array<Record<string, unknown>> };40    const keepId = payload.lots[0]!.lot_id;41    payload.lots = [42      { ...payload.lots[0]!, lot_id: 'future', end_timestamp: '2235-06-04T00:00:00Z' },43      { ...payload.lots[0]!, lot_id: 'unsold', status: 'Completed_Unsold' },44      { ...payload.lots[0]!, lot_id: 'zero', current_price: 0 },45      payload.lots[0]!,46    ];47    const out = await connector.normalize({ ...fx.raw, payload });48    expect(out.map((r) => (r.kind === 'sale' ? r.externalId : null))).toEqual([keepId]);49  });5051  it('normalises a sold item page (lookup) with cert number', async () => {52    const fx = loadFixture('goldin', 'item-sold-page');53    const out = await connector.normalize(fx.raw);54    expect(out.length).toBe(1);55    const r = out[0]!;56    expect(r.kind).toBe('sale');57    if (r.kind !== 'sale') return;58    expect(r.price).toBe(25726);59    expect(r.attributes.metadata.hammer_price).toBe(21438);60    expect(r.saleDate.toISOString()).toBe('2012-11-18T02:16:00.000Z');61    expect(r.buyerPremiumIncluded).toBe(true);62  });6364  it('helpers', () => {65    expect(parseGoldinGrade('2019 Pokemon Sun & Moon Team Up #33 Pikachu & Zekrom GX Tag Team - PSA GEM MT 10')).toMatchObject({ grader: 'psa', grade: '10' });66    expect(parseGoldinGrade('2003-04 Topps Chrome #111 LeBron James Rookie Card')).toMatchObject({ grader: null, grade: null });67    expect(soldPageUrl('/buy/sc/pokemon', 2, 240)).toBe('https://goldin.co/buy/sc/pokemon?page=2&number_of_lots=240&show_only=Sold%20Items&sort=Most_Recent_Bids');68    expect(parseGoldinDisplayDate('Sat, 11/17/12, 10:16 PM EDT')?.toISOString()).toBe('2012-11-18T02:16:00.000Z');69    expect(parseGoldinDisplayDate('Sun, 9/06/26, 9:02 PM PDT')?.toISOString()).toBe('2026-09-07T04:02:00.000Z');70    expect(classifyGoldinTitle('2003-04 Topps Chrome #111 LeBron James Rookie Card - PSA GEM MT 10', { path: '/buy/sc/Basketball', categorySlug: 'basketball_cards', sport: 'basketball' })).toBe('basketball_cards');71    expect(classifyGoldinTitle('1994-95 Patrick Ewing Game Used New York Knicks Home Jersey (Beckett)', { path: '/buy/sc/Basketball', categorySlug: 'basketball_cards', sport: 'basketball' })).toBe('sports_memorabilia');72    expect(classifyGoldinTitle('Amazing Spider-Man #300 (1988 Marvel) - CGC 9.8', { path: '/buy/sc/Marvel', categorySlug: 'marvel_comics' })).toBe('marvel_comics');73    expect(isBundleTitle('1993 Magic: The Gathering Unlimited Collection (250+)')).toBe(true);74    expect(isBundleTitle('2000 Pokemon Black Star Promo #23 Zapdos - PSA GEM MT 10')).toBe(false);75    const a = parseCardAttributes('2000 Pokemon Black Star Promo #23 Zapdos - PSA GEM MT 10', 'pokemon');76    expect(a).toMatchObject({ brand: 'Pokemon', set: 'Black Star Promo', number: '23', name: 'Zapdos' });77    const b = parseCardAttributes('2003-04 Topps Chrome #111 LeBron James Rookie Card - PSA GEM MT 10', 'basketball_cards');78    expect(b.brand).toBe('Topps Chrome');79    expect(b.number).toBe('111');80    expect(b.name).toMatch(/^LeBron James/);81  });82});83