60 lines
2.1 KiB
JavaScript
60 lines
2.1 KiB
JavaScript
import { beforeAll, describe, expect, it } from 'vitest';
|
||
import { scraperPrime } from '../src/index.js';
|
||
import { parsePrimeHtml } from '../src/parser.js';
|
||
|
||
const TEST_URL = 'https://www.primevideo.com/-/tr/detail/0NHIN3TGAI9L7VZ45RS52RHUPL/ref=share_ios_movie';
|
||
const UA =
|
||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36';
|
||
|
||
describe('parsePrimeHtml (örnek HTML)', () => {
|
||
it('boş veya geçersiz HTML için boş obje döner', () => {
|
||
expect(parsePrimeHtml('')).toEqual({});
|
||
expect(parsePrimeHtml(null)).toEqual({});
|
||
});
|
||
|
||
it('meta etiketlerinden başlık ve yıl çıkarır', () => {
|
||
const html = `
|
||
<html>
|
||
<head>
|
||
<meta property="og:title" content="Little Women | Prime Video">
|
||
<meta name="description" content="2020 yapımı bir film | Prime Video">
|
||
</head>
|
||
</html>
|
||
`;
|
||
const meta = parsePrimeHtml(html);
|
||
expect(meta.name).toBe('Little Women');
|
||
});
|
||
|
||
it('thumbnail ve info alanını çıkarır', () => {
|
||
const html = `
|
||
<meta property="og:image" content="https://m.media-amazon.com/images/S/pv-target-images/test.jpg">
|
||
<meta name="description" content="Louisa May Alcott'ın hikayesi | Prime Video">
|
||
`;
|
||
const meta = parsePrimeHtml(html);
|
||
expect(meta.thumbnail).toBe('https://m.media-amazon.com/images/S/pv-target-images/test.jpg');
|
||
expect(meta.info).toBe("Louisa May Alcott'ın hikayesi");
|
||
});
|
||
|
||
it('tür bilgisini normalize eder', () => {
|
||
const html = `
|
||
<meta itemprop="genre" content="Comedy">
|
||
`;
|
||
const meta = parsePrimeHtml(html);
|
||
expect(meta.genre).toBe('Komedi');
|
||
});
|
||
});
|
||
|
||
describe('scraperPrime (canlı istek)', () => {
|
||
it(
|
||
'normalize edilmiş url, id ve meta bilgilerini döner',
|
||
async () => {
|
||
const meta = await scraperPrime(TEST_URL, { headless: false, userAgent: UA });
|
||
expect(meta.url).toBe('https://www.primevideo.com/detail/0NHIN3TGAI9L7VZ45RS52RHUPL');
|
||
expect(meta.id).toBe('0NHIN3TGAI9L7VZ45RS52RHUPL');
|
||
expect(meta.name).toBeTruthy();
|
||
expect(meta.year).toMatch(/\d{4}/);
|
||
},
|
||
20000
|
||
);
|
||
});
|