lrj
3 天以前 6d519474e44855682043d3c40db2c86a6822caca
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
# 测试修复后的员工API
Write-Host "测试员工API修复..." -ForegroundColor Green
 
# 测试获取员工列表
Write-Host "1. 测试获取员工列表..." -ForegroundColor Yellow
$getEmployeesQuery = @{
    query = "query GetEmployees { employees { id name phone roleCode description status createTime updateTime } }"
} | ConvertTo-Json -Compress
 
try {
    $response = Invoke-RestMethod -Uri "http://localhost:8080/api/graphql" -Method POST -Body $getEmployeesQuery -ContentType "application/json"
    Write-Host "获取员工列表成功" -ForegroundColor Green
    Write-Host "员工数量: $($response.data.employees.Count)" -ForegroundColor Cyan
} catch {
    Write-Host "获取员工列表失败: $($_.Exception.Message)" -ForegroundColor Red
}
 
# 测试添加员工
Write-Host "`n2. 测试添加员工..." -ForegroundColor Yellow
$addEmployeeMutation = @{
    query = "mutation SaveEmployee(`$input: EmployeeInput!) { saveEmployee(input: `$input) { id name phone roleCode description status } }"
    variables = @{
        input = @{
            name = "测试员工API修复"
            phone = "13800138000"
            password = "123456"
            roleCode = "EMPLOYEE"
            description = "API修复测试员工"
        }
    }
} | ConvertTo-Json -Compress -Depth 3
 
try {
    $response = Invoke-RestMethod -Uri "http://localhost:8080/api/graphql" -Method POST -Body $addEmployeeMutation -ContentType "application/json"
    Write-Host "添加员工成功" -ForegroundColor Green
    $newEmployeeId = $response.data.saveEmployee.id
    $newEmployeeName = $response.data.saveEmployee.name
    Write-Host "新员工ID: $newEmployeeId, 姓名: $newEmployeeName" -ForegroundColor Cyan
} catch {
    Write-Host "添加员工失败: $($_.Exception.Message)" -ForegroundColor Red
}
 
Write-Host "`n员工API修复测试完成!" -ForegroundColor Green