67 lines
1.7 KiB
JavaScript
67 lines
1.7 KiB
JavaScript
|
|
/**
|
|||
|
|
* 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();
|
|||
|
|
|