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, { parseSearchPage } from './index.js';
const connector = createConnector(localMeta(metaJson));
describe('hifishark', () => {
runFixtureSuite(connector, it, expect);
it('parses server-rendered for-sale rows', async () => {
const html = `
marantz 2270
Subito€850Aug 2, 2026 `;
const p = parseSearchPage(html, 'u', 'Marantz 2270');
expect(p.forSaleCount).toBe(60);
expect(p.rows[0]).toMatchObject({ id: '152_abc', priceText: '€850', marketplace: 'Subito', countryIso: 'IT', firstSeen: 'Aug 2, 2026', image: 'https://img/x.jpg' });
const fx = loadFixture('hifishark', 'marantz-2270');
const out = await connector.normalize(fx.raw);
expect(out.length).toBeGreaterThan(0);
const l = out[0]!;
if (l.kind !== 'listing') throw new Error('expected listing');
expect(l.attributes).toMatchObject({ categorySlug: 'audio_equipment', brand: 'Marantz', model: '2270', name: 'Marantz 2270' });
expect(out.some((r) => r.kind === 'listing' && r.price && r.currency)).toBe(true);
});
});