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 · 52 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import { readFileSync } from 'node:fs';3import path from 'node:path';4import { fileURLToPath } from 'node:url';5import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';6import { localMeta } from '../_lib/local-meta.js';7import { popCultureCategory, toyGrade } from '../_memorabilia-lib/index.js';8import createConnector from './index.js';910const dir = path.dirname(fileURLToPath(import.meta.url));11const meta = localMeta(JSON.parse(readFileSync(path.join(dir, 'meta.json'), 'utf8')));12const connector = createConnector(meta);1314describe('hakes', () => {15  runFixtureSuite(connector, it, expect);1617  it('maps pop-culture titles to taxonomy slugs', () => {18    expect(popCultureCategory('STAR WARS (1978) - LUKE SKYWALKER 12 BACK-B AFA 85 Y-NM+')).toBe('star_wars');19    expect(popCultureCategory('AMAZING SPIDER-MAN #300 1988 CGC 9.8 NM/MINT')).toBe('marvel_comics');20    expect(popCultureCategory('DETECTIVE COMICS #27 1939 CGC 3.0')).toBe('dc_comics');21    expect(popCultureCategory('1860 ABRAHAM LINCOLN CAMPAIGN FERROTYPE PIN')).toBe('political_memorabilia');22    expect(popCultureCategory('1952 TOPPS #311 MICKEY MANTLE PSA 4')).toBe('baseball_cards');23    expect(popCultureCategory('GARBAGE PAIL KIDS 1985 SERIES 1 WAX BOX')).toBe('non_sport_cards');24    expect(popCultureCategory('MICKEY MOUSE 1930s LIONEL HANDCAR')).toBe('disney_collectibles');25    expect(toyGrade('STAR WARS DROIDS 1985 - A-WING FIGHTER VEHICLE AFA QUALIFIED 60 Q-EX')).toEqual({ company: 'AFA', grade: '60' });26  });2728  it('upcoming catalogs become auction lots with estimates and end times; sold lots would become sales', async () => {29    const fx = loadFixture('hakes', 'catalog-page');30    const out = await connector.normalize(fx.raw);31    expect(out.length).toBeGreaterThan(0);32    const lot = out.find((r) => r.kind === 'auction_lot');33    if (lot && lot.kind === 'auction_lot') {34      expect(lot.auctionHouse).toBe("Hake's Auctions");35      expect(lot.currency).toBe('USD');36      expect(lot.endsAt).toBeInstanceOf(Date);37    }38    // Same payload flagged as past with a sold label → sale39    const p = structuredClone(fx.raw.payload) as { event: { status: string }; items: Array<{ priceLabel: string | null; price: number | null }> };40    p.event.status = 'past';41    p.items[0]!.priceLabel = 'Sold for';42    p.items[0]!.price = 1234;43    const sold = await connector.normalize({ ...fx.raw, payload: p });44    const s = sold.find((r) => r.kind === 'sale');45    expect(s).toBeDefined();46    if (s && s.kind === 'sale') {47      expect(s.price).toBe(1234);48      expect(s.buyerPremiumIncluded).toBeNull();49    }50  });51});52