feat: complete staging seed coverage

This commit is contained in:
2026-01-26 09:51:48 +08:00
parent 619e17fc15
commit 51f88f23f9
2 changed files with 239 additions and 32 deletions

View File

@@ -119,6 +119,15 @@ func Serve(cmd *cobra.Command, args []string) error {
if err := models.TenantUserQuery.WithContext(ctx).Create(member); err != nil {
fmt.Printf("Create tenant member failed: %v\n", err)
}
adminMember := &models.TenantUser{
TenantID: tenant.ID,
UserID: creator.ID,
Role: types.Array[consts.TenantUserRole]{consts.TenantUserRoleTenantAdmin},
Status: consts.UserStatusVerified,
}
if err := models.TenantUserQuery.WithContext(ctx).Create(adminMember); err != nil {
fmt.Printf("Create tenant admin failed: %v\n", err)
}
// 3. Contents
titles := []string{
@@ -222,6 +231,14 @@ func Serve(cmd *cobra.Command, args []string) error {
AmountPaid: 990,
IdempotencyKey: uuid.NewString(),
PaidAt: time.Now().Add(-2 * time.Hour),
IsFlagged: true,
FlagReason: "seed risk",
FlaggedBy: superAdmin.ID,
FlaggedAt: time.Now().Add(-1 * time.Hour),
IsReconciled: true,
ReconcileNote: "seed reconcile",
ReconciledBy: superAdmin.ID,
ReconciledAt: time.Now().Add(-30 * time.Minute),
}
if err := models.OrderQuery.WithContext(ctx).Create(order); err != nil {
fmt.Printf("Create order failed: %v\n", err)
@@ -242,6 +259,102 @@ func Serve(cmd *cobra.Command, args []string) error {
Status: consts.ContentAccessStatusActive,
})
}
refundOrder := &models.Order{
TenantID: tenant.ID,
UserID: buyer.ID,
Type: consts.OrderTypeContentPurchase,
Status: consts.OrderStatusRefunded,
Currency: consts.CurrencyCNY,
AmountOriginal: 1200,
AmountDiscount: 0,
AmountPaid: 1200,
IdempotencyKey: uuid.NewString(),
PaidAt: time.Now().Add(-6 * time.Hour),
RefundedAt: time.Now().Add(-2 * time.Hour),
}
if err := models.OrderQuery.WithContext(ctx).Create(refundOrder); err != nil {
fmt.Printf("Create refund order failed: %v\n", err)
}
missingPaid := &models.Order{
TenantID: tenant.ID,
UserID: buyer.ID,
Type: consts.OrderTypeContentPurchase,
Status: consts.OrderStatusPaid,
Currency: consts.CurrencyCNY,
AmountOriginal: 1500,
AmountDiscount: 0,
AmountPaid: 1500,
IdempotencyKey: uuid.NewString(),
}
if err := models.OrderQuery.WithContext(ctx).Create(missingPaid); err != nil {
fmt.Printf("Create missing paid order failed: %v\n", err)
}
missingRefund := &models.Order{
TenantID: tenant.ID,
UserID: buyer.ID,
Type: consts.OrderTypeContentPurchase,
Status: consts.OrderStatusRefunded,
Currency: consts.CurrencyCNY,
AmountOriginal: 800,
AmountDiscount: 0,
AmountPaid: 800,
IdempotencyKey: uuid.NewString(),
PaidAt: time.Now().Add(-8 * time.Hour),
}
if err := models.OrderQuery.WithContext(ctx).Create(missingRefund); err != nil {
fmt.Printf("Create missing refund order failed: %v\n", err)
}
withdrawOrder := &models.Order{
TenantID: tenant.ID,
UserID: creator.ID,
Type: consts.OrderTypeWithdrawal,
Status: consts.OrderStatusCreated,
Currency: consts.CurrencyCNY,
AmountOriginal: 300,
AmountDiscount: 0,
AmountPaid: 300,
IdempotencyKey: uuid.NewString(),
CreatedAt: time.Now().Add(-4 * time.Hour),
}
if err := models.OrderQuery.WithContext(ctx).Create(withdrawOrder); err != nil {
fmt.Printf("Create withdrawal order failed: %v\n", err)
}
withdrawApproved := &models.Order{
TenantID: tenant.ID,
UserID: creator.ID,
Type: consts.OrderTypeWithdrawal,
Status: consts.OrderStatusPaid,
Currency: consts.CurrencyCNY,
AmountOriginal: 500,
AmountDiscount: 0,
AmountPaid: 500,
IdempotencyKey: uuid.NewString(),
PaidAt: time.Now().Add(-3 * time.Hour),
}
if err := models.OrderQuery.WithContext(ctx).Create(withdrawApproved); err != nil {
fmt.Printf("Create approved withdrawal failed: %v\n", err)
}
withdrawRejected := &models.Order{
TenantID: tenant.ID,
UserID: creator.ID,
Type: consts.OrderTypeWithdrawal,
Status: consts.OrderStatusFailed,
Currency: consts.CurrencyCNY,
AmountOriginal: 200,
AmountDiscount: 0,
AmountPaid: 200,
IdempotencyKey: uuid.NewString(),
UpdatedAt: time.Now().Add(-1 * time.Hour),
}
if err := models.OrderQuery.WithContext(ctx).Create(withdrawRejected); err != nil {
fmt.Printf("Create rejected withdrawal failed: %v\n", err)
}
}
// 6. Creator join request & invite
@@ -251,6 +364,15 @@ func Serve(cmd *cobra.Command, args []string) error {
Status: "pending",
Reason: "申请加入租户用于创作",
})
models.TenantJoinRequestQuery.WithContext(ctx).Create(&models.TenantJoinRequest{
TenantID: tenant.ID,
UserID: buyer.ID,
Status: "approved",
Reason: "已通过审核",
DecidedAt: time.Now().Add(-1 * time.Hour),
DecidedOperatorUserID: creator.ID,
DecidedReason: "符合要求",
})
models.TenantInviteQuery.WithContext(ctx).Create(&models.TenantInvite{
TenantID: tenant.ID,
UserID: creator.ID,
@@ -287,6 +409,14 @@ func Serve(cmd *cobra.Command, args []string) error {
Content: "您提交的内容已通过审核。",
IsActive: true,
})
models.NotificationTemplateQuery.WithContext(ctx).Create(&models.NotificationTemplate{
TenantID: 0,
Name: "互动提醒",
Type: consts.NotificationTypeInteraction,
Title: "有人点赞了你",
Content: "有用户对你的内容进行了点赞。",
IsActive: true,
})
// 8. System config
models.SystemConfigQuery.WithContext(ctx).Create(&models.SystemConfig{
@@ -294,6 +424,11 @@ func Serve(cmd *cobra.Command, args []string) error {
Value: types.JSON([]byte(`{"value":"曲韵平台"}`)),
Description: "站点名称",
})
models.SystemConfigQuery.WithContext(ctx).Create(&models.SystemConfig{
ConfigKey: "support_email",
Value: types.JSON([]byte(`{"value":"support@quyun.example"}`)),
Description: "客服邮箱",
})
// 9. Audit log
models.AuditLogQuery.WithContext(ctx).Create(&models.AuditLog{
@@ -316,7 +451,7 @@ func Serve(cmd *cobra.Command, args []string) error {
})
}
// 11. Comments
// 11. Comments & interactions
if len(seededContents) > 0 {
models.CommentQuery.WithContext(ctx).Create(&models.Comment{
TenantID: tenant.ID,
@@ -325,6 +460,80 @@ func Serve(cmd *cobra.Command, args []string) error {
Content: "好喜欢这段演出!",
Likes: 1,
})
models.UserContentActionQuery.WithContext(ctx).Create(&models.UserContentAction{
UserID: buyer.ID,
ContentID: seededContents[0].ID,
Type: "like",
})
models.UserContentActionQuery.WithContext(ctx).Create(&models.UserContentAction{
UserID: buyer.ID,
ContentID: seededContents[0].ID,
Type: "favorite",
})
media := &models.MediaAsset{
TenantID: tenant.ID,
UserID: creator.ID,
Type: consts.MediaAssetTypeVideo,
Status: consts.MediaAssetStatusReady,
Provider: "mock",
ObjectKey: "seed/video-demo.mp4",
Meta: types.NewJSONType(fields.MediaAssetMeta{
Size: 2048,
}),
}
models.MediaAssetQuery.WithContext(ctx).Create(media)
models.ContentAssetQuery.WithContext(ctx).Create(&models.ContentAsset{
TenantID: tenant.ID,
UserID: creator.ID,
ContentID: seededContents[0].ID,
AssetID: media.ID,
Role: consts.ContentAssetRoleMain,
})
}
// 12. Ledger & payout account
models.TenantLedgerQuery.WithContext(ctx).Create(&models.TenantLedger{
TenantID: tenant.ID,
UserID: creator.ID,
OrderID: 0,
Type: consts.TenantLedgerTypeDebitPurchase,
Amount: 990,
BalanceBefore: 0,
BalanceAfter: 990,
FrozenBefore: 0,
FrozenAfter: 0,
IdempotencyKey: uuid.NewString(),
Remark: "内容销售收入",
OperatorUserID: creator.ID,
BizRefType: "order",
BizRefID: 0,
})
models.PayoutAccountQuery.WithContext(ctx).Create(&models.PayoutAccount{
TenantID: tenant.ID,
UserID: creator.ID,
Type: consts.PayoutAccountTypeAlipay,
Name: "支付宝",
Account: "creator@example.com",
Realname: "梅派传人小林",
Status: consts.PayoutAccountStatusApproved,
ReviewedBy: superAdmin.ID,
ReviewedAt: time.Now().Add(-1 * time.Hour),
ReviewReason: "seed approved",
})
// 13. Balance anomaly user
negativeUser := &models.User{
Username: "negative",
Phone: "13800009998",
Nickname: "负余额用户",
Avatar: "https://api.dicebear.com/7.x/avataaars/svg?seed=Negative",
Balance: -100,
BalanceFrozen: -10,
Status: consts.UserStatusVerified,
Roles: types.Array[consts.Role]{consts.RoleUser},
}
if err := models.UserQuery.WithContext(ctx).Create(negativeUser); err != nil {
fmt.Printf("Create negative user failed: %v\n", err)
}
fmt.Println("Seed done.")