import { describe, it, expect, vi, beforeEach } from 'vitest' import { readFileSync } from 'node:fs' import { join } from 'node:path' import { idealoScraper } from '@/lib/scrapers/idealo' const fixture = readFileSync(join(__dirname, '../fixtures/idealo-headphones.html'), 'utf-8') beforeEach(() => { global.fetch = vi.fn().mockResolvedValue({ ok: true, status: 200, text: async () => fixture, }) as unknown as typeof fetch }) describe('idealoScraper', () => { it('extracts price and name', async () => { const r = await idealoScraper.scrape('https://www.idealo.de/foo') expect(r.price).toBeGreaterThan(0) expect(r.currency).toBe('EUR') expect(r.name).toBeTruthy() }) it('flags cloudflare challenge', async () => { global.fetch = vi.fn().mockResolvedValue({ ok: false, status: 403, text: async () => 'Cloudflare', }) as unknown as typeof fetch const r = await idealoScraper.scrape('https://www.idealo.de/foo') expect(r.price).toBeNull() expect(r.error).toMatch(/403|cloudflare/i) }) })