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.9 KB · 54 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import metaJson from './meta.json' with { type: 'json' };3import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';4import { localMeta } from '../_lib/local-meta.js';5import { designSlug } from '../_g10-lib/index.js';6import createConnector, { hasNextPage, pageUrl, parseBrowseHtml } from './index.js';78const connector = createConnector(localMeta(metaJson));910describe('chairish', () => {11  runFixtureSuite(connector, it, expect);1213  it('parses JSON-LD products from a browse page snapshot', () => {14    const html = String((loadFixture('chairish', 'vintage-furniture-p2').raw.payload as { snapshot?: string }).snapshot ?? '');15    const items = parseBrowseHtml(html);16    expect(items.length).toBeGreaterThanOrEqual(2);17    const first = items[0]!;18    expect(first.id).toMatch(/^\d+$/);19    expect(first.url).toMatch(/^https:\/\/www\.chairish\.com\/product\/\d+\//);20    expect(first.price).toBeGreaterThan(0);21    expect(first.currency).toBe('USD');22    expect(first.category).toMatch(/^Furniture/);23    expect(first.availability).toBe('available');24    expect(first.images[0]).toMatch(/chairish-prod/);25    expect(hasNextPage(html)).toBe(true);26    expect(hasNextPage('<html><head></head><body></body></html>')).toBe(false);27  });2829  it('builds page urls and maps categories', () => {30    expect(pageUrl('/collection/lighting', 1)).toBe('https://www.chairish.com/collection/lighting');31    expect(pageUrl('/collection/lighting', 3)).toBe('https://www.chairish.com/collection/lighting?page=3');32    expect(designSlug('Furniture > Chairs > Chaises', 'Adrian Pearsall for Craft Associates Chaise Lounge', 'furniture')).toBe('design_furniture');33    expect(designSlug('Furniture > Chairs', 'Set of Five Louis XVI Style Carved Beech Dining Chairs, 19th Century', 'furniture')).toBe('antiques');34    expect(designSlug('Decor > Vases', 'Murano Glass Vase by Venini, 1960s', 'decor')).toBe('glass_crystal');35    expect(designSlug('Decor > Clocks', 'Howard Miller Mantel Clock', 'decor')).toBe('clocks');36    expect(designSlug('Rugs > Area Rugs', 'Vintage Persian Rug 8x10', 'rugs')).toBeNull();37    expect(designSlug('Jewelry > Watches', 'Rolex Datejust 1601', 'watches')).toBe('rolex');38  });3940  it('normalises listings in USD with the seller location and product id', async () => {41    const fx = loadFixture('chairish', 'vintage-furniture-p2');42    const out = await connector.normalize(fx.raw);43    expect(out.length).toBeGreaterThan(0);44    for (const r of out) {45      if (r.kind !== 'listing') throw new Error('expected listing');46      expect(r.currency).toBe('USD');47      expect(r.price).toBeGreaterThan(0);48      expect(r.attributes.identifiers.chairish_product_id).toMatch(/^\d+$/);49      expect(['design_furniture', 'antiques', 'clocks', 'porcelain', 'glass_crystal', 'silver', 'art']).toContain(r.attributes.categorySlug);50      expect(r.listingType).toBe('fixed_price');51    }52  });53});54