import * as fs from 'fs'; import * as path from 'path'; const testNewsApiPath = path.join(process.cwd(), 'scripts', 'tests', 'test-news-api.js'); function main() { console.log(`Modifying ${testNewsApiPath} to prevent it from creating test news items...`); if (!fs.existsSync(testNewsApiPath)) { console.error(`File not found: ${testNewsApiPath}`); process.exit(1); } // Read the file let content = fs.readFileSync(testNewsApiPath, 'utf8'); // Create a backup const backupPath = `${testNewsApiPath}.bak`; fs.writeFileSync(backupPath, content); console.log(`Created backup at ${backupPath}`); // Modify the file to disable the test functions that create, update, and delete news items content = content.replace( /async function testCreateNews\(\) {[\s\S]*?return data;\n } catch[\s\S]*?return null;\n }/, `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 }` ); content = content.replace( /async function testUpdateNews\(id\) {[\s\S]*?return data;\n } catch[\s\S]*?return null;\n }/, `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 }` ); content = content.replace( /async function testDeleteNews\(id\) {[\s\S]*?return true;\n } catch[\s\S]*?return false;\n }/, `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 }` ); // Modify the runTests function to only test GET content = content.replace( /async function runTests\(\) {[\s\S]*?console\.log\('\\n🎯 All tests completed!'\);/, `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!');` ); // Write the modified content back to the file fs.writeFileSync(testNewsApiPath, content); console.log(`Modified ${testNewsApiPath} to prevent it from creating test news items`); } main();