import { describe, expect, it } from 'vitest'; import metaJson from './meta.json' with { type: 'json' }; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import { localMeta } from '../_lib/local-meta.js'; import createConnector, { categoryFor, trimListing } from './index.js'; const connector = createConnector(localMeta(metaJson)); describe('reverb', () => { runFixtureSuite(connector, it, expect); it('maps categories and trims API listings', async () => { expect(categoryFor(['Home Audio / Amplifiers'])).toBe('audio_equipment'); expect(categoryFor(['Electric Guitars / Solid Body'])).toBe('musical_instruments'); const l = trimListing({ id: 1, make: 'Fender', model: 'Stratocaster', year: '1965', title: 'Fender Stratocaster 1965', condition: { display_name: 'Excellent' }, price: { amount: '18184.16', currency: 'USD' }, listing_currency: 'EUR', categories: [{ full_name: 'Electric Guitars / Solid Body' }], state: { slug: 'live' }, _links: { web: { href: 'https://reverb.com/item/1-x' } }, photos: [{ _links: { large_crop: { href: 'https://img/1.jpg' } } }] }); expect(l).toMatchObject({ id: 1, make: 'Fender', year: '1965', condition: 'Excellent', price: 18184.16, currency: 'USD', listingCurrency: 'EUR', photo: 'https://img/1.jpg' }); const fx = loadFixture('reverb', 'stratocaster-p1'); const out = await connector.normalize(fx.raw); expect(out.length).toBeGreaterThan(0); for (const r of out) { if (r.kind !== 'listing') throw new Error('expected listing'); expect(['musical_instruments', 'audio_equipment']).toContain(r.attributes.categorySlug); expect(r.attributes.identifiers.reverb_listing_id).toMatch(/^\d+$/); expect(r.price).toBeGreaterThan(0); expect(r.currency).toBe('USD'); expect(r.sourceUrl).toMatch(/reverb\.com/); } }); });