- 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
102 lines
3.5 KiB
PowerShell
102 lines
3.5 KiB
PowerShell
# Script de prueba para actualización de tenants
|
|
Write-Host "`n=== TEST: Tenant Update Endpoint ===" -ForegroundColor Cyan
|
|
|
|
# 1. Login como admin
|
|
Write-Host "`n1. Login como admin..." -ForegroundColor Yellow
|
|
$loginBody = @{
|
|
email = "admin@aduanasoft.com"
|
|
password = "admin123"
|
|
tenant_slug = "aduanasoft"
|
|
} | ConvertTo-Json
|
|
|
|
$loginResponse = Invoke-RestMethod -Uri "http://localhost:8000/v1/auth/login" `
|
|
-Method POST `
|
|
-ContentType "application/json" `
|
|
-Body $loginBody
|
|
|
|
$token = $loginResponse.access_token
|
|
Write-Host "OK - Token obtenido" -ForegroundColor Green
|
|
|
|
# 2. Listar tenants para obtener ID
|
|
Write-Host "`n2. Obteniendo lista de tenants..." -ForegroundColor Yellow
|
|
$headers = @{
|
|
"Authorization" = "Bearer $token"
|
|
}
|
|
|
|
$tenants = Invoke-RestMethod -Uri "http://localhost:8000/v1/tenants/" `
|
|
-Method GET `
|
|
-Headers $headers
|
|
|
|
$firstTenant = $tenants[0]
|
|
|
|
Write-Host "OK - Tenant encontrado: $($firstTenant.name) (ID: $($firstTenant.id))" -ForegroundColor Green
|
|
Write-Host " Status actual: $($firstTenant.status)" -ForegroundColor Cyan
|
|
|
|
# 3. Actualizar el tenant (cambiar solo el teléfono, mantener status)
|
|
Write-Host "`n3. Actualizando tenant (test de status)..." -ForegroundColor Yellow
|
|
|
|
$updateBody = @{
|
|
contact_phone = "+52-555-TEST-UPDATE"
|
|
status = "active" # Probamos que funcione con el enum
|
|
} | ConvertTo-Json
|
|
|
|
try {
|
|
$updatedTenant = Invoke-RestMethod -Uri "http://localhost:8000/v1/tenants/$($firstTenant.id)" `
|
|
-Method PUT `
|
|
-ContentType "application/json" `
|
|
-Headers $headers `
|
|
-Body $updateBody
|
|
|
|
Write-Host "OK - Tenant actualizado correctamente" -ForegroundColor Green
|
|
Write-Host " Telefono: $($updatedTenant.contact_phone)" -ForegroundColor Cyan
|
|
Write-Host " Status: $($updatedTenant.status)" -ForegroundColor Cyan
|
|
} catch {
|
|
Write-Host "ERROR al actualizar tenant:" -ForegroundColor Red
|
|
Write-Host $_.Exception.Message -ForegroundColor Red
|
|
Write-Host $_.ErrorDetails.Message -ForegroundColor Yellow
|
|
exit 1
|
|
}
|
|
|
|
# 4. Verificar que el cambio persiste
|
|
Write-Host "`n4. Verificando persistencia..." -ForegroundColor Yellow
|
|
$verifiedTenant = Invoke-RestMethod -Uri "http://localhost:8000/v1/tenants/$($firstTenant.id)" `
|
|
-Method GET `
|
|
-Headers $headers
|
|
|
|
if ($verifiedTenant.contact_phone -eq "+52-555-TEST-UPDATE") {
|
|
Write-Host "OK - Cambios guardados correctamente en BD" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "ERROR - Los cambios NO se guardaron" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# 5. Test de cambio de status (ACTIVE -> SUSPENDED -> ACTIVE)
|
|
Write-Host "`n5. Probando cambio de status..." -ForegroundColor Yellow
|
|
|
|
# Cambiar a SUSPENDED
|
|
$suspendBody = @{
|
|
status = "suspended"
|
|
} | ConvertTo-Json
|
|
|
|
$suspendedTenant = Invoke-RestMethod -Uri "http://localhost:8000/v1/tenants/$($firstTenant.id)" `
|
|
-Method PUT `
|
|
-ContentType "application/json" `
|
|
-Headers $headers `
|
|
-Body $suspendBody
|
|
Write-Host " -> Cambiado a: $($suspendedTenant.status)" -ForegroundColor Yellow
|
|
|
|
# Volver a ACTIVE
|
|
$activeBody = @{
|
|
status = "active"
|
|
} | ConvertTo-Json
|
|
|
|
$activeTenant = Invoke-RestMethod -Uri "http://localhost:8000/v1/tenants/$($firstTenant.id)" `
|
|
-Method PUT `
|
|
-ContentType "application/json" `
|
|
-Headers $headers `
|
|
-Body $activeBody
|
|
Write-Host " -> Cambiado a: $($activeTenant.status)" -ForegroundColor Green
|
|
|
|
Write-Host "`n=== OK - TODAS LAS PRUEBAS PASARON ===" -ForegroundColor Green
|
|
Write-Host "El endpoint de actualizacion de tenants funciona correctamente" -ForegroundColor Cyan
|