import { describe, it, expect, vi, beforeEach } from 'vitest' import { readFileSync } from 'node:fs' import { join } from 'node:path' import { geizhalsScraper } from '@/lib/scrapers/geizhals' const fixture = readFileSync(join(__dirname, '../fixtures/geizhals-gpu.html'), 'utf-8') beforeEach(() => { global.fetch = vi.fn().mockResolvedValue({ ok: true, status: 200, text: async () => fixture, }) as unknown as typeof fetch }) describe('geizhalsScraper', () => { it('extracts price and name', async () => { const r = await geizhalsScraper.scrape('https://geizhals.de/test') expect(r.price).toBeGreaterThan(0) expect(r.currency).toBe('EUR') expect(r.name).toBeTruthy() }) it('returns error on HTTP failure', async () => { global.fetch = vi.fn().mockResolvedValue({ ok: false, status: 503, text: async () => '', }) as unknown as typeof fetch const r = await geizhalsScraper.scrape('https://geizhals.de/test') expect(r.price).toBeNull() expect(r.error).toMatch(/HTTP 503/) }) })