- Agregar 46 tests de integración (auth, multi-tenancy, tickets) - Crear estructura organizada tests/integration/ y tests/unit/ - Implementar fixtures completas para testing con BD separada - Agregar conftest_integration.py con setup async - Mover scripts PowerShell de testing a tests/scripts/ - Actualizar pytest.ini con markers y configuración - Crear run_tests.sh script ejecutable para testing - Documentación completa en README_TESTS.md - Fix: Remover opciones obsoletas de TypeScript (importsNotUsedAsValues) Tests implementados: - Authentication: 15 tests (login, refresh, permisos, seguridad) - Multi-tenancy: 13 tests (aislamiento, validaciones, seguridad B2B) - Tickets: 18 tests (CRUD, filtros, permisos por rol) - Unit: 10 tests básicos - Verificación: 8 tests de setup Base de datos de testing: servicemanager_test (separada de producción) Cobertura estimada: ~40% (desde 5%) Próximos pasos: Agregar tests de SLA, attachments, auditoría
143 lines
6.8 KiB
PowerShell
143 lines
6.8 KiB
PowerShell
# Script de Pruebas Manuales - ServiceManagerWeb
|
|
# Fecha: 2026-02-17
|
|
Write-Host "`n========================================" -ForegroundColor Cyan
|
|
Write-Host "PRUEBAS MANUALES - ServiceManagerWeb" -ForegroundColor Cyan
|
|
Write-Host "========================================`n" -ForegroundColor Cyan
|
|
|
|
# PRUEBA 1: Login
|
|
Write-Host "PRUEBA 1: Login y obtener token..." -ForegroundColor Yellow
|
|
|
|
$loginBody = @{
|
|
email = "admin@aduanasoft.com"
|
|
password = "admin123"
|
|
tenant_slug = "aduanasoft-demo"
|
|
} | ConvertTo-Json
|
|
|
|
try {
|
|
$response = Invoke-RestMethod -Uri "http://localhost:8000/v1/auth/login" -Method Post -ContentType "application/json" -Body $loginBody
|
|
$token = $response.access_token
|
|
Write-Host "[OK] Token obtenido exitosamente" -ForegroundColor Green
|
|
$headers = @{ "Authorization" = "Bearer $token" }
|
|
} catch {
|
|
Write-Host "[ERROR] $($_.Exception.Message)" -ForegroundColor Red
|
|
exit
|
|
}
|
|
|
|
# PRUEBA 2: Listar categorias
|
|
Write-Host "`nPRUEBA 2: Listar categorias..." -ForegroundColor Yellow
|
|
|
|
try {
|
|
$categories = Invoke-RestMethod -Uri "http://localhost:8000/v1/categories/" -Method Get -Headers $headers
|
|
Write-Host "[OK] Categorias encontradas: $($categories.Count)" -ForegroundColor Green
|
|
$categoryId = $categories[0].id
|
|
Write-Host "Usaremos: $($categories[0].name) (ID: $categoryId)" -ForegroundColor Gray
|
|
} catch {
|
|
Write-Host "[ERROR] $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
|
|
# PRUEBA 3: Crear ticket con SLA
|
|
Write-Host "`nPRUEBA 3: Crear ticket con SLA automatico..." -ForegroundColor Yellow
|
|
|
|
$ticketBody = @{
|
|
subject = "Prueba SLA $(Get-Date -Format 'HH:mm:ss')"
|
|
description = "Ticket de prueba para verificar calculo automatico de SLA"
|
|
category_id = $categoryId
|
|
priority = "HIGH"
|
|
} | ConvertTo-Json
|
|
|
|
try {
|
|
$newTicket = Invoke-RestMethod -Uri "http://localhost:8000/v1/tickets/" -Method Post -ContentType "application/json" -Headers $headers -Body $ticketBody
|
|
Write-Host "[OK] Ticket creado: $($newTicket.ticket_number)" -ForegroundColor Green
|
|
$ticketId = $newTicket.id
|
|
Write-Host "ID: $ticketId" -ForegroundColor Gray
|
|
} catch {
|
|
Write-Host "[ERROR] $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
|
|
# PRUEBA 4: Verificar ticket en BD
|
|
Write-Host "`nPRUEBA 4: Verificar ticket en base de datos..." -ForegroundColor Yellow
|
|
Start-Sleep -Seconds 2
|
|
|
|
Write-Host "Consultando BD..." -ForegroundColor Gray
|
|
docker exec servicemanager-db psql -U servicemanager -d servicemanager -c "SELECT ticket_number, created_at, sla_response_due, sla_resolution_due FROM tickets WHERE id = '$ticketId'::uuid;"
|
|
|
|
# PRUEBA 5: Verificar auditoria del ticket
|
|
Write-Host "`nPRUEBA 5: Verificar auditoria del ticket..." -ForegroundColor Yellow
|
|
|
|
Write-Host "Consultando audit logs..." -ForegroundColor Gray
|
|
docker exec servicemanager-db psql -U servicemanager -d servicemanager -c "SELECT action, resource_type, created_at FROM audit_logs WHERE resource_id = '$ticketId'::uuid;"
|
|
|
|
# PRUEBA 6: Crear categoria nueva
|
|
Write-Host "`nPRUEBA 6: Crear nueva categoria (probar auditoria)..." -ForegroundColor Yellow
|
|
|
|
$newCategoryBody = @{
|
|
name = "Prueba Auditoria $(Get-Date -Format 'HH:mm:ss')"
|
|
description = "Categoria de prueba para verificar auditoria"
|
|
sla_response_hours = 6
|
|
sla_resolution_hours = 48
|
|
is_active = $true
|
|
} | ConvertTo-Json
|
|
|
|
try {
|
|
$newCategory = Invoke-RestMethod -Uri "http://localhost:8000/v1/categories/" -Method Post -ContentType "application/json" -Headers $headers -Body $newCategoryBody
|
|
Write-Host "[OK] Categoria creada: $($newCategory.name)" -ForegroundColor Green
|
|
$newCategoryId = $newCategory.id
|
|
Write-Host "ID: $newCategoryId" -ForegroundColor Gray
|
|
} catch {
|
|
Write-Host "[ERROR] $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
|
|
# PRUEBA 7: Verificar auditoria de CREATE
|
|
Write-Host "`nPRUEBA 7: Verificar auditoria de categoria CREATE..." -ForegroundColor Yellow
|
|
Start-Sleep -Seconds 2
|
|
|
|
Write-Host "Consultando audit logs..." -ForegroundColor Gray
|
|
docker exec servicemanager-db psql -U servicemanager -d servicemanager -c "SELECT action, resource_type, created_at FROM audit_logs WHERE resource_id = '$newCategoryId'::uuid AND action = 'category.create';"
|
|
|
|
# PRUEBA 8: Actualizar categoria
|
|
Write-Host "`nPRUEBA 8: Actualizar categoria (probar auditoria UPDATE)..." -ForegroundColor Yellow
|
|
|
|
$updateBody = @{
|
|
sla_response_hours = 12
|
|
sla_resolution_hours = 72
|
|
} | ConvertTo-Json
|
|
|
|
try {
|
|
$updated = Invoke-RestMethod -Uri "http://localhost:8000/v1/categories/$newCategoryId" -Method Put -ContentType "application/json" -Headers $headers -Body $updateBody
|
|
Write-Host "[OK] Categoria actualizada" -ForegroundColor Green
|
|
Write-Host "Nuevo Response: $($updated.sla_response_hours)h, Resolution: $($updated.sla_resolution_hours)h" -ForegroundColor Gray
|
|
} catch {
|
|
Write-Host "[ERROR] $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
|
|
# PRUEBA 9: Verificar auditoria de UPDATE
|
|
Write-Host "`nPRUEBA 9: Verificar auditoria de categoria UPDATE..." -ForegroundColor Yellow
|
|
Start-Sleep -Seconds 2
|
|
|
|
Write-Host "Consultando audit logs..." -ForegroundColor Gray
|
|
docker exec servicemanager-db psql -U servicemanager -d servicemanager -c "SELECT action, created_at FROM audit_logs WHERE resource_id = '$newCategoryId'::uuid AND action = 'category.update';"
|
|
|
|
# PRUEBA 10: Resumen final
|
|
Write-Host "`n========================================" -ForegroundColor Cyan
|
|
Write-Host "RESUMEN FINAL" -ForegroundColor Cyan
|
|
Write-Host "========================================`n" -ForegroundColor Cyan
|
|
|
|
$totalTickets = docker exec servicemanager-db psql -U servicemanager -d servicemanager -t -c "SELECT COUNT(*) FROM tickets;"
|
|
$ticketsWithSLA = docker exec servicemanager-db psql -U servicemanager -d servicemanager -t -c "SELECT COUNT(*) FROM tickets WHERE sla_response_due IS NOT NULL;"
|
|
$totalAudits = docker exec servicemanager-db psql -U servicemanager -d servicemanager -t -c "SELECT COUNT(*) FROM audit_logs;"
|
|
$categoryAudits = docker exec servicemanager-db psql -U servicemanager -d servicemanager -t -c "SELECT COUNT(*) FROM audit_logs WHERE action LIKE 'category.%';"
|
|
|
|
Write-Host "Tickets totales: $($totalTickets.Trim())"
|
|
Write-Host "Tickets con SLA calculado: $($ticketsWithSLA.Trim())" -ForegroundColor Green
|
|
Write-Host "Audit logs totales: $($totalAudits.Trim())"
|
|
Write-Host "Audit logs de categorias: $($categoryAudits.Trim())" -ForegroundColor Green
|
|
|
|
Write-Host "`n========================================" -ForegroundColor Green
|
|
Write-Host "VERIFICACIONES COMPLETADAS" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host "[OK] Calculo automatico de SLA" -ForegroundColor Green
|
|
Write-Host "[OK] Auditoria de tickets" -ForegroundColor Green
|
|
Write-Host "[OK] Auditoria de categorias (CREATE)" -ForegroundColor Green
|
|
Write-Host "[OK] Auditoria de categorias (UPDATE)" -ForegroundColor Green
|
|
Write-Host "`nRevisa los resultados arriba para confirmar que todo funciona.`n" -ForegroundColor White
|