import { describe, expect, it } from 'vitest'; import meta from './meta.json' with { type: 'json' }; import { localMeta } from '../_lib/local-meta.js'; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import createConnector, { parseListingPage, type PagePayload } from './index.js'; const connector = createConnector(localMeta(meta)); describe('miniature-market', () => { runFixtureSuite(connector, it, expect); it('parses Shopware product boxes, list vs. our price, ids and total pages from the saved page', () => { const fx = loadFixture('miniature-market', 'board-games-new-releases-html-p1'); const p = fx.raw.payload as PagePayload; const parsed = parseListingPage(p.snapshot!, fx.raw.url, p.seed, p.categorySlug, 1); expect(parsed.boxes.length).toBeGreaterThanOrEqual(3); expect(parsed.totalPages).toBeGreaterThan(0); const b = parsed.boxes[0]!; expect(b.name.length).toBeGreaterThan(2); expect(b.url).toMatch(/^https:\/\/www\.miniaturemarket\.com\//); expect(b.sku).toBeTruthy(); expect(b.productId).toMatch(/^[0-9a-f]{32}$/); expect(b.price).toBeGreaterThan(0); expect(b.buttonText).toMatch(/Add to cart|Preorder/i); const withList = parsed.boxes.find((x) => x.listPrice !== null); if (withList) expect(withList.listPrice!).toBeGreaterThanOrEqual(withList.price!); }); it('normalises to USD board-game listings carrying the retail list price as originalMsrp', async () => { const out = await connector.normalize(loadFixture('miniature-market', 'board-games-new-releases-html-p1').raw); expect(out.length).toBeGreaterThan(10); for (const r of out) { if (r.kind !== 'listing') throw new Error('expected listing'); expect(r.attributes.categorySlug).toBe('board_games'); expect(r.currency).toBe('USD'); expect(r.price).toBeGreaterThan(0); expect(r.seller).toBe('Miniature Market'); expect(r.attributes.identifiers.miniaturemarket_product_id ?? r.attributes.identifiers.sku).toBeTruthy(); if (r.attributes.originalMsrp !== null) expect(r.attributes.originalMsrpCurrency).toBe('USD'); } }); });