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.3 KB · 47 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import meta from './meta.json' with { type: 'json' };3import { localMeta } from '../../api/_lib/local-meta.js';4import { listFixtures, loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';5import createConnector, { parsePlatformPage, splitPlatform, type PagePayload } from './index.js';67const connector = createConnector(localMeta(meta));89describe('estarland', () => {10  runFixtureSuite(connector, it, expect);1112  it('parses main-grid cards (not carousel duplicates) and the pager from the saved platform page', () => {13    const name = listFixtures('estarland')[0]!;14    const fx = loadFixture('estarland', name);15    const p = fx.raw.payload as PagePayload;16    const parsed = parsePlatformPage(p.snapshot!, fx.raw.url, p.seed, p.categorySlug, p.brand, 1);17    expect(parsed.cards.length).toBeGreaterThanOrEqual(3);18    expect(parsed.totalPages).toBeGreaterThan(1);19    for (const c of parsed.cards) {20      expect(c.productId).toMatch(/^\d+$/);21      expect(c.url).toMatch(/^https:\/\/www\.estarland\.com\/product-description\//);22      expect(c.platformLine).toBeTruthy();23      expect(['New', 'Used']).toContain(c.condition);24    }25    expect(new Set(parsed.cards.map((c) => c.productId)).size).toBe(parsed.cards.length);26  });2728  it('splits platform lines and normalises to USD listings with platform as set', async () => {29    expect(splitPlatform('Nintendo / NES')).toEqual({ brand: 'Nintendo', platform: 'NES' });30    expect(splitPlatform(null)).toEqual({ brand: null, platform: null });31    expect(splitPlatform('Multi-Platform')).toEqual({ brand: 'Multi-Platform', platform: null });32    for (const name of listFixtures('estarland')) {33      const out = await connector.normalize(loadFixture('estarland', name).raw);34      expect(out.length).toBeGreaterThan(0);35      for (const r of out) {36        if (r.kind !== 'listing') throw new Error('expected listing');37        expect(meta.categories).toContain(r.attributes.categorySlug);38        expect(r.currency).toBe('USD');39        expect(r.price).toBeGreaterThan(0);40        expect(r.attributes.identifiers.estarland_product_id).toBe(r.externalId);41        expect(r.seller).toBe('eStarland');42        if (r.condition.conditionRaw === 'Used') expect(r.condition.completeness).toBeNull();43      }44    }45  });46});47