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 '../../api/_lib/local-meta.js'; import createConnector, { bbtsCategory, parseSearchMarkdown } 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); const MD = `Hide In Stock ## Product Results - ![](https://images.bigbadtoystore.com/images/product/197167/a.png) ### [Declaration of War MJZ-05 Dark Shadow 1/100 Scale Limited Edition Action Figure](https://www.bigbadtoystore.com/product/declaration-war-mjz-05-dark-shadow-1_100-scale-action-figure-197167?variation=388429) By: Hot General PRE-ORDER $118.99 - ![](https://images.bigbadtoystore.com/images/product/197181/b.jpg) ### [Pop! Marvel Deadpool Vinyl Figure - BBTS Exclusive](https://www.bigbadtoystore.com/product/pop-marvel-deadpool-197181?variation=388500) By: Funko SOLD OUT $14.99 `; describe('bbts', () => { runFixtureSuite(connector, it, expect); it('parses product cards from the rendered search markdown', () => { const p = parseSearchMarkdown(MD, 'hot toys', 1); expect(p.items.length).toBe(2); expect(p.items[0]).toMatchObject({ productId: '197167', variation: '388429', brand: 'Hot General', status: 'PRE-ORDER', price: 118.99, url: 'https://www.bigbadtoystore.com/product/declaration-war-mjz-05-dark-shadow-1_100-scale-action-figure-197167' }); expect(p.items[1]).toMatchObject({ productId: '197181', brand: 'Funko', status: 'SOLD OUT', price: 14.99 }); expect(bbtsCategory(p.items[1]!.title, 'Funko')).toBe('funko'); expect(bbtsCategory('MG 1/100 RX-78-2 Gundam Ver. 3.0 Model Kit', 'Bandai')).toBe('gundam'); expect(bbtsCategory('BE@RBRICK KAWS 1000%', 'Medicom')).toBe('designer_toys'); }); it('normalises to catalog items + retailer listings with stock-aware availability', async () => { const out = await connector.normalize({ url: 'x', externalId: 'q:1', kind: 'listing', engine: 'firecrawl', fetchedAt: new Date('2026-09-07T00:00:00Z'), payload: parseSearchMarkdown(MD, 'hot toys', 1) }); expect(out.map((r) => r.kind)).toEqual(['catalog_item', 'listing', 'catalog_item', 'listing']); const soldOut = out[3]!; if (soldOut.kind !== 'listing') throw new Error('listing'); expect(soldOut.availability).toBe('ended'); expect(soldOut.attributes.categorySlug).toBe('funko'); const pre = out[1]!; if (pre.kind !== 'listing') throw new Error('listing'); expect(pre).toMatchObject({ price: 118.99, currency: 'USD', availability: 'available', seller: 'BigBadToyStore' }); }); it('fixture normalises', async () => { expect((await connector.normalize(loadFixture('bbts', 'search-page').raw)).length).toBeGreaterThan(0); }); });