90 lines
2.4 KiB
JavaScript
90 lines
2.4 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';
|
||
|
||
let liveHtml = '';
|
||
|
||
beforeAll(async () => {
|
||
const res = await fetch(TEST_URL, {
|
||
headers: {
|
||
'User-Agent': UA,
|
||
Accept: 'text/html,application/xhtml+xml'
|
||
}
|
||
});
|
||
|
||
if (!res.ok) {
|
||
throw new Error(`Live fetch başarısız: ${res.status}`);
|
||
}
|
||
|
||
liveHtml = await res.text();
|
||
}, 20000);
|
||
|
||
describe('parsePrimeHtml (canlı sayfa)', () => {
|
||
it(
|
||
'static HTML’den en az isim ve yıl bilgisini okur',
|
||
() => {
|
||
const meta = parsePrimeHtml(liveHtml);
|
||
expect(meta.name).toBeTruthy();
|
||
expect(String(meta.name).toLowerCase()).toContain('women');
|
||
expect(String(meta.year)).toMatch(/\d{4}/);
|
||
},
|
||
20000
|
||
);
|
||
|
||
it(
|
||
'thumbnail URL’sini çıkarır',
|
||
() => {
|
||
const meta = parsePrimeHtml(liveHtml);
|
||
if (meta.thumbnail) {
|
||
expect(meta.thumbnail).toContain('m.media-amazon.com/images/S/pv-target-images');
|
||
}
|
||
},
|
||
20000
|
||
);
|
||
|
||
it(
|
||
'film/dizi açıklamasını (info) çıkarır',
|
||
() => {
|
||
const meta = parsePrimeHtml(liveHtml);
|
||
if (meta.info) {
|
||
expect(meta.info).toBeTruthy();
|
||
expect(meta.info).not.toContain('Prime Video');
|
||
expect(meta.info).not.toContain('Amazon');
|
||
}
|
||
},
|
||
20000
|
||
);
|
||
|
||
it(
|
||
'film/dizi türünü (genre) çıkarır',
|
||
() => {
|
||
const meta = parsePrimeHtml(liveHtml);
|
||
if (meta.genre) {
|
||
expect(meta.genre).toBeTruthy();
|
||
expect(typeof meta.genre).toBe('string');
|
||
}
|
||
},
|
||
20000
|
||
);
|
||
});
|
||
|
||
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(String(meta.name).toLowerCase()).toContain('women');
|
||
expect(meta.year).toMatch(/\d{4}/);
|
||
},
|
||
20000
|
||
);
|
||
});
|