feat: soporte de contraseña REMOVERVOTOE3 para remover votos individuales y vaciar pruebas

This commit is contained in:
urieljareth
2026-08-13 17:05:59 -06:00
parent 3faae49fa6
commit bd3ead6e74
9 changed files with 323 additions and 75 deletions
+33 -15
View File
@@ -27,12 +27,14 @@ async function runTests() {
const serverProcess = spawn('node', ['dist-server/index.js'], {
env: { ...process.env, PORT: String(PORT), NODE_ENV: 'production' },
stdio: 'pipe',
shell: true,
});
serverProcess.stdout.on('data', (d) => process.stdout.write(`[SERVER] ${d}`));
serverProcess.stderr.on('data', (d) => process.stderr.write(`[SERVER ERR] ${d}`));
serverProcess.on('error', (err) => console.error('[SERVER SPAWN ERROR]', err));
await sleep(2000);
await sleep(3500);
try {
// 2. Health check
@@ -97,33 +99,49 @@ async function runTests() {
if (selfVote.status !== 400) throw new Error('Anti-autovoto no bloqueó la petición');
console.log(' ✅ Autovoto bloqueado correctamente con 400 Bad Request');
// 8. Verificar lista de votos actualizada
console.log('\n7. Test Verificación de Conteo y Persistencia:');
const updatedVotes = await request('/api/votes');
console.log(' Votos registrados:', updatedVotes.data.votes);
if (updatedVotes.data.total < 2) throw new Error('Total de votos incorrecto');
console.log(' ✅ Conteo verificado: Total =', updatedVotes.data.total);
// 8. Test Protección por Contraseña Incorrecta
console.log('\n7. Test Protección de Contraseña (Rechazo con clave errónea):');
const badPassRes = await request('/api/vote/SERVANDO%20PEREZ', {
method: 'DELETE',
headers: { 'x-admin-key': 'CLAVE_INCORRECTA' },
});
console.log(' Bad pass status:', badPassRes.status, 'Data:', badPassRes.data);
if (badPassRes.status !== 401) throw new Error('Contraseña incorrecta no fue rechazada');
console.log(' ✅ Clave incorrecta rechazada con 401 Unauthorized');
// 9. Test Restablecer Voto (Admin DELETE)
console.log('\n8. Test Panel Admin - Restablecer Voto (/api/vote/:voter):');
// 9. Test Remover Voto Individual con Clave "REMOVERVOTOE3"
console.log('\n8. Test Remover Voto Individual con REMOVERVOTOE3:');
const deleteRes = await request('/api/vote/SERVANDO%20PEREZ', {
method: 'DELETE',
headers: { 'x-admin-key': 'RESETEOE3' },
headers: { 'x-admin-key': 'REMOVERVOTOE3' },
});
console.log(' Delete status:', deleteRes.status, 'Data:', deleteRes.data);
if (!deleteRes.ok) throw new Error('Delete vote failed');
console.log(' ✅ Voto de SERVANDO restablecido');
console.log(' ✅ Voto de SERVANDO removido exitosamente con REMOVERVOTOE3');
await sleep(500);
await sleep(400);
// 10. Confirmar estado final
// 10. Test Vaciar Todo con "REMOVERVOTOE3"
console.log('\n9. Test Vaciar Todos los Votos (Reset General) con REMOVERVOTOE3:');
const deleteAllRes = await request('/api/votes', {
method: 'DELETE',
headers: { 'x-admin-key': 'REMOVERVOTOE3' },
});
console.log(' Delete all status:', deleteAllRes.status, 'Data:', deleteAllRes.data);
if (!deleteAllRes.ok) throw new Error('Delete all votes failed');
console.log(' ✅ Todos los votos vaciados correctamente');
await sleep(400);
// 11. Confirmar estado final vacío
const finalVotes = await request('/api/votes');
console.log('\n9. Estado final de votos:', finalVotes.data.votes);
console.log('\n10. Estado final de votos en base de datos:', finalVotes.data.votes);
if (finalVotes.data.total !== 0) throw new Error('Los votos no se vaciaron completamente');
sseReq.destroy();
console.log('\n=========================================');
console.log('🎉 TODAS LAS PRUEBAS EN VIVO PASARON CON ÉXITO (100% FUNCIONAL)');
console.log('🎉 TODAS LAS PRUEBAS DE REMOCIÓN EN VIVO PASARON CON ÉXITO (100% FUNCIONAL)');
console.log('=========================================\n');
} finally {
serverProcess.kill();