Files
metascraper/tests/netflix.test.js

95 lines
2.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
);
});