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 { designSlug } from '../_g10-lib/index.js'; import createConnector, { hasNextPage, pageUrl, parseBrowseHtml } from './index.js'; const connector = createConnector(localMeta(metaJson)); describe('chairish', () => { runFixtureSuite(connector, it, expect); it('parses JSON-LD products from a browse page snapshot', () => { const html = String((loadFixture('chairish', 'vintage-furniture-p2').raw.payload as { snapshot?: string }).snapshot ?? ''); const items = parseBrowseHtml(html); expect(items.length).toBeGreaterThanOrEqual(2); const first = items[0]!; expect(first.id).toMatch(/^\d+$/); expect(first.url).toMatch(/^https:\/\/www\.chairish\.com\/product\/\d+\//); expect(first.price).toBeGreaterThan(0); expect(first.currency).toBe('USD'); expect(first.category).toMatch(/^Furniture/); expect(first.availability).toBe('available'); expect(first.images[0]).toMatch(/chairish-prod/); expect(hasNextPage(html)).toBe(true); expect(hasNextPage('')).toBe(false); }); it('builds page urls and maps categories', () => { expect(pageUrl('/collection/lighting', 1)).toBe('https://www.chairish.com/collection/lighting'); expect(pageUrl('/collection/lighting', 3)).toBe('https://www.chairish.com/collection/lighting?page=3'); expect(designSlug('Furniture > Chairs > Chaises', 'Adrian Pearsall for Craft Associates Chaise Lounge', 'furniture')).toBe('design_furniture'); expect(designSlug('Furniture > Chairs', 'Set of Five Louis XVI Style Carved Beech Dining Chairs, 19th Century', 'furniture')).toBe('antiques'); expect(designSlug('Decor > Vases', 'Murano Glass Vase by Venini, 1960s', 'decor')).toBe('glass_crystal'); expect(designSlug('Decor > Clocks', 'Howard Miller Mantel Clock', 'decor')).toBe('clocks'); expect(designSlug('Rugs > Area Rugs', 'Vintage Persian Rug 8x10', 'rugs')).toBeNull(); expect(designSlug('Jewelry > Watches', 'Rolex Datejust 1601', 'watches')).toBe('rolex'); }); it('normalises listings in USD with the seller location and product id', async () => { const fx = loadFixture('chairish', 'vintage-furniture-p2'); 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.chairish_product_id).toMatch(/^\d+$/); expect(['design_furniture', 'antiques', 'clocks', 'porcelain', 'glass_crystal', 'silver', 'art']).toContain(r.attributes.categorySlug); expect(r.listingType).toBe('fixed_price'); } }); });