feat: amazon scraper with playwright + html parser tests
This commit is contained in:
7563
tests/fixtures/amazon-ps5.html
vendored
Normal file
7563
tests/fixtures/amazon-ps5.html
vendored
Normal file
File diff suppressed because one or more lines are too long
23
tests/scrapers/amazon.test.ts
Normal file
23
tests/scrapers/amazon.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { parseAmazonHtml } from '@/lib/scrapers/amazon'
|
||||
|
||||
const fixture = readFileSync(join(__dirname, '../fixtures/amazon-ps5.html'), 'utf-8')
|
||||
|
||||
describe('parseAmazonHtml', () => {
|
||||
it('extracts price, name, image', () => {
|
||||
const r = parseAmazonHtml(fixture)
|
||||
expect(r.price).toBeGreaterThan(0)
|
||||
expect(r.currency).toBe('EUR')
|
||||
expect(r.name).toBeTruthy()
|
||||
expect(r.imageUrl).toMatch(/^https?:\/\//)
|
||||
})
|
||||
|
||||
it('detects captcha page', () => {
|
||||
const captchaHtml = '<html><body><form action="/errors/validateCaptcha"></form></body></html>'
|
||||
const r = parseAmazonHtml(captchaHtml)
|
||||
expect(r.price).toBeNull()
|
||||
expect(r.error).toBe('captcha')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user