amazon prime scrap özelliği eklendi

This commit is contained in:
2025-11-23 16:09:39 +03:00
parent 46d75b64d5
commit fefa6627e9
6 changed files with 988 additions and 28 deletions

94
tests/netflix.test.js Normal file
View File

@@ -0,0 +1,94 @@
import { beforeAll, describe, expect, it } from 'vitest';
import { scraperNetflix } from '../src/index.js';
import { parseNetflixHtml } from '../src/parser.js';
const TEST_URL = 'https://www.netflix.com/title/80189685';
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('parseNetflixHtml (canlı sayfa)', () => {
it(
'static HTMLden en az isim ve yıl bilgisini okur',
() => {
const meta = parseNetflixHtml(liveHtml);
expect(meta.name).toBeTruthy();
expect(String(meta.name).toLowerCase()).toContain('witcher');
expect(meta.year).toMatch(/\d{4}/);
},
20000
);
it(
'thumbnail URLsini çıkarır',
() => {
const meta = parseNetflixHtml(liveHtml);
if (meta.thumbnail) {
expect(meta.thumbnail).toContain('nflxso.net');
}
// Thumbnail olmayabilir ama test geçmeli
},
20000
);
it(
'film/dizi açıklamasını (info) çıkarır',
() => {
const meta = parseNetflixHtml(liveHtml);
if (meta.info) {
expect(meta.info).toBeTruthy();
expect(meta.info).not.toContain('Netflix');
expect(meta.info).not.toContain('Fragmanları izleyin');
}
// Info olmayabilir ama varsa boş olmamalı
},
20000
);
it(
'film/dizi türünü (genre) çıkarır',
() => {
const meta = parseNetflixHtml(liveHtml);
if (meta.genre) {
expect(meta.genre).toBeTruthy();
expect(typeof meta.genre).toBe('string');
// Genre mapping test: 'Action' → 'Aksiyon'
['Aksiyon', 'Dram', 'Komedi', 'Fantastik'].includes(meta.genre) ||
['Action', 'Drama', 'Comedy', 'Fantasy'].includes(meta.genre);
}
// Genre olmayabilir ama varsa geçerli bir değer olmalı
},
20000
);
});
describe('scraperNetflix (canlı istek)', () => {
it(
'normalize edilmiş url, id ve meta bilgilerini döner',
async () => {
const meta = await scraperNetflix(TEST_URL, { headless: false, userAgent: UA });
expect(meta.url).toBe('https://www.netflix.com/title/80189685');
expect(meta.id).toBe('80189685');
expect(meta.name).toBeTruthy();
expect(String(meta.name).toLowerCase()).toContain('witcher');
expect(meta.year).toMatch(/\d{4}/);
},
20000
);
});