-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-bulk-import.ps1
More file actions
75 lines (57 loc) · 2.76 KB
/
Copy pathtest-bulk-import.ps1
File metadata and controls
75 lines (57 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Test script for bulk product import
# Make sure the application is running on localhost:8080
Write-Host "🚀 Testing Bulk Product Import API" -ForegroundColor Green
Write-Host "=================================" -ForegroundColor Green
# First, let's login as admin to get a token
Write-Host "`n1. Logging in as admin..." -ForegroundColor Yellow
$loginBody = @{
email = "admin@ordernet.com"
password = "admin123"
} | ConvertTo-Json
try {
$loginResponse = Invoke-RestMethod -Uri "http://localhost:8080/api/v1/auth/login" -Method POST -Body $loginBody -ContentType "application/json"
$token = $loginResponse.token
Write-Host "✅ Login successful! Token received." -ForegroundColor Green
} catch {
Write-Host "❌ Login failed: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Make sure the application is running and admin credentials are correct." -ForegroundColor Yellow
exit 1
}
# Set up headers with authorization
$headers = @{
"Authorization" = "Bearer $token"
"Content-Type" = "application/json"
}
# Test the bulk import endpoint
Write-Host "`n2. Testing bulk import endpoint..." -ForegroundColor Yellow
try {
# Read the JSON file
$jsonContent = Get-Content -Path "bulk-import-products.json" -Raw
# Make the API call
$response = Invoke-RestMethod -Uri "http://localhost:8080/api/v1/products/bulk-import" -Method POST -Body $jsonContent -Headers $headers
Write-Host "✅ Bulk import successful!" -ForegroundColor Green
Write-Host "Response:" -ForegroundColor Cyan
$response | ConvertTo-Json -Depth 3 | Write-Host
} catch {
Write-Host "❌ Bulk import failed: $($_.Exception.Message)" -ForegroundColor Red
if ($_.Exception.Response) {
$errorStream = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($errorStream)
$errorBody = $reader.ReadToEnd()
Write-Host "Error details: $errorBody" -ForegroundColor Red
}
}
# Test getting products to verify import
Write-Host "`n3. Verifying imported products..." -ForegroundColor Yellow
try {
$productsResponse = Invoke-RestMethod -Uri "http://localhost:8080/api/v1/products?size=20" -Method GET -Headers $headers
Write-Host "✅ Products retrieved successfully!" -ForegroundColor Green
Write-Host "Total products found: $($productsResponse.totalElements)" -ForegroundColor Cyan
Write-Host "First few products:" -ForegroundColor Cyan
$productsResponse.content | Select-Object -First 5 | ForEach-Object {
Write-Host " - $($_.name) (SKU: $($_.sku)) - $($_.price) TL" -ForegroundColor White
}
} catch {
Write-Host "❌ Failed to retrieve products: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host "`n🎉 Test completed!" -ForegroundColor Green