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.1 KB · 35 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import { ConnectorMetaSchema } from '@rareindex/connectors';3import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';4import metaJson from './meta.json' with { type: 'json' };5import createConnector, { parseBrowsePage } from './index.js';67const connector = createConnector(ConnectorMetaSchema.parse(metaJson));89describe('saatchi-art', () => {10  runFixtureSuite(connector, it, expect);1112  it('maps artworks to USD fixed-price listings with artist, medium and size', async () => {13    const fx = loadFixture('saatchi-art', 'paintings-page-1');14    const out = await connector.normalize(fx.raw);15    expect(out.length).toBe(25);16    for (const r of out) {17      if (r.kind !== 'listing') throw new Error('expected listing');18      expect(r.currency).toBe('USD');19      expect(r.listingType).toBe('fixed_price');20      expect(['available', 'sold', 'unknown']).toContain(r.availability);21      expect(r.attributes.identifiers.saatchi_artwork_id).toMatch(/^\d+$/);22      expect(r.attributes.brand).toBeTruthy();23      expect(r.sourceUrl).toMatch(/^https:\/\/www\.saatchiart\.com\/art\//);24    }25  });2627  it('parses __NEXT_DATA__ browse pages', () => {28    const html = `<script id="__NEXT_DATA__" type="application/json">${JSON.stringify({ props: { pageProps: { initialState: { searchProvider: { serverSideData: { totalResults: 2, results: [{ artworkId: '1', artworkTitle: 'A', artworkOriginalUrl: '/art/Painting-A/1/1/view', artistFirstName: 'jane', artistLastName: 'doe', category: 'Painting', mediums: ['oil'], materials: ['canvas'], dimensions: { widthInCentimeters: 10, heightInCentimeters: 20 }, listPriceInCents: 123400, originalArtworkStatus: 'sold', imageUrl: 'https://i/x.jpg' }] } } } } } })}</script>`;29    const p = parseBrowsePage(html, 'u', { path: '/paintings', category: 'contemporary_art' }, 1)!;30    expect(p.totalResults).toBe(2);31    expect(p.works[0]).toMatchObject({ artworkId: '1', title: 'A', listPriceCents: 123400, status: 'sold', widthCm: 10 });32    expect(parseBrowsePage('<html></html>', 'u', { path: '/x', category: 'art' }, 1)).toBeNull();33  });34});35