TypeScript 61.9%
HTML 37.2%
SQL 0.7%
1import { readFileSync } from 'node:fs';2import path from 'node:path';3import { describe, expect, it } from 'vitest';4import { getConnectorMeta } from '@rareindex/connectors';5import { fixtureDir, loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';6import createConnector, { parseInventoryPage, parseProductPage } from './index.js';78const connector = createConnector(getConnectorMeta('european-watch-company'));9const sample = (name: string) => readFileSync(path.join(fixtureDir('european-watch-company'), name), 'utf8');1011describe('european-watch-company', () => {12 runFixtureSuite(connector, it, expect);1314 it('parses inventory cards (title, USD price, badge, image, product url) and dedupes desktop/mobile layouts', () => {15 const p = parseInventoryPage(sample('inventory-cards.sample.html'), 'https://www.europeanwatch.com/all');16 expect(p.cards.length).toBeGreaterThanOrEqual(1);17 const c = p.cards[0]!;18 expect(c.id).toBe('71732');19 expect(c.title).toBe('Patek Philippe 7010R-013 Nautilus Luce Diamonds 18K Rose Gold Purple Wave Dial');20 expect(c.price).toBe(79900);21 expect(c.currency).toBe('USD');22 expect(c.badge).toBe('Sale Pending');23 expect(c.href).toBe('https://www.europeanwatch.com/watch/patek-philippe-7010r-013-7010r-013-nautilus-luce-diamonds-18k-ros-71732');24 expect(c.image).toBe('https://images.europeanwatch.com/images/71/71732-1.jpg');25 expect(new Set(p.cards.map((x) => x.id)).size).toBe(p.cards.length);26 });2728 it('parses the product page JSON-LD (sku, mpn = reference, offer)', async () => {29 const p = parseProductPage(sample('product-jsonld.sample.html'), 'https://www.europeanwatch.com/watch/patek-philippe-7010r-013-7010r-013-nautilus-luce-diamonds-18k-ros-71732');30 expect(p?.kind).toBe('product_page');31 if (p?.kind !== 'product_page') throw new Error();32 expect(p.product.sku).toBe('71732');33 expect(p.product.mpn).toBe('7010R-013');34 expect(p.product.price).toBe(79900);35 expect(p.product.currency).toBe('USD');36 expect(p.product.availability).toBe('OutOfStock');37 expect(p.product.condition).toBe('UsedCondition');38 const out = await connector.normalize({ url: p.url, externalId: null, kind: 'listing', engine: 'api', fetchedAt: new Date('2026-09-08T00:00:00Z'), payload: p });39 const l = out[0];40 if (l?.kind !== 'listing') throw new Error('expected listing');41 expect(l.attributes.reference).toBe('7010R-013');42 expect(l.attributes.brand).toBe('Patek Philippe');43 expect(l.attributes.categorySlug).toBe('patek_philippe');44 expect(l.attributes.identifiers).toEqual({ ewc_sku: '71732', reference: '7010R-013' });45 expect(l.availability).toBe('ended');46 expect(l.price).toBe(79900);47 });4849 it('inventory fixture normalises to USD dealer listings with brand-based categories', async () => {50 const fx = loadFixture('european-watch-company', 'inventory-all');51 const out = await connector.normalize(fx.raw);52 expect(out.length).toBeGreaterThan(5);53 for (const r of out) {54 if (r.kind !== 'listing') throw new Error('expected listing');55 expect(r.currency).toBe('USD');56 expect(r.seller).toBe('European Watch Company');57 expect(r.listingType).toBe('fixed_price');58 }59 expect(out.some((r) => r.kind === 'listing' && r.attributes.categorySlug === 'patek_philippe')).toBe(true);60 const gs = out.find((r) => r.kind === 'listing' && /SBGE201G/.test(r.rawTitle));61 expect(gs && gs.kind === 'listing' ? gs.attributes.reference : null).toBe('SBGE201G');62 });63});64