lrj
3 天以前 4fa9591629721797386fc11836e3a9deb69cd58c
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
# Employee Management Test Script
Write-Host "=== Employee Management Test ===" -ForegroundColor Green
 
$baseUrl = "http://localhost:8080/api/graphql"
$headers = @{
    "Content-Type" = "application/json"
}
 
# Test 1: Get all employees
Write-Host "`n1. Testing get all employees..." -ForegroundColor Yellow
$query1 = '{"query":"query GetEmployees { employees { id name phone roleCode description status createTime updateTime } }"}'
 
try {
    $response1 = Invoke-RestMethod -Uri $baseUrl -Method POST -Body $query1 -Headers $headers
    Write-Host "Success: Get employees list" -ForegroundColor Green
    Write-Host "Employee count: $($response1.data.employees.Count)" -ForegroundColor Cyan
    if ($response1.data.employees.Count -gt 0) {
        Write-Host "First employee: $($response1.data.employees[0].name)" -ForegroundColor Cyan
    }
} catch {
    Write-Host "Failed: Get employees list - $($_.Exception.Message)" -ForegroundColor Red
}
 
# Test 2: Add new employee
Write-Host "`n2. Testing add new employee..." -ForegroundColor Yellow
$mutation1 = '{"query":"mutation SaveEmployee($input: EmployeeInput!) { saveEmployee(input: $input) { id name phone roleCode description status createTime } }","variables":{"input":{"name":"Test Employee","phone":"13800138000","password":"123456","roleCode":"STAFF","description":"This is a test employee","status":"ACTIVE"}}}'
 
try {
    $response2 = Invoke-RestMethod -Uri $baseUrl -Method POST -Body $mutation1 -Headers $headers
    Write-Host "Success: Add new employee" -ForegroundColor Green
    $newEmployeeId = $response2.data.saveEmployee.id
    Write-Host "New employee ID: $newEmployeeId" -ForegroundColor Cyan
    Write-Host "New employee name: $($response2.data.saveEmployee.name)" -ForegroundColor Cyan
} catch {
    Write-Host "Failed: Add new employee - $($_.Exception.Message)" -ForegroundColor Red
    $newEmployeeId = $null
}
 
# Test 3: Search employees by name
Write-Host "`n3. Testing search employees..." -ForegroundColor Yellow
$query2 = '{"query":"query SearchEmployees($name: String) { employeesByName(name: $name) { id name phone roleCode description status } }","variables":{"name":"Test"}}'
 
try {
    $response3 = Invoke-RestMethod -Uri $baseUrl -Method POST -Body $query2 -Headers $headers
    Write-Host "Success: Search employees" -ForegroundColor Green
    Write-Host "Search result count: $($response3.data.employeesByName.Count)" -ForegroundColor Cyan
} catch {
    Write-Host "Failed: Search employees - $($_.Exception.Message)" -ForegroundColor Red
}
 
# Test 4: Delete test employee (if created successfully)
if ($newEmployeeId) {
    Write-Host "`n4. Testing delete employee..." -ForegroundColor Yellow
    $mutation2 = "{`"query`":`"mutation DeleteEmployee(`$id: Long!) { deleteEmployee(id: `$id) }`",`"variables`":{`"id`":$newEmployeeId}}"
 
    try {
        $response4 = Invoke-RestMethod -Uri $baseUrl -Method POST -Body $mutation2 -Headers $headers
        Write-Host "Success: Delete employee" -ForegroundColor Green
    } catch {
        Write-Host "Failed: Delete employee - $($_.Exception.Message)" -ForegroundColor Red
    }
}
 
Write-Host "`n=== Test Complete ===" -ForegroundColor Green
Write-Host "Please check frontend page http://localhost:3000/#/employee to verify UI functionality" -ForegroundColor Cyan