TypeScript 61.9%
HTML 37.2%
SQL 0.7%
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 createConnector, { makeDeref, pageUrl, parseBrowseHtml } from './index.js';67const connector = createConnector(localMeta(metaJson));89describe('1stdibs', () => {10 runFixtureSuite(connector, it, expect);1112 it('parses Item records out of the serverVars_data Relay store', () => {13 const html = String((loadFixture('1stdibs', 'seating-chairs-p1').raw.payload as { snapshot?: string }).snapshot ?? '');14 const p = parseBrowseHtml(html);15 expect(p).not.toBeNull();16 expect(p!.items.length).toBeGreaterThanOrEqual(2);17 expect(p!.totalResults).toBeGreaterThan(1000);18 expect(p!.maxPages).toBe(50);19 const it0 = p!.items[0]!;20 expect(it0.serviceId).toMatch(/^f_\d+$/);21 expect(it0.url).toMatch(/^https:\/\/www\.1stdibs\.com\/furniture\/.+\/id-f_\d+\/$/);22 expect(it0.prices.USD).toBeGreaterThan(0);23 expect(it0.prices.EUR).toBeGreaterThan(0);24 expect(it0.seller.serviceId).toMatch(/^f_\d+$/);25 expect(it0.images[0]).toMatch(/1stdibscdn\.com/);26 expect(it0.categoryCode).toMatch(/^F_/);27 expect(pageUrl('/furniture/seating/', 2)).toBe('https://www.1stdibs.com/furniture/seating/?page=2');28 });2930 it('dereferences __ref / __refs chains', () => {31 const store = { a: { __typename: 'A', b: { __ref: 'b' }, list: { __refs: ['c', 'c'] } }, b: { __typename: 'B', v: 1 }, c: { __typename: 'C', v: 2 } };32 const deref = makeDeref(store as never);33 expect(deref(store.a)).toEqual({ __typename: 'A', b: { __typename: 'B', v: 1 }, list: [{ __typename: 'C', v: 2 }, { __typename: 'C', v: 2 }] });34 expect(parseBrowseHtml('<html><body>no store</body></html>')).toBeNull();35 });3637 it('normalises items into USD dealer listings with designer, seller and identifiers', async () => {38 const fx = loadFixture('1stdibs', 'seating-chairs-p1');39 const out = await connector.normalize(fx.raw);40 expect(out.length).toBeGreaterThan(0);41 for (const r of out) {42 if (r.kind !== 'listing') throw new Error('expected listing');43 expect(r.currency).toBe('USD');44 expect(r.price).toBeGreaterThan(0);45 expect(r.attributes.identifiers.firstdibs_item_id).toMatch(/^f_\d+$/);46 expect(['design_furniture', 'antiques']).toContain(r.attributes.categorySlug);47 expect(r.seller).toBeTruthy();48 }49 const jw = loadFixture('1stdibs', 'wrist-watches-p1');50 const jwOut = await connector.normalize(jw.raw);51 expect(jwOut.length).toBeGreaterThan(0);52 for (const r of jwOut) expect(['rolex', 'omega', 'patek_philippe', 'audemars_piguet', 'other_watches']).toContain((r as { attributes: { categorySlug: string } }).attributes.categorySlug);53 });54});55