// This is a test script for the news API // Run with: node scripts/tests/test-news-api.js import fetch from 'node-fetch'; const BASE_URL = 'http://localhost:3000/api/news'; const API_KEY = process.env.NEXT_PUBLIC_AI_RESOURCE_PRO_API_KEY || ''; // Only needed for write operations // No longer exit if API key is not set, since we're only doing read operations if (!API_KEY) { console.warn('WARNING: NEXT_PUBLIC_AI_RESOURCE_PRO_API_KEY environment variable is not set. Only read operations will work.'); } async function testGetAllNews() { console.log('\n🧪 Testing GET all news...'); try { const response = await fetch(BASE_URL); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(`✅ SUCCESS: Retrieved ${data.length} news articles`); console.log('Sample news article:', data[0] ? { id: data[0].id, title: data[0].title, url: data[0].url } : 'No news articles found'); return data; } catch (error) { console.error('❌ ERROR:', error.message); return null; } } async function testCreateNews() { console.log('\n🧪 DISABLED: Test for creating news is disabled to prevent test data in production'); return null; // Disabled to prevent test data in production } async function testUpdateNews(id) { console.log('\n🧪 DISABLED: Test for updating news is disabled to prevent test data in production'); return null; // Disabled to prevent test data in production } async function testDeleteNews(id) { console.log('\n🧪 DISABLED: Test for deleting news is disabled to prevent test data in production'); return false; // Disabled to prevent test data in production } async function runTests() { console.log('📝 Starting News API tests (READ ONLY)...'); // Test GET all news await testGetAllNews(); // Skip tests that modify data console.log('\n⚠️ Tests for creating, updating, and deleting news are disabled to prevent test data in production'); console.log('\n🎯 All tests completed!'); } // Run the tests runTests();