tenant: extend admin order filters
This commit is contained in:
@@ -397,6 +397,238 @@ func (s *OrderTestSuite) Test_AdminOrderPage() {
|
||||
So(pager.Total, ShouldEqual, 1)
|
||||
})
|
||||
|
||||
Convey("按 username 关键字过滤", func() {
|
||||
s.truncate(ctx, models.TableNameOrderItem, models.TableNameOrder, models.TableNameUser)
|
||||
|
||||
u1 := &models.User{
|
||||
Username: "alice",
|
||||
Password: "x",
|
||||
Roles: types.NewArray([]consts.Role{consts.RoleUser}),
|
||||
Status: consts.UserStatusVerified,
|
||||
Metas: types.JSON([]byte("{}")),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(u1.Create(ctx), ShouldBeNil)
|
||||
u2 := &models.User{
|
||||
Username: "bob",
|
||||
Password: "x",
|
||||
Roles: types.NewArray([]consts.Role{consts.RoleUser}),
|
||||
Status: consts.UserStatusVerified,
|
||||
Metas: types.JSON([]byte("{}")),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(u2.Create(ctx), ShouldBeNil)
|
||||
|
||||
o1 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: u1.ID,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(o1.Create(ctx), ShouldBeNil)
|
||||
o2 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: u2.ID,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(o2.Create(ctx), ShouldBeNil)
|
||||
|
||||
username := "ali"
|
||||
pager, err := Order.AdminOrderPage(ctx, tenantID, &dto.AdminOrderListFilter{
|
||||
Username: &username,
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
So(pager.Total, ShouldEqual, 1)
|
||||
items, ok := pager.Items.([]*models.Order)
|
||||
So(ok, ShouldBeTrue)
|
||||
So(items[0].UserID, ShouldEqual, u1.ID)
|
||||
})
|
||||
|
||||
Convey("按 content_title 关键字过滤", func() {
|
||||
s.truncate(ctx, models.TableNameOrderItem, models.TableNameOrder, models.TableNameContent)
|
||||
|
||||
c1 := &models.Content{
|
||||
TenantID: tenantID,
|
||||
UserID: 1,
|
||||
Title: "Go 教程",
|
||||
Description: "desc",
|
||||
Status: consts.ContentStatusPublished,
|
||||
Visibility: consts.ContentVisibilityTenantOnly,
|
||||
PreviewSeconds: consts.DefaultContentPreviewSeconds,
|
||||
PreviewDownloadable: false,
|
||||
PublishedAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(c1.Create(ctx), ShouldBeNil)
|
||||
c2 := &models.Content{
|
||||
TenantID: tenantID,
|
||||
UserID: 1,
|
||||
Title: "Rust 教程",
|
||||
Description: "desc",
|
||||
Status: consts.ContentStatusPublished,
|
||||
Visibility: consts.ContentVisibilityTenantOnly,
|
||||
PreviewSeconds: consts.DefaultContentPreviewSeconds,
|
||||
PreviewDownloadable: false,
|
||||
PublishedAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(c2.Create(ctx), ShouldBeNil)
|
||||
|
||||
o1 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: 2,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(o1.Create(ctx), ShouldBeNil)
|
||||
So((&models.OrderItem{
|
||||
TenantID: tenantID,
|
||||
UserID: 2,
|
||||
OrderID: o1.ID,
|
||||
ContentID: c1.ID,
|
||||
ContentUserID: 1,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}).Create(ctx), ShouldBeNil)
|
||||
|
||||
o2 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: 3,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(o2.Create(ctx), ShouldBeNil)
|
||||
So((&models.OrderItem{
|
||||
TenantID: tenantID,
|
||||
UserID: 3,
|
||||
OrderID: o2.ID,
|
||||
ContentID: c2.ID,
|
||||
ContentUserID: 1,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}).Create(ctx), ShouldBeNil)
|
||||
|
||||
title := "Go"
|
||||
pager, err := Order.AdminOrderPage(ctx, tenantID, &dto.AdminOrderListFilter{
|
||||
ContentTitle: &title,
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
So(pager.Total, ShouldEqual, 1)
|
||||
})
|
||||
|
||||
Convey("按 created_at 时间窗过滤", func() {
|
||||
s.truncate(ctx, models.TableNameOrderItem, models.TableNameOrder)
|
||||
|
||||
o1 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: 2,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now.Add(-time.Hour),
|
||||
UpdatedAt: now.Add(-time.Hour),
|
||||
}
|
||||
So(o1.Create(ctx), ShouldBeNil)
|
||||
|
||||
o2 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: 3,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 200,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(o2.Create(ctx), ShouldBeNil)
|
||||
|
||||
from := now.Add(-10 * time.Minute)
|
||||
to := now.Add(10 * time.Minute)
|
||||
pager, err := Order.AdminOrderPage(ctx, tenantID, &dto.AdminOrderListFilter{
|
||||
CreatedAtFrom: &from,
|
||||
CreatedAtTo: &to,
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
So(pager.Total, ShouldEqual, 1)
|
||||
})
|
||||
|
||||
Convey("按 type 过滤", func() {
|
||||
s.truncate(ctx, models.TableNameOrderItem, models.TableNameOrder)
|
||||
|
||||
o1 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: 2,
|
||||
Type: consts.OrderTypeTopup,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(o1.Create(ctx), ShouldBeNil)
|
||||
|
||||
o2 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: 3,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 200,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(o2.Create(ctx), ShouldBeNil)
|
||||
|
||||
typ := consts.OrderTypeTopup
|
||||
pager, err := Order.AdminOrderPage(ctx, tenantID, &dto.AdminOrderListFilter{
|
||||
Type: &typ,
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
So(pager.Total, ShouldEqual, 1)
|
||||
})
|
||||
|
||||
Convey("组合筛选:user_id + status + amount_paid 区间 + content_id", func() {
|
||||
s.truncate(ctx, models.TableNameOrderItem, models.TableNameOrder)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user