25 lines
870 B
TypeScript
25 lines
870 B
TypeScript
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)
|
|
})
|
|
})
|