NuvioStreaming/trailer-server/test.js
2025-09-13 17:02:11 +05:30

87 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const fetch = require('node-fetch');
const SERVER_URL = 'http://localhost:3001';
async function testServer() {
console.log('🧪 Testing Trailer Server...\n');
// Test 1: Health check
console.log('1⃣ Testing health endpoint...');
try {
const healthResponse = await fetch(`${SERVER_URL}/health`);
const healthData = await healthResponse.json();
console.log('✅ Health check passed:', healthData.status);
console.log('📊 Cache stats:', healthData.cache);
} catch (error) {
console.log('❌ Health check failed:', error.message);
}
console.log('\n');
// Test 2: Trailer endpoint with sample YouTube URL
console.log('2⃣ Testing trailer endpoint...');
const testTrailer = {
youtube_url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', // Rick Roll for testing
title: 'Test Movie',
year: '2023'
};
try {
const trailerResponse = await fetch(
`${SERVER_URL}/trailer?${new URLSearchParams(testTrailer)}`
);
if (trailerResponse.ok) {
const trailerData = await trailerResponse.json();
console.log('✅ Trailer fetch successful!');
console.log('📹 Title:', trailerData.title);
console.log('📅 Year:', trailerData.year);
console.log('🔗 URL:', trailerData.url.substring(0, 50) + '...');
console.log('⏰ Timestamp:', trailerData.timestamp);
} else {
const errorData = await trailerResponse.json();
console.log('❌ Trailer fetch failed:', errorData.error);
}
} catch (error) {
console.log('❌ Trailer test failed:', error.message);
}
console.log('\n');
// Test 3: Cache endpoint
console.log('3⃣ Testing cache endpoint...');
try {
const cacheResponse = await fetch(`${SERVER_URL}/cache`);
const cacheData = await cacheResponse.json();
console.log('✅ Cache endpoint working');
console.log('📦 Cached items:', cacheData.count);
} catch (error) {
console.log('❌ Cache test failed:', error.message);
}
console.log('\n');
// Test 4: Rate limiting
console.log('4⃣ Testing rate limiting...');
try {
const promises = Array(12).fill().map(() =>
fetch(`${SERVER_URL}/trailer?youtube_url=https://www.youtube.com/watch?v=dQw4w9WgXcQ&title=Test&year=2023`)
);
const responses = await Promise.all(promises);
const rateLimited = responses.some(r => r.status === 429);
if (rateLimited) {
console.log('✅ Rate limiting working correctly');
} else {
console.log('⚠️ Rate limiting may not be working');
}
} catch (error) {
console.log('❌ Rate limiting test failed:', error.message);
}
console.log('\n🏁 Testing complete!');
}
// Run tests
testServer().catch(console.error);