TypeScript 61.9%
HTML 37.2%
SQL 0.7%
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 '../_lib/local-meta.js';7import createConnector, { splitTitle, trimProduct } 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);1213describe('trainz', () => {14 runFixtureSuite(connector, it, expect);1516 it('splits Trainz condition suffixes and trims products', () => {17 expect(splitTitle('Lionel 6-18005 O Gauge 700E Hudson Steam Locomotive LN/Box')).toEqual({ name: 'Lionel 6-18005 O Gauge 700E Hudson Steam Locomotive', conditionCode: 'LN/Box' });18 expect(splitTitle('S. Soho & Co. HO BRASS Passenger Coach Car- Unpainted EX/Box').conditionCode).toBe('EX/Box');19 expect(splitTitle('Marklin 3000 HO Steam Locomotive').conditionCode).toBeNull();20 const p = trimProduct({ id: 1, title: 'X LN/Box', handle: 'x', vendor: 'Lionel', product_type: 'Trains', tags: ['condition:Like New', 'foo', 'scale:O Gauge'], variants: [{ id: 2, sku: 'A', price: '10.00', available: true }], images: [] });21 expect(p?.tags).toEqual(['condition:Like New', 'scale:O Gauge']);22 });2324 it('emits a catalog item and a dealer listing per product with a normalised condition', async () => {25 const out = await connector.normalize({26 url: 'https://www.trainz.com/collections/lionel-o-postwar-trains/products.json?limit=250&page=1',27 externalId: 'lionel-o-postwar-trains:1',28 kind: 'listing',29 engine: 'api',30 fetchedAt: new Date('2026-09-07T00:00:00Z'),31 payload: { kind: 'collection_page', collection: 'lionel-o-postwar-trains', page: 1, products: [{ id: 99, title: 'Lionel 2343 O Gauge Santa Fe F3 AA Diesel Locomotive Set EX/Box', handle: 'lionel-2343', vendor: 'Lionel', product_type: 'Trains', tags: ['condition:Excellent', 'era:Postwar', 'scale:O Gauge'], created_at: '2026-09-01T00:00:00-04:00', updated_at: null, variants: [{ id: 1, sku: 'P123', price: '499.99', compare_at_price: null, available: true }], images: [{ src: 'https://cdn.shopify.com/x.jpg' }] }] },32 });33 expect(out.map((r) => r.kind)).toEqual(['catalog_item', 'listing']);34 const l = out[1]!;35 if (l.kind !== 'listing') throw new Error('listing');36 expect(l).toMatchObject({ price: 499.99, currency: 'USD', availability: 'available', seller: 'Trainz' });37 expect(l.attributes).toMatchObject({ categorySlug: 'model_trains', brand: 'Lionel', series: 'O Gauge', name: 'Lionel 2343 O Gauge Santa Fe F3 AA Diesel Locomotive Set' });38 expect(l.condition).toMatchObject({ condition: 'boxed', conditionRaw: 'Excellent' });39 expect(l.attributes.identifiers.trainz_sku).toBe('P123');40 });4142 it('fixture products all carry a vendor and a USD price', async () => {43 const out = await connector.normalize(loadFixture('trainz', 'collection-page').raw);44 expect(out.filter((r) => r.kind === 'listing').length).toBeGreaterThan(0);45 });46});47