feat: scraper registry + adapter interface

This commit is contained in:
2026-05-25 13:55:07 +00:00
parent 91dea772aa
commit 890fdecf24
3 changed files with 58 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { describe, it, expect, vi } from 'vitest'
import { scrapeUrl, registerScraperForTest, resetScrapersForTest } from '@/lib/scrapers'
import type { PriceScraper } from '@/lib/scrapers/types'
describe('scrapeUrl', () => {
it('dispatches to matching shop scraper', async () => {
const fake: PriceScraper = {
shop: 'geizhals',
scrape: vi.fn().mockResolvedValue({
price: 42, currency: 'EUR', availability: 'in_stock', name: 'X',
}),
}
resetScrapersForTest()
registerScraperForTest(fake)
const result = await scrapeUrl('https://geizhals.de/foo')
expect(result.price).toBe(42)
expect(fake.scrape).toHaveBeenCalledWith('https://geizhals.de/foo')
})
it('throws on unknown shop', async () => {
resetScrapersForTest()
await expect(scrapeUrl('https://example.com')).rejects.toThrow(/unsupported/i)
})
})