24 lines
794 B
TypeScript
24 lines
794 B
TypeScript
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')
|
|
})
|
|
})
|