阶段七:完成 React Feature 化与前置重构收口

This commit is contained in:
Christ committed 2026-08-17 20:29:34 +08:00
1 parent 375e84d663
commit 1a228dc35c
305 files changed
+14179 -5431

No files matched your search

+16 -8
View File
@@ -3,10 +3,12 @@ package server
import (
"context"
"testing"
accountapp "xianyu-go/internal/application/account"
)
// TestMarkSuccessfulLoginUsesApplicationAuditService 验证 Server 仅调用应用审计服务并保持登录成功持久化语义。
func TestMarkSuccessfulLoginUsesApplicationAuditService(t *testing.T) {
// TestLoginAuditApplicationPersistsSuccessfulLogin 验证 Server 通过应用审计服务保持登录成功持久化语义。
func TestLoginAuditApplicationPersistsSuccessfulLogin(t *testing.T) {
// srv、store 和 cleanup 保存带固定管理员账号的 HTTP 测试服务及资源清理函数。
srv, store, cleanup := newTestServer(t)
defer cleanup()
@@ -15,8 +17,11 @@ func TestMarkSuccessfulLoginUsesApplicationAuditService(t *testing.T) {
if adminErr != nil {
t.Fatal(adminErr)
}
// srv.markSuccessfulLogin 执行账号密码登录别名的成功审计。
srv.markSuccessfulLogin(context.Background(), "acc1", admin.ID, "password_login", "账号登录成功")
// auditErr 保存应用审计服务执行账号密码登录成功记录的结果。
auditErr := srv.loginAuditApplication().RecordSuccessfulLogin(context.Background(), accountapp.SuccessfulLoginInput{AccountID: "acc1", UserID: admin.ID, Method: "password_login", Message: "账号登录成功"})
if auditErr != nil {
t.Fatalf("应用审计服务写入失败: %v", auditErr)
}
// summary 保存应用服务写入后的账号非敏感摘要。
summary, summaryErr := store.Cookies.GetSummaryOwned(context.Background(), admin.ID, "acc1")
if summaryErr != nil || summary.LoginMethod != loginMethodPassword || summary.LastLoginAt == 0 {
@@ -29,13 +34,16 @@ func TestMarkSuccessfulLoginUsesApplicationAuditService(t *testing.T) {
}
}
// TestMarkSuccessfulLoginSkipsEmptyMethod 验证 Server 对缺少登录方式的兼容空操作不创建审计记录。
func TestMarkSuccessfulLoginSkipsEmptyMethod(t *testing.T) {
// TestLoginAuditApplicationSkipsEmptyMethod 验证应用审计服务对缺少登录方式的兼容空操作不创建审计记录。
func TestLoginAuditApplicationSkipsEmptyMethod(t *testing.T) {
// srv、store 和 cleanup 保存 HTTP 测试服务及资源清理函数。
srv, store, cleanup := newTestServer(t)
defer cleanup()
// srv.markSuccessfulLogin 执行缺少方式的兼容调用。
srv.markSuccessfulLogin(context.Background(), "acc1", 1, "", "不应记录")
// auditErr 保存缺少登录方式时的兼容空操作结果。
auditErr := srv.loginAuditApplication().RecordSuccessfulLogin(context.Background(), accountapp.SuccessfulLoginInput{AccountID: "acc1", UserID: 1, Message: "不应记录"})
if auditErr != nil {
t.Fatalf("缺少登录方式不应失败: %v", auditErr)
}
// logs 保存兼容调用后的数据库审计记录。
logs, logsErr := store.LoginLogs.ListByCookie(context.Background(), "acc1", 10)
if logsErr != nil {