Refactor order and tenant ledger models to use consts for Currency and Type fields; add new UserStatus values; implement comprehensive test cases for content, creator, order, super, and wallet services.
This commit is contained in:
91
backend/app/services/super_test.go
Normal file
91
backend/app/services/super_test.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"testing"
|
||||
|
||||
"quyun/v2/app/commands/testx"
|
||||
super_dto "quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/database"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
"go.uber.org/dig"
|
||||
)
|
||||
|
||||
type SuperTestSuiteInjectParams struct {
|
||||
dig.In
|
||||
|
||||
DB *sql.DB
|
||||
Initials []contracts.Initial `group:"initials"`
|
||||
}
|
||||
|
||||
type SuperTestSuite struct {
|
||||
suite.Suite
|
||||
SuperTestSuiteInjectParams
|
||||
}
|
||||
|
||||
func Test_Super(t *testing.T) {
|
||||
providers := testx.Default().With(Provide)
|
||||
|
||||
testx.Serve(providers, t, func(p SuperTestSuiteInjectParams) {
|
||||
suite.Run(t, &SuperTestSuite{SuperTestSuiteInjectParams: p})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SuperTestSuite) Test_ListUsers() {
|
||||
Convey("ListUsers", s.T(), func() {
|
||||
ctx := s.T().Context()
|
||||
database.Truncate(ctx, s.DB, models.TableNameUser)
|
||||
|
||||
u1 := &models.User{Username: "user1", Nickname: "Alice"}
|
||||
u2 := &models.User{Username: "user2", Nickname: "Bob"}
|
||||
models.UserQuery.WithContext(ctx).Create(u1, u2)
|
||||
|
||||
Convey("should list users", func() {
|
||||
res, err := Super.ListUsers(ctx, 1, 10, "")
|
||||
So(err, ShouldBeNil)
|
||||
So(res.Total, ShouldEqual, 2)
|
||||
|
||||
items := res.Items.([]super_dto.UserItem)
|
||||
So(items[0].Username, ShouldEqual, "user2") // Desc order
|
||||
})
|
||||
|
||||
Convey("should filter users", func() {
|
||||
res, err := Super.ListUsers(ctx, 1, 10, "Alice")
|
||||
So(err, ShouldBeNil)
|
||||
So(res.Total, ShouldEqual, 1)
|
||||
items := res.Items.([]super_dto.UserItem)
|
||||
So(items[0].Username, ShouldEqual, "user1")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SuperTestSuite) Test_CreateTenant() {
|
||||
Convey("CreateTenant", s.T(), func() {
|
||||
ctx := s.T().Context()
|
||||
database.Truncate(ctx, s.DB, models.TableNameUser, models.TableNameTenant)
|
||||
|
||||
u := &models.User{Username: "admin1"}
|
||||
models.UserQuery.WithContext(ctx).Create(u)
|
||||
|
||||
Convey("should create tenant", func() {
|
||||
form := &super_dto.TenantCreateForm{
|
||||
Name: "Super Tenant",
|
||||
Code: "st1",
|
||||
AdminUserID: u.ID,
|
||||
}
|
||||
err := Super.CreateTenant(ctx, form)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
t, _ := models.TenantQuery.WithContext(ctx).Where(models.TenantQuery.Code.Eq("st1")).First()
|
||||
So(t, ShouldNotBeNil)
|
||||
So(t.Name, ShouldEqual, "Super Tenant")
|
||||
So(t.UserID, ShouldEqual, u.ID)
|
||||
So(t.Status, ShouldEqual, consts.TenantStatusVerified)
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user