import { describe, expect, it } from 'vitest'; import metaJson from './meta.json' with { type: 'json' }; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import { localMeta } from '../_lib/local-meta.js'; import { makerFromTitle, yearOrDecade } from '../_g10-lib/index.js'; import createConnector, { pageUrl, parseCategoryHtml, parseStoreCurrency } from './index.js'; const connector = createConnector(localMeta(metaJson)); describe('pamono', () => { runFixtureSuite(connector, it, expect); it('parses product cards (sku, price content, image) and the store currency', () => { const html = String((loadFixture('pamono', 'furniture-p1').raw.payload as { snapshot?: string }).snapshot ?? ''); expect(parseStoreCurrency(html)).toBe('USD'); const cards = parseCategoryHtml(html); expect(cards.length).toBeGreaterThanOrEqual(2); const c = cards[0]!; expect(c.sku).toMatch(/^[A-Z0-9]{2,4}-\d+$/); expect(c.productId).toMatch(/^\d+$/); expect(c.url).toMatch(/^https:\/\/www\.pamono\.com\//); expect(c.price).toBeGreaterThan(0); expect(c.currency).toBe('USD'); expect(c.image).toMatch(/cdn20\.pamono\.com/); }); it('parses makers and decades from titles', () => { expect(makerFromTitle('Large Coffee Table by Maison Jansen, 1970s')).toBe('Maison Jansen'); expect(makerFromTitle('Mid-Century Teak Tola Sideboard from Greaves & Thomas')).toBe('Greaves & Thomas'); expect(makerFromTitle('Art Deco Ruby and Diamonds Brooch, 1920s')).toBeNull(); expect(yearOrDecade('Large Coffee Table by Maison Jansen, 1970s')).toEqual({ year: null, decade: '1970s' }); expect(yearOrDecade('Egg Chair by Arne Jacobsen for Fritz Hansen, 1965')).toEqual({ year: 1965, decade: null }); expect(pageUrl('/furniture', 2)).toBe('https://www.pamono.com/furniture?p=2'); }); it('normalises cards into USD listings with pamono identifiers', async () => { const fx = loadFixture('pamono', 'furniture-p1'); const out = await connector.normalize(fx.raw); expect(out.length).toBeGreaterThan(0); for (const r of out) { if (r.kind !== 'listing') throw new Error('expected listing'); expect(r.currency).toBe('USD'); expect(r.price).toBeGreaterThan(0); expect(r.attributes.identifiers.pamono_sku).toBeTruthy(); expect(['design_furniture', 'antiques', 'clocks', 'glass_crystal', 'porcelain', 'silver', 'art']).toContain(r.attributes.categorySlug); } const jw = loadFixture('pamono', 'jewelry-watches-p1'); const jwOut = await connector.normalize(jw.raw); expect(jwOut.length).toBeGreaterThan(0); for (const r of jwOut) expect(['jewelry', 'gemstones', 'rolex', 'omega', 'patek_philippe', 'audemars_piguet', 'other_watches']).toContain((r as { attributes: { categorySlug: string } }).attributes.categorySlug); }); });