import { describe, expect, it } from 'vitest'; import { readFileSync } from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import { localMeta } from '../_lib/local-meta.js'; import { popCultureCategory, toyGrade } from '../_memorabilia-lib/index.js'; import createConnector from './index.js'; const dir = path.dirname(fileURLToPath(import.meta.url)); const meta = localMeta(JSON.parse(readFileSync(path.join(dir, 'meta.json'), 'utf8'))); const connector = createConnector(meta); describe('hakes', () => { runFixtureSuite(connector, it, expect); it('maps pop-culture titles to taxonomy slugs', () => { expect(popCultureCategory('STAR WARS (1978) - LUKE SKYWALKER 12 BACK-B AFA 85 Y-NM+')).toBe('star_wars'); expect(popCultureCategory('AMAZING SPIDER-MAN #300 1988 CGC 9.8 NM/MINT')).toBe('marvel_comics'); expect(popCultureCategory('DETECTIVE COMICS #27 1939 CGC 3.0')).toBe('dc_comics'); expect(popCultureCategory('1860 ABRAHAM LINCOLN CAMPAIGN FERROTYPE PIN')).toBe('political_memorabilia'); expect(popCultureCategory('1952 TOPPS #311 MICKEY MANTLE PSA 4')).toBe('baseball_cards'); expect(popCultureCategory('GARBAGE PAIL KIDS 1985 SERIES 1 WAX BOX')).toBe('non_sport_cards'); expect(popCultureCategory('MICKEY MOUSE 1930s LIONEL HANDCAR')).toBe('disney_collectibles'); expect(toyGrade('STAR WARS DROIDS 1985 - A-WING FIGHTER VEHICLE AFA QUALIFIED 60 Q-EX')).toEqual({ company: 'AFA', grade: '60' }); }); it('upcoming catalogs become auction lots with estimates and end times; sold lots would become sales', async () => { const fx = loadFixture('hakes', 'catalog-page'); const out = await connector.normalize(fx.raw); expect(out.length).toBeGreaterThan(0); const lot = out.find((r) => r.kind === 'auction_lot'); if (lot && lot.kind === 'auction_lot') { expect(lot.auctionHouse).toBe("Hake's Auctions"); expect(lot.currency).toBe('USD'); expect(lot.endsAt).toBeInstanceOf(Date); } // Same payload flagged as past with a sold label → sale const p = structuredClone(fx.raw.payload) as { event: { status: string }; items: Array<{ priceLabel: string | null; price: number | null }> }; p.event.status = 'past'; p.items[0]!.priceLabel = 'Sold for'; p.items[0]!.price = 1234; const sold = await connector.normalize({ ...fx.raw, payload: p }); const s = sold.find((r) => r.kind === 'sale'); expect(s).toBeDefined(); if (s && s.kind === 'sale') { expect(s.price).toBe(1234); expect(s.buyerPremiumIncluded).toBeNull(); } }); });