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, { auctionSaleDate, discoverRealizedSlugs, imageUrl, parseAuctionPageData } from './index.js';
const connector = createConnector(ConnectorMetaSchema.parse(metaJson));
describe('gooding', () => {
runFixtureSuite(connector, it, expect);
it('maps realized lots to auction sales in the auction currency', async () => {
const fx = loadFixture('gooding', 'realized-auction');
const out = await connector.normalize(fx.raw);
expect(out.length).toBeGreaterThan(0);
for (const r of out) {
if (r.kind !== 'sale') throw new Error('expected sale');
expect(['USD', 'GBP', 'EUR']).toContain(r.currency);
expect(r.saleType).toBe('auction');
expect(r.buyerPremiumIncluded).toBeNull();
expect(['automobiles', 'motorcycles', 'automotive_memorabilia']).toContain(r.attributes.categorySlug);
expect(r.attributes.identifiers.gooding_lot).toBeTruthy();
expect(r.sourceUrl).toMatch(/^https:\/\/www\.goodingco\.com\/lot\//);
expect(r.auctionHouse).toBe('Gooding & Company');
}
});
it('parses page-data JSON, dates and images', () => {
const json = { result: { data: { contentfulWebPageAuction: { title: 'x', auction: { name: 'Pebble Beach Auctions', currency: 'USD', sellThroughRate: 0.94, subEvents: [{ __typename: 'ContentfulSubEventViewing' }, { __typename: 'ContentfulSubEventAuction', startDate: '2026-08-14T16:00-08:00', endDate: '2026-08-14T21:00-08:00' }, { __typename: 'ContentfulSubEventAuction', startDate: '2026-08-15T11:00-08:00', endDate: '2026-08-15T16:00-08:00' }], lot: [{ slug: '1961-jaguar-xk150', lotNumber: 116, salePrice: 72800, privateSalesPrice: false, item: { __typename: 'ContentfulVehicle', title: '1961 Jaguar XK150 3.8-Litre Fixed Head Coupe', modelYear: 1961, make: { name: 'Jaguar' }, model: 'XK150', cloudinaryImagesCombined: [{ public_id: 'Prod/PB26 Pebble/1961_Jaguar' }] } }, { slug: 'unsold', lotNumber: 1, salePrice: null, item: { title: 'Unsold car' } }] } } } } };
const p = parseAuctionPageData(json, 'pebble-beach-auctions-2026')!;
expect(p.saleDate).toBe('2026-08-15T00:00:00.000Z');
expect(p.lots).toHaveLength(2);
expect(p.lots[0]!.image).toBe('https://res.cloudinary.com/goodingco/image/upload/c_fill,w_1200/Prod/PB26%20Pebble/1961_Jaguar');
expect(auctionSaleDate(undefined)).toBeNull();
expect(imageUrl(null)).toBeNull();
expect(discoverRealizedSlugs('xy')).toEqual(['pebble-beach-auctions-2026', 'amelia-island-auctions-2026']);
});
});