import { describe, expect, it } from 'vitest'; import { ConnectorMetaSchema } from '@rareindex/connectors'; import metaJson from './meta.json' with { type: 'json' }; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import createConnector from './index.js'; const connector = createConnector(ConnectorMetaSchema.parse(metaJson)); describe('lego-shop', () => { runFixtureSuite(connector, it, expect); it('emits official MSRP catalog items and store listings keyed by set number', async () => { const fx = loadFixture('lego-shop', 'star-wars-theme-p1'); const out = await connector.normalize(fx.raw); const cats = out.filter((r) => r.kind === 'catalog_item'); const lst = out.filter((r) => r.kind === 'listing'); expect(cats.length).toBeGreaterThanOrEqual(4); expect(lst.length).toBeGreaterThanOrEqual(4); for (const c of cats) { if (c.kind !== 'catalog_item') continue; expect(c.attributes.categorySlug).toBe('lego_sets'); expect(c.attributes.identifiers.lego_set_number).toMatch(/^\d{4,6}$/); expect(c.attributes.number).toBe(c.attributes.identifiers.lego_set_number); expect(c.attributes.brand).toBe('LEGO'); expect(c.attributes.franchise).toBe('Star Wars'); expect(c.attributes.originalMsrpCurrency).toBe('USD'); expect(c.attributes.originalMsrp).toBeGreaterThan(0); expect(c.sourceUrl).toMatch(/lego\.com\/en-us\/product\//); } const l = lst[0]!; if (l.kind !== 'listing') throw new Error(); expect(l.seller).toBe('LEGO Shop (official)'); expect(l.currency).toBe('USD'); }); });