import { describe, expect, it } from 'vitest'; import { ConnectorMetaSchema } from '@rareindex/connectors'; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import metaJson from './meta.json' with { type: 'json' }; import createConnector, { parseBrowsePage } from './index.js'; const connector = createConnector(ConnectorMetaSchema.parse(metaJson)); describe('saatchi-art', () => { runFixtureSuite(connector, it, expect); it('maps artworks to USD fixed-price listings with artist, medium and size', async () => { const fx = loadFixture('saatchi-art', 'paintings-page-1'); const out = await connector.normalize(fx.raw); expect(out.length).toBe(25); for (const r of out) { if (r.kind !== 'listing') throw new Error('expected listing'); expect(r.currency).toBe('USD'); expect(r.listingType).toBe('fixed_price'); expect(['available', 'sold', 'unknown']).toContain(r.availability); expect(r.attributes.identifiers.saatchi_artwork_id).toMatch(/^\d+$/); expect(r.attributes.brand).toBeTruthy(); expect(r.sourceUrl).toMatch(/^https:\/\/www\.saatchiart\.com\/art\//); } }); it('parses __NEXT_DATA__ browse pages', () => { const html = ``; const p = parseBrowsePage(html, 'u', { path: '/paintings', category: 'contemporary_art' }, 1)!; expect(p.totalResults).toBe(2); expect(p.works[0]).toMatchObject({ artworkId: '1', title: 'A', listPriceCents: 123400, status: 'sold', widthCm: 10 }); expect(parseBrowsePage('', 'u', { path: '/x', category: 'art' }, 1)).toBeNull(); }); });