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, { parsePlatformPage, splitPlatform, type PagePayload } from './index.js'; const connector = createConnector(localMeta(meta)); describe('estarland', () => { runFixtureSuite(connector, it, expect); it('parses main-grid cards (not carousel duplicates) and the pager from the saved platform page', () => { const name = listFixtures('estarland')[0]!; const fx = loadFixture('estarland', name); const p = fx.raw.payload as PagePayload; const parsed = parsePlatformPage(p.snapshot!, fx.raw.url, p.seed, p.categorySlug, p.brand, 1); expect(parsed.cards.length).toBeGreaterThanOrEqual(3); expect(parsed.totalPages).toBeGreaterThan(1); for (const c of parsed.cards) { expect(c.productId).toMatch(/^\d+$/); expect(c.url).toMatch(/^https:\/\/www\.estarland\.com\/product-description\//); expect(c.platformLine).toBeTruthy(); expect(['New', 'Used']).toContain(c.condition); } expect(new Set(parsed.cards.map((c) => c.productId)).size).toBe(parsed.cards.length); }); it('splits platform lines and normalises to USD listings with platform as set', async () => { expect(splitPlatform('Nintendo / NES')).toEqual({ brand: 'Nintendo', platform: 'NES' }); expect(splitPlatform(null)).toEqual({ brand: null, platform: null }); expect(splitPlatform('Multi-Platform')).toEqual({ brand: 'Multi-Platform', platform: null }); for (const name of listFixtures('estarland')) { const out = await connector.normalize(loadFixture('estarland', name).raw); expect(out.length).toBeGreaterThan(0); for (const r of out) { if (r.kind !== 'listing') throw new Error('expected listing'); expect(meta.categories).toContain(r.attributes.categorySlug); expect(r.currency).toBe('USD'); expect(r.price).toBeGreaterThan(0); expect(r.attributes.identifiers.estarland_product_id).toBe(r.externalId); expect(r.seller).toBe('eStarland'); if (r.condition.conditionRaw === 'Used') expect(r.condition.completeness).toBeNull(); } } }); });