feat: scraper registry + adapter interface
This commit is contained in:
24
tests/scrapers/registry.test.ts
Normal file
24
tests/scrapers/registry.test.ts
Normal 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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user