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.9 KB · 67 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 '../../api/_lib/local-meta.js';7import createConnector, { bbtsCategory, parseSearchMarkdown } from './index.js';89const dir = path.dirname(fileURLToPath(import.meta.url));10const meta = localMeta(JSON.parse(readFileSync(path.join(dir, 'meta.json'), 'utf8')));11const connector = createConnector(meta);1213const MD = `Hide In Stock1415## Product Results1617- ![](https://images.bigbadtoystore.com/images/product/197167/a.png)1819### [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)2021By: Hot General2223PRE-ORDER2425$118.992627- ![](https://images.bigbadtoystore.com/images/product/197181/b.jpg)2829### [Pop! Marvel Deadpool Vinyl Figure - BBTS Exclusive](https://www.bigbadtoystore.com/product/pop-marvel-deadpool-197181?variation=388500)3031By: Funko3233SOLD OUT3435$14.9936`;3738describe('bbts', () => {39  runFixtureSuite(connector, it, expect);4041  it('parses product cards from the rendered search markdown', () => {42    const p = parseSearchMarkdown(MD, 'hot toys', 1);43    expect(p.items.length).toBe(2);44    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' });45    expect(p.items[1]).toMatchObject({ productId: '197181', brand: 'Funko', status: 'SOLD OUT', price: 14.99 });46    expect(bbtsCategory(p.items[1]!.title, 'Funko')).toBe('funko');47    expect(bbtsCategory('MG 1/100 RX-78-2 Gundam Ver. 3.0 Model Kit', 'Bandai')).toBe('gundam');48    expect(bbtsCategory('BE@RBRICK KAWS 1000%', 'Medicom')).toBe('designer_toys');49  });5051  it('normalises to catalog items + retailer listings with stock-aware availability', async () => {52    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) });53    expect(out.map((r) => r.kind)).toEqual(['catalog_item', 'listing', 'catalog_item', 'listing']);54    const soldOut = out[3]!;55    if (soldOut.kind !== 'listing') throw new Error('listing');56    expect(soldOut.availability).toBe('ended');57    expect(soldOut.attributes.categorySlug).toBe('funko');58    const pre = out[1]!;59    if (pre.kind !== 'listing') throw new Error('listing');60    expect(pre).toMatchObject({ price: 118.99, currency: 'USD', availability: 'available', seller: 'BigBadToyStore' });61  });6263  it('fixture normalises', async () => {64    expect((await connector.normalize(loadFixture('bbts', 'search-page').raw)).length).toBeGreaterThan(0);65  });66});67