import { describe, expect, it } from 'vitest'; import { readFileSync } from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import { localMeta } from '../_lib/local-meta.js'; import { parseSessionPage } from '../wright/index.js'; import { asInertiaHtml, SESSION_JSON } from '../wright/test-data.js'; import createConnector, { LAMA } from './index.js'; const dir = path.dirname(fileURLToPath(import.meta.url)); const meta = localMeta(JSON.parse(readFileSync(path.join(dir, 'meta.json'), 'utf8'))); const connector = createConnector(meta); describe('lama', () => { runFixtureSuite(connector, it, expect); it('uses the shared Rago/Wright parser with its own site and house', async () => { const p = parseSessionPage(asInertiaHtml(SESSION_JSON), LAMA, 'https://www.lamodern.com/auctions/2026/08/design')!; expect(p.site).toBe('https://www.lamodern.com'); expect(p.house).toBe('Los Angeles Modern Auctions'); const out = await connector.normalize({ url: 'x', externalId: 'e', kind: 'sale', engine: 'api', fetchedAt: new Date('2026-09-08T00:00:00Z'), payload: p }); expect(out.length).toBe(2); const s = out.find((r) => 'externalId' in r && r.externalId === '413032')!; if (s.kind !== 'sale') throw new Error('expected sale'); expect(s).toMatchObject({ connectorId: 'lama', auctionHouse: 'Los Angeles Modern Auctions', currency: 'USD', price: 57600, buyerPremiumIncluded: null }); expect(s.sourceUrl).toBe('https://www.lamodern.com/auctions/2026/08/design/100'); expect(s.attributes.identifiers).toEqual({ lama_item_id: '413032' }); }); it('live fixture sales are USD, dated in the past and mapped to art/design slugs', async () => { let sales = 0; for (const name of ['session-1', 'session-2']) { const out = await connector.normalize(loadFixture('lama', name).raw); for (const r of out) { if (r.kind !== 'sale') continue; sales++; expect(r.currency).toBe('USD'); expect(r.saleDate.getTime()).toBeLessThan(Date.now()); expect(['contemporary_art', 'art', 'design_furniture', 'photography', 'movie_posters', 'jewelry', 'antiques', 'glass_crystal', 'porcelain', 'silver', 'clocks', 'books', 'other_watches']).toContain(r.attributes.categorySlug); } } expect(sales).toBeGreaterThan(0); }); });