test: add comprehensive test coverage and improve code quality

- Add new test files for auth, service, and handler modules
- Improve test organization and coverage
- Refactor code for better maintainability
- Add captcha, settings, stats, and theme handler tests
- Add auth module tests (CAS, OAuth, password, SSO, state)
- Add service layer tests for auth, export, permissions, roles
- All Go tests pass (exit code 0)
- All frontend tests pass (325 tests in 59 files)
This commit is contained in:
2026-04-17 20:43:50 +08:00
parent 0d66aa0423
commit 582ad7a069
136 changed files with 19010 additions and 8544 deletions

View File

@@ -20,9 +20,9 @@ import (
"github.com/user-management-system/internal/auth"
"github.com/user-management-system/internal/cache"
"github.com/user-management-system/internal/config"
"github.com/user-management-system/internal/domain"
"github.com/user-management-system/internal/repository"
"github.com/user-management-system/internal/service"
"github.com/user-management-system/internal/domain"
gormsqlite "gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
@@ -109,7 +109,7 @@ func setupHandlerTestServer(t *testing.T) (*httptest.Server, func()) {
rateLimitCfg := config.RateLimitConfig{}
rateLimitMiddleware := middleware.NewRateLimitMiddleware(rateLimitCfg)
authMiddleware := middleware.NewAuthMiddleware(
jwtManager, userRepo, userRoleRepo, roleRepo, rolePermissionRepo, permissionRepo, l1Cache,
jwtManager, userRepo, userRoleRepo, l1Cache,
)
authMiddleware.SetCacheManager(cacheManager)
opLogMiddleware := middleware.NewOperationLogMiddleware(opLogRepo)
@@ -646,10 +646,10 @@ func TestDeviceHandler_CreateDevice_Success(t *testing.T) {
token := getToken(server.URL, "createdevice", "UserPass123!")
resp, body := doPost(server.URL+"/api/v1/devices", token, map[string]interface{}{
"name": "My Device",
"device_id": "device-001",
"device_type": 3, // DeviceTypeDesktop
"device_os": "Windows 10",
"name": "My Device",
"device_id": "device-001",
"device_type": 3, // DeviceTypeDesktop
"device_os": "Windows 10",
"device_browser": "Chrome",
})
defer resp.Body.Close()