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)
2026-04-17 20:43:50 +08:00
|
|
|
package handler_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2026-05-30 14:37:15 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
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)
2026-04-17 20:43:50 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// =============================================================================
|
2026-05-30 14:37:15 +08:00
|
|
|
// SettingsHandler Tests - System Settings
|
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)
2026-04-17 20:43:50 +08:00
|
|
|
// =============================================================================
|
|
|
|
|
|
2026-05-30 14:37:15 +08:00
|
|
|
// TestSettingsHandler_GetSettings_Success 验证获取系统设置
|
|
|
|
|
func TestSettingsHandler_GetSettings_Success(t *testing.T) {
|
|
|
|
|
server, cleanup := setupHandlerTestServer(t)
|
|
|
|
|
defer cleanup()
|
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)
2026-04-17 20:43:50 +08:00
|
|
|
|
2026-05-30 14:37:15 +08:00
|
|
|
token := bootstrapAdminToken(server.URL, "admin", "admin@test.com", "AdminPass123!")
|
|
|
|
|
if token == "" {
|
|
|
|
|
t.Fatal("bootstrap admin token should succeed")
|
|
|
|
|
}
|
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)
2026-04-17 20:43:50 +08:00
|
|
|
|
2026-05-30 14:37:15 +08:00
|
|
|
resp, body := doGet(server.URL+"/api/v1/admin/settings", token)
|
|
|
|
|
defer resp.Body.Close()
|
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)
2026-04-17 20:43:50 +08:00
|
|
|
|
2026-05-30 14:37:15 +08:00
|
|
|
assert.True(t, resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusForbidden || resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusInternalServerError,
|
|
|
|
|
"should get settings, got %d: %s", resp.StatusCode, body)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TestSettingsHandler_GetSettings_NonAdmin 验证非管理员访问
|
|
|
|
|
func TestSettingsHandler_GetSettings_NonAdmin(t *testing.T) {
|
|
|
|
|
server, cleanup := setupHandlerTestServer(t)
|
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
|
|
registerUser(server.URL, "regular", "regular@test.com", "Pass123!")
|
|
|
|
|
token := getToken(server.URL, "regular", "Pass123!")
|
|
|
|
|
assert.NotEmpty(t, token)
|
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)
2026-04-17 20:43:50 +08:00
|
|
|
|
2026-05-30 14:37:15 +08:00
|
|
|
resp, _ := doGet(server.URL+"/api/v1/admin/settings", token)
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
|
|
assert.True(t, resp.StatusCode == http.StatusForbidden || resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusOK,
|
|
|
|
|
"should handle non-admin access, got %d", resp.StatusCode)
|
|
|
|
|
}
|
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)
2026-04-17 20:43:50 +08:00
|
|
|
|
2026-05-30 14:37:15 +08:00
|
|
|
// TestSettingsHandler_GetSettings_Unauthorized 验证未认证访问
|
|
|
|
|
func TestSettingsHandler_GetSettings_Unauthorized(t *testing.T) {
|
|
|
|
|
server, cleanup := setupHandlerTestServer(t)
|
|
|
|
|
defer cleanup()
|
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)
2026-04-17 20:43:50 +08:00
|
|
|
|
2026-05-30 14:37:15 +08:00
|
|
|
resp, _ := doGet(server.URL+"/api/v1/admin/settings", "")
|
|
|
|
|
defer resp.Body.Close()
|
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)
2026-04-17 20:43:50 +08:00
|
|
|
|
2026-05-30 14:37:15 +08:00
|
|
|
assert.True(t, resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusForbidden,
|
|
|
|
|
"should require auth, got %d", resp.StatusCode)
|
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)
2026-04-17 20:43:50 +08:00
|
|
|
}
|