- 将员工表org_no字段迁移至dept_id,关联系统部门表 - 更新员工信息相关DTO、VO和Controller,使用deptId替代orgNo - 添加员工信息管理OpenSpec规范文档(proposal/design/spec/tasks) - 更新API文档,反映部门关联变更 - 添加数据库迁移脚本employee_org_no_to_dept_id.sql - 新增员工信息分页接口测试脚本(PowerShell/Python) - 更新CLAUDE.md,添加MCP数据库工具使用说明 Co-Authored-By: Claude (glm-4.7) <noreply@anthropic.com>
141 lines
4.3 KiB
PowerShell
141 lines
4.3 KiB
PowerShell
# Pagination API Test Script
|
|
# Test employee list pagination and total count
|
|
|
|
$BaseUrl = "http://localhost:8080"
|
|
$LoginUrl = "$BaseUrl/login/test"
|
|
$ListUrl = "$BaseUrl/dpc/employee/list"
|
|
|
|
# Login to get token
|
|
$loginBody = @{
|
|
username = "admin"
|
|
password = "admin123"
|
|
} | ConvertTo-Json
|
|
|
|
Write-Host "Logging in..." -ForegroundColor Cyan
|
|
$loginResponse = Invoke-RestMethod -Uri $LoginUrl -Method Post -Body $loginBody -ContentType "application/json"
|
|
$token = $loginResponse.token
|
|
|
|
Write-Host "Login success!" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
$headers = @{
|
|
Authorization = "Bearer $token"
|
|
}
|
|
|
|
# Test function
|
|
function Test-Page {
|
|
param(
|
|
[int]$PageNum,
|
|
[int]$PageSize
|
|
)
|
|
|
|
Write-Host "========== Testing: pageNum=$PageNum, pageSize=$PageSize ==========" -ForegroundColor Yellow
|
|
|
|
$queryParams = @{
|
|
pageNum = $PageNum
|
|
pageSize = $PageSize
|
|
}
|
|
|
|
$queryString = ($queryParams.GetEnumerator() | ForEach-Object { "$($_.Key)=$($_.Value)" }) -join '&'
|
|
$url = "$ListUrl?$queryString"
|
|
|
|
try {
|
|
$response = Invoke-RestMethod -Uri $url -Method Get -Headers $headers
|
|
|
|
$rows = $response.rows.Count
|
|
$total = $response.total
|
|
$code = $response.code
|
|
|
|
Write-Host " Response Code: $code" -ForegroundColor Cyan
|
|
Write-Host " Returned Rows: $rows" -ForegroundColor Cyan
|
|
Write-Host " Total Records: $total" -ForegroundColor Cyan
|
|
|
|
# Calculate expected values
|
|
$expectedTotalPages = [Math]::Ceiling($total / $pageSize)
|
|
$expectedRows = if ($PageNum -lt $expectedTotalPages) { $pageSize } elseif ($PageNum -eq $expectedTotalPages) { $total - ($pageSize * ($PageNum - 1)) } else { 0 }
|
|
|
|
Write-Host " Expected Rows: $expectedRows" -ForegroundColor Cyan
|
|
Write-Host " Expected Total Pages: $expectedTotalPages" -ForegroundColor Cyan
|
|
|
|
# Verify
|
|
$isCorrect = $rows -eq $expectedRows
|
|
if ($isCorrect) {
|
|
Write-Host " Result: CORRECT" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " Result: WRONG! Got $rows rows, expected $expectedRows" -ForegroundColor Red
|
|
}
|
|
|
|
# Show returned employee IDs
|
|
if ($response.rows -and $response.rows.Count -gt 0) {
|
|
$ids = ($response.rows | ForEach-Object { $_.employeeId }) -join ', '
|
|
Write-Host " Employee IDs: $ids" -ForegroundColor Gray
|
|
}
|
|
|
|
return @{
|
|
Success = ($code -eq 200)
|
|
Rows = $rows
|
|
Total = $total
|
|
ExpectedRows = $expectedRows
|
|
IsCorrect = $isCorrect
|
|
Response = $response
|
|
}
|
|
}
|
|
catch {
|
|
Write-Host " Error: $_" -ForegroundColor Red
|
|
return @{
|
|
Success = $false
|
|
Error = $_.Exception.Message
|
|
}
|
|
}
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "================ Starting Pagination Tests ================" -ForegroundColor Yellow
|
|
Write-Host ""
|
|
|
|
# Test cases
|
|
$testCases = @(
|
|
@{ PageNum = 1; PageSize = 10; Description = "Page 1, Size 10" }
|
|
@{ PageNum = 2; PageSize = 10; Description = "Page 2, Size 10" }
|
|
@{ PageNum = 1; PageSize = 5; Description = "Page 1, Size 5" }
|
|
@{ PageNum = 3; PageSize = 5; Description = "Page 3, Size 5" }
|
|
@{ PageNum = 1; PageSize = 20; Description = "Page 1, Size 20" }
|
|
@{ PageNum = 1; PageSize = 3; Description = "Page 1, Size 3" }
|
|
)
|
|
|
|
$results = @()
|
|
$allCorrect = $true
|
|
|
|
foreach ($testCase in $testCases) {
|
|
Write-Host ""
|
|
$result = Test-Page -PageNum $testCase.PageNum -PageSize $testCase.PageSize
|
|
$results += [PSCustomObject]@{
|
|
Test = $testCase.Description
|
|
PageNum = $testCase.PageNum
|
|
PageSize = $testCase.PageSize
|
|
ReturnedRows = $result.Rows
|
|
TotalRecords = $result.Total
|
|
ExpectedRows = $result.ExpectedRows
|
|
Correct = if ($result.IsCorrect) { "PASS" } else { "FAIL" }
|
|
}
|
|
|
|
if (-not $result.IsCorrect) {
|
|
$allCorrect = $false
|
|
}
|
|
|
|
Start-Sleep -Milliseconds 200
|
|
}
|
|
|
|
# Show summary
|
|
Write-Host ""
|
|
Write-Host "================ Test Results Summary ================" -ForegroundColor Yellow
|
|
Write-Host ""
|
|
$results | Format-Table -AutoSize
|
|
|
|
Write-Host ""
|
|
if ($allCorrect) {
|
|
Write-Host "PASS - All tests passed! Pagination is working correctly." -ForegroundColor Green
|
|
} else {
|
|
Write-Host "FAIL - Some tests failed! Please check pagination logic." -ForegroundColor Red
|
|
}
|