feat: add super comment governance and finance oversight
This commit is contained in:
@@ -220,6 +220,122 @@ func (s *SuperTestSuite) Test_WithdrawalApproval() {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SuperTestSuite) Test_CommentGovernance() {
|
||||
Convey("Comment Governance", s.T(), func() {
|
||||
ctx := s.T().Context()
|
||||
database.Truncate(ctx, s.DB, models.TableNameComment, models.TableNameContent, models.TableNameTenant, models.TableNameUser)
|
||||
|
||||
owner := &models.User{Username: "owner_comment"}
|
||||
commenter := &models.User{Username: "commenter"}
|
||||
admin := &models.User{Username: "admin_comment"}
|
||||
models.UserQuery.WithContext(ctx).Create(owner, commenter, admin)
|
||||
|
||||
tenant := &models.Tenant{UserID: owner.ID, Code: "t-comment", Name: "Comment Tenant", Status: consts.TenantStatusVerified}
|
||||
models.TenantQuery.WithContext(ctx).Create(tenant)
|
||||
|
||||
content := &models.Content{
|
||||
TenantID: tenant.ID,
|
||||
UserID: owner.ID,
|
||||
Title: "Comment Content",
|
||||
Description: "Desc",
|
||||
}
|
||||
models.ContentQuery.WithContext(ctx).Create(content)
|
||||
|
||||
Convey("should list comments", func() {
|
||||
comment := &models.Comment{
|
||||
TenantID: tenant.ID,
|
||||
UserID: commenter.ID,
|
||||
ContentID: content.ID,
|
||||
Content: "Nice work",
|
||||
}
|
||||
models.CommentQuery.WithContext(ctx).Create(comment)
|
||||
|
||||
filter := &super_dto.SuperCommentListFilter{
|
||||
Pagination: requests.Pagination{Page: 1, Limit: 10},
|
||||
}
|
||||
res, err := Super.ListComments(ctx, filter)
|
||||
So(err, ShouldBeNil)
|
||||
So(res.Total, ShouldEqual, 1)
|
||||
items := res.Items.([]super_dto.SuperCommentItem)
|
||||
So(items[0].ContentTitle, ShouldEqual, "Comment Content")
|
||||
So(items[0].Username, ShouldEqual, commenter.Username)
|
||||
})
|
||||
|
||||
Convey("should delete comment", func() {
|
||||
comment := &models.Comment{
|
||||
TenantID: tenant.ID,
|
||||
UserID: commenter.ID,
|
||||
ContentID: content.ID,
|
||||
Content: "Spam content",
|
||||
}
|
||||
models.CommentQuery.WithContext(ctx).Create(comment)
|
||||
|
||||
err := Super.DeleteComment(ctx, admin.ID, comment.ID, &super_dto.SuperCommentDeleteForm{Reason: "spam"})
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
deleted, err := models.CommentQuery.WithContext(ctx).Unscoped().Where(models.CommentQuery.ID.Eq(comment.ID)).First()
|
||||
So(err, ShouldBeNil)
|
||||
So(deleted.DeletedAt.Valid, ShouldBeTrue)
|
||||
|
||||
filter := &super_dto.SuperCommentListFilter{
|
||||
Pagination: requests.Pagination{Page: 1, Limit: 10},
|
||||
}
|
||||
res, err := Super.ListComments(ctx, filter)
|
||||
So(err, ShouldBeNil)
|
||||
So(res.Total, ShouldEqual, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SuperTestSuite) Test_FinanceAnomalies() {
|
||||
Convey("Finance Anomalies", s.T(), func() {
|
||||
ctx := s.T().Context()
|
||||
database.Truncate(ctx, s.DB, models.TableNameOrder, models.TableNameTenant, models.TableNameUser)
|
||||
|
||||
user := &models.User{Username: "finance_user", Balance: -100}
|
||||
models.UserQuery.WithContext(ctx).Create(user)
|
||||
|
||||
tenant := &models.Tenant{UserID: user.ID, Code: "t-fin", Name: "Finance Tenant", Status: consts.TenantStatusVerified}
|
||||
models.TenantQuery.WithContext(ctx).Create(tenant)
|
||||
|
||||
order := &models.Order{
|
||||
TenantID: tenant.ID,
|
||||
UserID: user.ID,
|
||||
Type: consts.OrderTypeRecharge,
|
||||
Status: consts.OrderStatusPaid,
|
||||
AmountOriginal: 100,
|
||||
AmountDiscount: 0,
|
||||
AmountPaid: 100,
|
||||
IdempotencyKey: "anomaly-paid",
|
||||
}
|
||||
models.OrderQuery.WithContext(ctx).Create(order)
|
||||
|
||||
Convey("should list balance anomalies", func() {
|
||||
filter := &super_dto.SuperBalanceAnomalyFilter{
|
||||
Pagination: requests.Pagination{Page: 1, Limit: 10},
|
||||
}
|
||||
res, err := Super.ListBalanceAnomalies(ctx, filter)
|
||||
So(err, ShouldBeNil)
|
||||
So(res.Total, ShouldEqual, 1)
|
||||
items := res.Items.([]super_dto.SuperBalanceAnomalyItem)
|
||||
So(items[0].UserID, ShouldEqual, user.ID)
|
||||
So(items[0].Issue, ShouldEqual, "negative_balance")
|
||||
})
|
||||
|
||||
Convey("should list order anomalies", func() {
|
||||
filter := &super_dto.SuperOrderAnomalyFilter{
|
||||
Pagination: requests.Pagination{Page: 1, Limit: 10},
|
||||
}
|
||||
res, err := Super.ListOrderAnomalies(ctx, filter)
|
||||
So(err, ShouldBeNil)
|
||||
So(res.Total, ShouldEqual, 1)
|
||||
items := res.Items.([]super_dto.SuperOrderAnomalyItem)
|
||||
So(items[0].OrderID, ShouldEqual, order.ID)
|
||||
So(items[0].Issue, ShouldEqual, "missing_paid_at")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SuperTestSuite) Test_TenantHealth() {
|
||||
Convey("TenantHealth", s.T(), func() {
|
||||
ctx := s.T().Context()
|
||||
|
||||
Reference in New Issue
Block a user