feat: idealo scraper
This commit is contained in:
2611
tests/fixtures/idealo-headphones.html
vendored
Normal file
2611
tests/fixtures/idealo-headphones.html
vendored
Normal file
File diff suppressed because one or more lines are too long
30
tests/scrapers/idealo.test.ts
Normal file
30
tests/scrapers/idealo.test.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
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 () => '<html>Cloudflare</html>',
|
||||
}) 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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user