# 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