feat: add super admin health review
This commit is contained in:
@@ -3,6 +3,7 @@ package services
|
||||
import (
|
||||
"database/sql"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/commands/testx"
|
||||
super_dto "quyun/v2/app/http/super/v1/dto"
|
||||
@@ -163,3 +164,158 @@ func (s *SuperTestSuite) Test_WithdrawalApproval() {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SuperTestSuite) Test_TenantHealth() {
|
||||
Convey("TenantHealth", s.T(), func() {
|
||||
ctx := s.T().Context()
|
||||
database.Truncate(
|
||||
ctx,
|
||||
s.DB,
|
||||
models.TableNameUser,
|
||||
models.TableNameTenant,
|
||||
models.TableNameTenantUser,
|
||||
models.TableNameContent,
|
||||
models.TableNameOrder,
|
||||
)
|
||||
|
||||
owner1 := &models.User{Username: "health_owner_1"}
|
||||
owner2 := &models.User{Username: "health_owner_2"}
|
||||
models.UserQuery.WithContext(ctx).Create(owner1, owner2)
|
||||
|
||||
tenant1 := &models.Tenant{
|
||||
UserID: owner1.ID,
|
||||
Name: "Health Tenant 1",
|
||||
Code: "health1",
|
||||
Status: consts.TenantStatusVerified,
|
||||
}
|
||||
tenant2 := &models.Tenant{
|
||||
UserID: owner2.ID,
|
||||
Name: "Health Tenant 2",
|
||||
Code: "health2",
|
||||
Status: consts.TenantStatusVerified,
|
||||
}
|
||||
models.TenantQuery.WithContext(ctx).Create(tenant1, tenant2)
|
||||
|
||||
models.TenantUserQuery.WithContext(ctx).Create(
|
||||
&models.TenantUser{TenantID: tenant1.ID, UserID: owner1.ID},
|
||||
&models.TenantUser{TenantID: tenant2.ID, UserID: owner2.ID},
|
||||
)
|
||||
|
||||
models.ContentQuery.WithContext(ctx).Create(
|
||||
&models.Content{
|
||||
TenantID: tenant1.ID,
|
||||
UserID: owner1.ID,
|
||||
Title: "Content H1",
|
||||
Status: consts.ContentStatusPublished,
|
||||
},
|
||||
&models.Content{
|
||||
TenantID: tenant2.ID,
|
||||
UserID: owner2.ID,
|
||||
Title: "Content H2",
|
||||
Status: consts.ContentStatusPublished,
|
||||
},
|
||||
)
|
||||
|
||||
now := time.Now()
|
||||
models.OrderQuery.WithContext(ctx).Create(
|
||||
&models.Order{
|
||||
TenantID: tenant1.ID,
|
||||
UserID: owner1.ID,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
AmountPaid: 1000,
|
||||
PaidAt: now,
|
||||
},
|
||||
&models.Order{
|
||||
TenantID: tenant2.ID,
|
||||
UserID: owner2.ID,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
AmountPaid: 1000,
|
||||
PaidAt: now,
|
||||
},
|
||||
&models.Order{
|
||||
TenantID: tenant2.ID,
|
||||
UserID: owner2.ID,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusRefunded,
|
||||
AmountPaid: 1000,
|
||||
UpdatedAt: now,
|
||||
},
|
||||
)
|
||||
|
||||
filter := &super_dto.TenantListFilter{
|
||||
Pagination: requests.Pagination{Page: 1, Limit: 10},
|
||||
}
|
||||
res, err := Super.TenantHealth(ctx, filter)
|
||||
So(err, ShouldBeNil)
|
||||
So(res.Total, ShouldEqual, 2)
|
||||
|
||||
items := res.Items.([]super_dto.TenantHealthItem)
|
||||
itemMap := make(map[int64]super_dto.TenantHealthItem, len(items))
|
||||
for _, item := range items {
|
||||
itemMap[item.TenantID] = item
|
||||
}
|
||||
|
||||
So(itemMap[tenant1.ID].PaidOrders, ShouldEqual, 1)
|
||||
So(itemMap[tenant1.ID].RefundOrders, ShouldEqual, 0)
|
||||
So(itemMap[tenant1.ID].HealthLevel, ShouldEqual, "healthy")
|
||||
|
||||
So(itemMap[tenant2.ID].PaidOrders, ShouldEqual, 1)
|
||||
So(itemMap[tenant2.ID].RefundOrders, ShouldEqual, 1)
|
||||
So(itemMap[tenant2.ID].HealthLevel, ShouldEqual, "risk")
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SuperTestSuite) Test_ContentReview() {
|
||||
Convey("ContentReview", s.T(), func() {
|
||||
ctx := s.T().Context()
|
||||
database.Truncate(ctx, s.DB, models.TableNameUser, models.TableNameTenant, models.TableNameContent)
|
||||
|
||||
admin := &models.User{Username: "review_admin"}
|
||||
owner := &models.User{Username: "review_owner"}
|
||||
models.UserQuery.WithContext(ctx).Create(admin, owner)
|
||||
|
||||
tenant := &models.Tenant{
|
||||
UserID: owner.ID,
|
||||
Name: "Review Tenant",
|
||||
Code: "review",
|
||||
Status: consts.TenantStatusVerified,
|
||||
}
|
||||
models.TenantQuery.WithContext(ctx).Create(tenant)
|
||||
|
||||
content := &models.Content{
|
||||
TenantID: tenant.ID,
|
||||
UserID: owner.ID,
|
||||
Title: "Review Content",
|
||||
Status: consts.ContentStatusReviewing,
|
||||
}
|
||||
models.ContentQuery.WithContext(ctx).Create(content)
|
||||
|
||||
err := Super.ReviewContent(ctx, admin.ID, content.ID, &super_dto.SuperContentReviewForm{
|
||||
Action: "approve",
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
reloaded, _ := models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(content.ID)).First()
|
||||
So(reloaded.Status, ShouldEqual, consts.ContentStatusPublished)
|
||||
So(reloaded.PublishedAt.IsZero(), ShouldBeFalse)
|
||||
|
||||
content2 := &models.Content{
|
||||
TenantID: tenant.ID,
|
||||
UserID: owner.ID,
|
||||
Title: "Review Content 2",
|
||||
Status: consts.ContentStatusReviewing,
|
||||
}
|
||||
models.ContentQuery.WithContext(ctx).Create(content2)
|
||||
|
||||
err = Super.ReviewContent(ctx, admin.ID, content2.ID, &super_dto.SuperContentReviewForm{
|
||||
Action: "reject",
|
||||
Reason: "Policy violation",
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
reloaded2, _ := models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(content2.ID)).First()
|
||||
So(reloaded2.Status, ShouldEqual, consts.ContentStatusBlocked)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user