import { describe, expect, it } from 'vitest'; import meta from './meta.json' with { type: 'json' }; import { localMeta } from '../../api/_lib/local-meta.js'; import { listFixtures, loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import createConnector, { availabilityOf, parseCategoryPage, type PagePayload } from './index.js'; const connector = createConnector(localMeta(meta)); describe('entertainment-earth', () => { runFixtureSuite(connector, it, expect); it('parses product tiles and pagination from the saved category page', () => { const fx = loadFixture('entertainment-earth', 's-action-figures-p-p1'); const p = fx.raw.payload as PagePayload; const parsed = parseCategoryPage(p.snapshot!, fx.raw.url, p.seed, p.categorySlug, 1); expect(parsed.tiles.length).toBe(4); expect(parsed.totalPages).toBe(73); const t = parsed.tiles.find((x) => x.sku === 'BFEH0021')!; expect(t).toMatchObject({ name: 'Epic H.A.C.K.S. Rand Arora: Gamma Squad Leader 6-Inch Action Figure', price: 39.99, company: 'Boss Fight Studio', theme: 'Vitruvian H.A.C.K.S.', collect: 'Action Figures' }); expect(t.url).toBe('https://www.entertainmentearth.com/product/epic-hacks-rand-arora-gamma-squad-leader-6inch-action-figure/bfeh0021'); expect(t.image).toMatch(/^https:\/\/media\.entertainmentearth\.com\//); expect(t.buttonText).toMatch(/Pre-Order/); }); it('maps button labels to availability', () => { expect(availabilityOf('Pre-Order: Add to Cart')).toEqual({ availability: 'available', preorder: true }); expect(availabilityOf('Add to Cart')).toEqual({ availability: 'available', preorder: false }); expect(availabilityOf('Sold Out')).toEqual({ availability: 'sold', preorder: false }); expect(availabilityOf(null)).toEqual({ availability: 'unknown', preorder: false }); }); it('normalises tiles into USD listings with brand/franchise/sku per seed category', async () => { for (const name of listFixtures('entertainment-earth')) { const fx = loadFixture('entertainment-earth', name); const p = fx.raw.payload as PagePayload; const out = await connector.normalize(fx.raw); expect(out.length).toBeGreaterThan(0); for (const r of out) { if (r.kind !== 'listing') throw new Error('expected listing'); expect(r.attributes.categorySlug).toBe(p.categorySlug); expect(r.currency).toBe('USD'); expect(r.price).toBeGreaterThan(0); expect(r.attributes.identifiers.sku).toBe(r.externalId); expect(r.seller).toBe('Entertainment Earth'); expect(r.condition.completeness).toBe('sealed'); } } const funko = await connector.normalize(loadFixture('entertainment-earth', 's-funko-c-p1').raw); expect(funko.every((r) => r.kind === 'listing' && r.attributes.categorySlug === 'funko')).toBe(true); }); });