tenant: admin order export csv
This commit is contained in:
@@ -827,6 +827,56 @@ func (s *OrderTestSuite) Test_AdminOrderDetail() {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *OrderTestSuite) Test_AdminOrderExportCSV() {
|
||||
Convey("Order.AdminOrderExportCSV", s.T(), func() {
|
||||
ctx := s.T().Context()
|
||||
now := time.Now().UTC()
|
||||
tenantID := int64(1)
|
||||
|
||||
s.truncate(ctx, models.TableNameOrderItem, models.TableNameOrder, models.TableNameUser, models.TableNameContent)
|
||||
|
||||
Convey("参数非法应返回错误", func() {
|
||||
_, err := Order.AdminOrderExportCSV(ctx, 0, &dto.AdminOrderListFilter{})
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("导出应返回 CSV 且包含表头", func() {
|
||||
u := &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(u.Create(ctx), ShouldBeNil)
|
||||
|
||||
o := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: u.ID,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 123,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(o.Create(ctx), ShouldBeNil)
|
||||
|
||||
resp, err := Order.AdminOrderExportCSV(ctx, tenantID, &dto.AdminOrderListFilter{})
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.ContentType, ShouldEqual, "text/csv")
|
||||
So(resp.Filename, ShouldContainSubstring, "tenant_1_orders_")
|
||||
So(resp.CSV, ShouldContainSubstring, "id,tenant_id,user_id,type,status,amount_paid,paid_at,created_at")
|
||||
So(resp.CSV, ShouldContainSubstring, "content_purchase")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *OrderTestSuite) Test_AdminRefundOrder() {
|
||||
Convey("Order.AdminRefundOrder", s.T(), func() {
|
||||
ctx := s.T().Context()
|
||||
|
||||
Reference in New Issue
Block a user