- 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)
94 lines
2.6 KiB
Go
94 lines
2.6 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
// =============================================================================
|
|
// Settings Service Tests
|
|
// =============================================================================
|
|
|
|
func TestSettingsService_GetSettings(t *testing.T) {
|
|
svc := NewSettingsService()
|
|
ctx := context.Background()
|
|
|
|
settings, err := svc.GetSettings(ctx)
|
|
if err != nil {
|
|
t.Fatalf("GetSettings failed: %v", err)
|
|
}
|
|
if settings == nil {
|
|
t.Fatal("Expected non-nil settings")
|
|
}
|
|
if settings.System.Name == "" {
|
|
t.Error("Expected system name to be set")
|
|
}
|
|
if settings.Security.PasswordMinLength <= 0 {
|
|
t.Error("Expected password min length to be positive")
|
|
}
|
|
if len(settings.Features.OAuthProviders) == 0 {
|
|
t.Error("Expected at least one OAuth provider")
|
|
}
|
|
}
|
|
|
|
func TestNewSettingsService(t *testing.T) {
|
|
svc := NewSettingsService()
|
|
if svc == nil {
|
|
t.Error("Expected non-nil service")
|
|
}
|
|
}
|
|
|
|
func TestSystemSettings_Fields(t *testing.T) {
|
|
svc := NewSettingsService()
|
|
ctx := context.Background()
|
|
|
|
settings, _ := svc.GetSettings(ctx)
|
|
|
|
t.Run("System info fields", func(t *testing.T) {
|
|
if settings.System.Name == "" {
|
|
t.Error("Expected System.Name to be set")
|
|
}
|
|
if settings.System.Version == "" {
|
|
t.Error("Expected System.Version to be set")
|
|
}
|
|
if settings.System.Environment == "" {
|
|
t.Error("Expected System.Environment to be set")
|
|
}
|
|
if settings.System.Description == "" {
|
|
t.Error("Expected System.Description to be set")
|
|
}
|
|
})
|
|
|
|
t.Run("Security info fields", func(t *testing.T) {
|
|
if settings.Security.PasswordMinLength <= 0 {
|
|
t.Error("Expected Security.PasswordMinLength to be positive")
|
|
}
|
|
if settings.Security.PasswordHistory < 0 {
|
|
t.Error("Expected Security.PasswordHistory to be non-negative")
|
|
}
|
|
if settings.Security.LoginFailThreshold <= 0 {
|
|
t.Error("Expected Security.LoginFailThreshold to be positive")
|
|
}
|
|
if settings.Security.LoginFailDuration <= 0 {
|
|
t.Error("Expected Security.LoginFailDuration to be positive")
|
|
}
|
|
if settings.Security.SessionTimeout <= 0 {
|
|
t.Error("Expected Security.SessionTimeout to be positive")
|
|
}
|
|
if settings.Security.DeviceTrustDuration <= 0 {
|
|
t.Error("Expected Security.DeviceTrustDuration to be positive")
|
|
}
|
|
})
|
|
|
|
t.Run("Features info fields", func(t *testing.T) {
|
|
// Just verify the fields exist and are accessible
|
|
_ = settings.Features.EmailVerification
|
|
_ = settings.Features.PhoneVerification
|
|
_ = settings.Features.SSOEnabled
|
|
_ = settings.Features.OperationLogEnabled
|
|
_ = settings.Features.LoginLogEnabled
|
|
_ = settings.Features.DataExportEnabled
|
|
_ = settings.Features.DataImportEnabled
|
|
})
|
|
}
|