codigo0/backend/scripts/test-content-endpoint.js
planetazuzu 0201f16cf4
Some checks are pending
Auto Deploy to Server / deploy (push) Waiting to run
Update lab configuration 2026-03-22
2026-03-22 22:50:29 +01:00

67 lines
1.7 KiB
JavaScript
Executable file
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.

/**
* Script para probar el endpoint de contenido
*/
import axios from 'axios';
const API_URL = 'http://localhost:3000';
async function testContentEndpoint() {
try {
console.log('🧪 Probando endpoint de contenido...\n');
// 1. Login para obtener token
console.log('1⃣ Haciendo login...');
const loginResponse = await axios.post(`${API_URL}/api/auth/login`, {
email: 'admin@emerges-tes.local',
password: 'Admin123!'
});
const token = loginResponse.data.token;
console.log(' ✅ Login exitoso\n');
// 2. Obtener contenido
console.log('2⃣ Obteniendo contenido...');
const contentResponse = await axios.get(`${API_URL}/api/content`, {
headers: {
'Authorization': `Bearer ${token}`
},
params: {
page: 1,
pageSize: 20
}
});
const { items, total } = contentResponse.data;
console.log(` ✅ Encontrados ${total} items\n`);
console.log('📋 Contenido encontrado:\n');
// Agrupar por tipo
const byType = {};
items.forEach(item => {
if (!byType[item.type]) {
byType[item.type] = [];
}
byType[item.type].push(item);
});
Object.keys(byType).forEach(type => {
console.log(` ${type.toUpperCase()} (${byType[type].length}):`);
byType[type].forEach(item => {
console.log(` - ${item.title} (${item.status})`);
});
console.log('');
});
console.log('✅ Test completado exitosamente!');
} catch (error) {
console.error('❌ Error:', error.response?.data || error.message);
process.exit(1);
}
}
testContentEndpoint();