重构:统一应用服务与基础设施适配边界
将账号、认证、管理员、分析、自动化、卡券、聊天、商品、关键词、设置和订单能力迁移到 application 与 adapter,删除 Server 内对应的旧仓储和业务服务实现,并收紧架构检查。 完善批量发布与订单刷新生命周期、凭证写回、账号任务补偿、订单 reconciliation、通知和敏感数据边界;补充正常、失败、取消、并发、越权及多方言回归测试,并修正 MySQL 延迟任务表的 InnoDB 配置。 修复空卡密响应为 null 时前端加载失败的问题,重建嵌入式前端资产;重写重构总计划,清除历史流水并明确阶段 1 至 10 各对应一次完整迭代和一个 PR。 验证:make check;make test-server-race;npm test/typecheck/comments:check/build;Docker SQLite/MySQL 8.4/PostgreSQL 17 TestMultiDB_*。
This commit is contained in:
1 parent
19a7d5f924
commit
375e84d663
239 files changed
+23870
-7871
No files matched your search
@@ -4,73 +4,11 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"xianyu-go/internal/adapter"
|
||||
orderapp "xianyu-go/internal/application/orders"
|
||||
"xianyu-go/internal/db"
|
||||
)
|
||||
|
||||
// TestOrderModelConversions 保证订单边界转换完整保留业务字段并正确处理空值。
|
||||
func TestOrderModelConversions(t *testing.T) {
|
||||
// databaseOrder 是模拟数据库读取到的完整订单实体。
|
||||
databaseOrder := &db.Order{
|
||||
OrderID: "order-1", ItemID: "item-1", BuyerID: "buyer-1", SpecName: "颜色",
|
||||
SpecValue: "蓝", Quantity: "2", Amount: "19.90", OrderStatus: "pending_ship",
|
||||
CookieID: "cookie-1", IsBargain: 1, ReceiverName: "收货人", ReceiverPhone: "13800000000",
|
||||
ReceiverAddr: "上海市", ReceiverCity: "上海", Version: 3, ChatID: "chat-1",
|
||||
SystemShipped: true, PaidAt: "paid", ShippedAt: "shipped", CompletedAt: "completed",
|
||||
BuyerReviewedAt: "reviewed", LastReviewRequestAt: "requested", ReviewRequestCount: 2,
|
||||
CreatedAt: "created", UpdatedAt: "updated",
|
||||
}
|
||||
// applicationOrder 是订单应用层实体的预期结果。
|
||||
applicationOrder := &orderapp.Order{
|
||||
OrderID: "order-1", ItemID: "item-1", BuyerID: "buyer-1", SpecName: "颜色",
|
||||
SpecValue: "蓝", Quantity: "2", Amount: "19.90", OrderStatus: "pending_ship",
|
||||
CookieID: "cookie-1", IsBargain: 1, ReceiverName: "收货人", ReceiverPhone: "13800000000",
|
||||
ReceiverAddress: "上海市", ReceiverCity: "上海", Version: 3, ChatID: "chat-1",
|
||||
SystemShipped: true, PaidAt: "paid", ShippedAt: "shipped", CompletedAt: "completed",
|
||||
BuyerReviewedAt: "reviewed", LastReviewRequestAt: "requested", ReviewRequestCount: 2,
|
||||
CreatedAt: "created", UpdatedAt: "updated",
|
||||
}
|
||||
// converted 是数据库订单转换后的应用订单。
|
||||
converted := orderFromDB(databaseOrder)
|
||||
if !reflect.DeepEqual(converted, applicationOrder) {
|
||||
t.Fatalf("订单转换结果不完整: got=%+v want=%+v", converted, applicationOrder)
|
||||
}
|
||||
if orderFromDB(nil) != nil {
|
||||
t.Fatal("空数据库订单应转换为空应用订单")
|
||||
}
|
||||
|
||||
// databaseItem 是模拟数据库读取到的完整商品实体。
|
||||
databaseItem := &db.ItemInfo{
|
||||
ID: 7, CookieID: "cookie-1", ItemID: "item-1", ItemTitle: "商品",
|
||||
ItemDescription: "描述", ItemCategory: "分类", ItemPrice: "9.95", ItemDetail: `{"images":["a"]}`,
|
||||
IsMultiSpec: true, MultiQuantityDelivery: true,
|
||||
}
|
||||
// applicationItem 是商品应用层实体的预期结果。
|
||||
applicationItem := &orderapp.ItemInfo{
|
||||
ID: 7, CookieID: "cookie-1", ItemID: "item-1", ItemTitle: "商品",
|
||||
ItemDescription: "描述", ItemCategory: "分类", ItemPrice: "9.95", ItemDetail: `{"images":["a"]}`,
|
||||
IsMultiSpec: true, MultiQuantityDelivery: true,
|
||||
}
|
||||
// convertedItem 是数据库商品转换后的应用商品。
|
||||
convertedItem := itemInfoFromDB(databaseItem)
|
||||
if !reflect.DeepEqual(convertedItem, applicationItem) {
|
||||
t.Fatalf("商品转换结果不完整: got=%+v want=%+v", convertedItem, applicationItem)
|
||||
}
|
||||
if itemInfoFromDB(nil) != nil {
|
||||
t.Fatal("空数据库商品应转换为空应用商品")
|
||||
}
|
||||
|
||||
// databaseRuntime 是模拟数据库读取到的平台运行视图。
|
||||
databaseRuntime := db.CookiePlatformRuntimeData{ID: "cookie-1", UserID: 9, Value: "cookie", MetadataJSON: "{}", ShowBrowser: true}
|
||||
// applicationRuntime 是平台运行视图的预期应用层结果。
|
||||
applicationRuntime := &orderapp.PlatformRuntimeData{ID: "cookie-1", UserID: 9, Value: "cookie", MetadataJSON: "{}", ShowBrowser: true}
|
||||
// convertedRuntime 是数据库平台运行视图转换后的应用模型。
|
||||
convertedRuntime := platformRuntimeDataFromDB(databaseRuntime)
|
||||
if !reflect.DeepEqual(convertedRuntime, applicationRuntime) {
|
||||
t.Fatalf("平台运行视图转换结果不完整: got=%+v want=%+v", convertedRuntime, applicationRuntime)
|
||||
}
|
||||
}
|
||||
|
||||
// TestOrderForAutomation 保证未迁移的自动化边界不会丢失订单字段。
|
||||
func TestOrderForAutomation(t *testing.T) {
|
||||
// applicationOrder 是传入自动化中心适配器的应用订单。
|
||||
@@ -84,27 +22,11 @@ func TestOrderForAutomation(t *testing.T) {
|
||||
CookieID: "cookie-2", ChatID: "chat-2", OrderStatus: "pending_ship", Version: 4,
|
||||
}
|
||||
// converted 是传给自动化中心的数据库订单。
|
||||
converted := orderForAutomation(applicationOrder)
|
||||
converted := adapter.OrderForAutomation(applicationOrder)
|
||||
if !reflect.DeepEqual(converted, expectedDatabaseOrder) {
|
||||
t.Fatalf("自动化边界订单转换错误: got=%+v want=%+v", converted, expectedDatabaseOrder)
|
||||
}
|
||||
if orderForAutomation(nil) != nil {
|
||||
if adapter.OrderForAutomation(nil) != nil {
|
||||
t.Fatal("空应用订单应转换为空数据库订单")
|
||||
}
|
||||
}
|
||||
|
||||
// TestCookieDetailForOrderPlatform 保证订单刷新访问共享会话辅助函数时只映射最小字段。
|
||||
func TestCookieDetailForOrderPlatform(t *testing.T) {
|
||||
// runtimeData 是订单应用层持有的平台运行视图。
|
||||
runtimeData := &orderapp.PlatformRuntimeData{ID: "cookie-3", UserID: 11, Value: "value", MetadataJSON: "metadata", ShowBrowser: true}
|
||||
// expectedDetail 是共享 Server 会话辅助函数使用的兼容详情。
|
||||
expectedDetail := &db.CookieDetail{ID: "cookie-3", UserID: 11, Value: "value", MetadataJSON: "metadata", ShowBrowser: true}
|
||||
// converted 是共享 Server 会话辅助函数使用的平台详情。
|
||||
converted := cookieDetailForOrderPlatform(runtimeData)
|
||||
if !reflect.DeepEqual(converted, expectedDetail) {
|
||||
t.Fatalf("平台详情边界转换错误: got=%+v want=%+v", converted, expectedDetail)
|
||||
}
|
||||
if cookieDetailForOrderPlatform(nil) != nil {
|
||||
t.Fatal("空平台运行视图应转换为空平台详情")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user