145 lines
5.2 KiB
Go
145 lines
5.2 KiB
Go
package seed
|
||
|
||
import (
|
||
"regexp"
|
||
"testing"
|
||
|
||
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/common"
|
||
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
||
)
|
||
|
||
func TestMockEntityIdentitiesAreStableAndUnique(t *testing.T) {
|
||
identityPattern := regexp.MustCompile(
|
||
`^00000000-0000-7000-8000-[0-9]{12}$`,
|
||
)
|
||
seen := make(map[string]struct{}, 46)
|
||
for sequence := 1; sequence <= 46; sequence++ {
|
||
record := entity(sequence, common.StatusEnable)
|
||
if !identityPattern.MatchString(record.Identity) {
|
||
t.Fatalf("entity(%d) identity = %q", sequence, record.Identity)
|
||
}
|
||
if _, exists := seen[record.Identity]; exists {
|
||
t.Fatalf("duplicate identity %q", record.Identity)
|
||
}
|
||
seen[record.Identity] = struct{}{}
|
||
if record.Status != common.StatusEnable {
|
||
t.Fatalf("entity(%d) has unexpected defaults: %#v", sequence, record)
|
||
}
|
||
}
|
||
}
|
||
|
||
// TestLinkMockProductProducer 验证未来 Mock 智能气阀始终关联已落库生产商。
|
||
func TestLinkMockProductProducer(t *testing.T) {
|
||
product := models.ProductInfo{}
|
||
producer := models.ProducerAccount{Entity: models.Entity{ID: 9}}
|
||
if err := linkMockProductProducer(&product, producer); err != nil {
|
||
t.Fatalf("关联 Mock 生产商失败:%v", err)
|
||
}
|
||
if product.ProducerAccountID != producer.ID {
|
||
t.Fatalf("生产商关联错误:got %d, want %d", product.ProducerAccountID, producer.ID)
|
||
}
|
||
if err := linkMockProductProducer(&models.ProductInfo{}, models.ProducerAccount{}); err == nil {
|
||
t.Fatal("未落库生产商不应建立 Mock 关联")
|
||
}
|
||
}
|
||
|
||
func TestIdentityOfEmbeddedEntity(t *testing.T) {
|
||
record := struct {
|
||
Entity struct {
|
||
Identity string
|
||
}
|
||
}{}
|
||
record.Entity.Identity = "mock-identity"
|
||
if got := identityOf(&record); got != record.Entity.Identity {
|
||
t.Fatalf("identityOf() = %q, want %q", got, record.Entity.Identity)
|
||
}
|
||
if got := identityOf(nil); got != "" {
|
||
t.Fatalf("identityOf(nil) = %q, want empty", got)
|
||
}
|
||
}
|
||
|
||
func TestIdentityOfDirectIdentityField(t *testing.T) {
|
||
record := struct {
|
||
Identity string
|
||
}{Identity: "mock-direct-identity"}
|
||
if got := identityOf(&record); got != record.Identity {
|
||
t.Fatalf("identityOf() = %q, want %q", got, record.Identity)
|
||
}
|
||
}
|
||
|
||
func TestAdditionalScenarioIdentitiesDoNotOverlapBaseScenario(t *testing.T) {
|
||
seen := make(map[string]struct{}, 226)
|
||
for sequence := 1; sequence <= 56; sequence++ {
|
||
seen[entity(sequence, common.StatusEnable).Identity] = struct{}{}
|
||
}
|
||
for scenario := 2; scenario <= 10; scenario++ {
|
||
base := 1000 + scenario*100
|
||
for offset := 1; offset <= 20; offset++ {
|
||
identity := entity(base+offset, common.StatusEnable).Identity
|
||
if _, exists := seen[identity]; exists {
|
||
t.Fatalf("duplicate identity %q", identity)
|
||
}
|
||
seen[identity] = struct{}{}
|
||
}
|
||
}
|
||
}
|
||
|
||
// TestMockGasorderInitialStatusMatchesWorkflow 验证 Mock 订单从文档定义的“已创建”状态起步。
|
||
func TestMockGasorderInitialStatusMatchesWorkflow(t *testing.T) {
|
||
if got := mockGasorderInitialStatus(); got != common.StatusCreated {
|
||
t.Fatalf("Mock 订单初始状态 = %d, want %d", got, common.StatusCreated)
|
||
}
|
||
if mockGasorderInitialStatus() == common.StatusPending {
|
||
t.Fatal("Mock 配送订单不得使用通用待处理状态")
|
||
}
|
||
}
|
||
|
||
// TestMockEcOrderStatusesMatchWorkflow 验证 Mock 商城订单遵循商城独立交易状态。
|
||
func TestMockEcOrderStatusesMatchWorkflow(t *testing.T) {
|
||
if got := mockEcOrderPendingStatus(); got != 16 {
|
||
t.Fatalf("Mock 商城待支付状态 = %d, want 16", got)
|
||
}
|
||
if got := mockEcOrderPaidStatus(); got != 18 {
|
||
t.Fatalf("Mock 商城已支付状态 = %d, want 18", got)
|
||
}
|
||
if mockEcOrderPendingStatus() == common.StatusPending || mockEcOrderPaidStatus() == common.StatusPaid {
|
||
t.Fatal("Mock 商城订单不得复用跨领域通用状态")
|
||
}
|
||
}
|
||
|
||
// TestMockEcOrderRepairSpecs 验证修复命令只覆盖固定十条商城 Mock 订单。
|
||
func TestMockEcOrderRepairSpecs(t *testing.T) {
|
||
specs := mockEcOrderRepairSpecs()
|
||
if len(specs) != 10 {
|
||
t.Fatalf("Mock 商城订单修复数量 = %d, want 10", len(specs))
|
||
}
|
||
if specs[0].orderNo != "MOCK-ECORDER-001" || specs[0].status != 18 || specs[0].paidAt == nil {
|
||
t.Fatalf("首条已支付 Mock 订单修复配置错误:%#v", specs[0])
|
||
}
|
||
for _, spec := range specs[1:] {
|
||
if spec.status != 16 || spec.paidAt != nil || spec.amount <= 0 ||
|
||
spec.contactName == "" || spec.contactPhone == "" || spec.address == "" ||
|
||
spec.longitude == "" || spec.latitude == "" {
|
||
t.Fatalf("待支付 Mock 订单修复配置错误:%#v", spec)
|
||
}
|
||
}
|
||
last := specs[len(specs)-1]
|
||
if last.contactName != "示例客户10" || last.address != "上海市客户路 10 号" ||
|
||
last.longitude != "121.5010" || last.latitude != "31.2010" {
|
||
t.Fatalf("第十组 Mock 快照格式错误:%#v", last)
|
||
}
|
||
}
|
||
|
||
// TestMockTrackPointSampleRequiredFields 验证演示轨迹点符合真实上报的必填字段和可读展示要求。
|
||
func TestMockTrackPointSampleRequiredFields(t *testing.T) {
|
||
if mockTrackPointRequestNo == "" {
|
||
t.Fatal("Mock 轨迹点必须包含上报流水号")
|
||
}
|
||
if mockTrackPointReceiveDelay <= 0 {
|
||
t.Fatal("Mock 轨迹点接收时间必须晚于定位时间")
|
||
}
|
||
if mockTrackPointSpeed == "" || mockTrackPointDirection == "" {
|
||
t.Fatal("演示轨迹点必须提供可读的速度和方向")
|
||
}
|
||
}
|