# Script de test local pour CRUD Crew Members (PowerShell) # Usage: .\test-crew-members-local.ps1 $BASE_URL = "http://apiparcapp.test" # Ou si vous utilisez artisan serve: $BASE_URL = "http://127.0.0.1:8000" Write-Host "🔐 Étape 1: Login pour obtenir le token..." -ForegroundColor Cyan $loginBody = @{ email = "admin@parcapp.test" password = "password123" } | ConvertTo-Json $loginResponse = Invoke-RestMethod -Uri "$BASE_URL/api/login" ` -Method POST ` -ContentType "application/json" ` -Body $loginBody $TOKEN = $loginResponse.token if (-not $TOKEN) { Write-Host "❌ Erreur: Impossible de rĂ©cupĂ©rer le token." -ForegroundColor Red exit 1 } Write-Host "✅ Token obtenu: $($TOKEN.Substring(0, [Math]::Min(20, $TOKEN.Length)))..." -ForegroundColor Green Write-Host "" Write-Host "📋 Étape 2: GET /api/crew-members (liste vide au dĂ©but)" -ForegroundColor Cyan $headers = @{ "Authorization" = "Bearer $TOKEN" "Accept" = "application/json" } try { $response = Invoke-RestMethod -Uri "$BASE_URL/api/crew-members" ` -Method GET ` -Headers $headers $response | ConvertTo-Json -Depth 10 } catch { Write-Host "Erreur: $_" -ForegroundColor Red } Write-Host "" Write-Host "➕ Étape 3: POST /api/crew-members (crĂ©ation)" -ForegroundColor Cyan $createBody = @{ nom = "OuĂ©draogo" prenom = "Amadou" role = "chauffeur" telephone = "+226 70 12 34 56" } | ConvertTo-Json try { $createResponse = Invoke-RestMethod -Uri "$BASE_URL/api/crew-members" ` -Method POST ` -Headers $headers ` -ContentType "application/json" ` -Body $createBody $createResponse | ConvertTo-Json -Depth 10 $CREW_MEMBER_ID = $createResponse.id Write-Host "✅ Membre créé avec ID: $CREW_MEMBER_ID" -ForegroundColor Green } catch { Write-Host "Erreur: $_" -ForegroundColor Red exit 1 } Write-Host "" Write-Host "đŸ‘ïž Étape 4: GET /api/crew-members/$CREW_MEMBER_ID (show)" -ForegroundColor Cyan try { $response = Invoke-RestMethod -Uri "$BASE_URL/api/crew-members/$CREW_MEMBER_ID" ` -Method GET ` -Headers $headers $response | ConvertTo-Json -Depth 10 } catch { Write-Host "Erreur: $_" -ForegroundColor Red } Write-Host "" Write-Host "✏ Étape 5: PATCH /api/crew-members/$CREW_MEMBER_ID (update partiel)" -ForegroundColor Cyan $updateBody = @{ telephone = "+226 70 99 88 77" } | ConvertTo-Json try { $response = Invoke-RestMethod -Uri "$BASE_URL/api/crew-members/$CREW_MEMBER_ID" ` -Method PATCH ` -Headers $headers ` -ContentType "application/json" ` -Body $updateBody $response | ConvertTo-Json -Depth 10 } catch { Write-Host "Erreur: $_" -ForegroundColor Red } Write-Host "" Write-Host "đŸ“€ Étape 6: POST /api/upload/crew-member-photo (upload)" -ForegroundColor Cyan Write-Host "⚠ Note: Cette Ă©tape nĂ©cessite un fichier image. CrĂ©ez un fichier test.jpg ou commentez cette section." -ForegroundColor Yellow # $uploadFile = "test.jpg" # if (Test-Path $uploadFile) { # $form = @{ # photo = Get-Item $uploadFile # } # try { # $response = Invoke-RestMethod -Uri "$BASE_URL/api/upload/crew-member-photo" ` # -Method POST ` # -Headers @{ "Authorization" = "Bearer $TOKEN" } ` # -Form $form # $response | ConvertTo-Json -Depth 10 # } catch { # Write-Host "Erreur: $_" -ForegroundColor Red # } # } else { # Write-Host "Fichier test.jpg non trouvĂ©, upload ignorĂ©." -ForegroundColor Yellow # } Write-Host "" Write-Host "📋 Étape 7: GET /api/crew-members (liste avec donnĂ©es)" -ForegroundColor Cyan try { $response = Invoke-RestMethod -Uri "$BASE_URL/api/crew-members" ` -Method GET ` -Headers $headers $response | ConvertTo-Json -Depth 10 } catch { Write-Host "Erreur: $_" -ForegroundColor Red } Write-Host "" Write-Host "đŸ—‘ïž Étape 8: DELETE /api/crew-members/$CREW_MEMBER_ID" -ForegroundColor Cyan try { $deleteResponse = Invoke-WebRequest -Uri "$BASE_URL/api/crew-members/$CREW_MEMBER_ID" ` -Method DELETE ` -Headers $headers if ($deleteResponse.StatusCode -eq 204) { Write-Host "✅ Suppression rĂ©ussie (status 204)" -ForegroundColor Green } else { Write-Host "❌ Erreur: Status $($deleteResponse.StatusCode) (attendu: 204)" -ForegroundColor Red } } catch { if ($_.Exception.Response.StatusCode -eq 204) { Write-Host "✅ Suppression rĂ©ussie (status 204)" -ForegroundColor Green } else { Write-Host "Erreur: $_" -ForegroundColor Red } } Write-Host "" Write-Host "✅ Tests terminĂ©s!" -ForegroundColor Green