feat: add user_tenant associations
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"quyun/v2/database"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
"quyun/v2/pkg/utils"
|
||||
|
||||
"github.com/samber/lo"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
@@ -200,3 +201,62 @@ func (t *UserTestSuite) Test_Page() {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (t *UserTestSuite) Test_Relations() {
|
||||
Convey("test page", t.T(), func() {
|
||||
// database.Truncate(
|
||||
// t.T().Context(),
|
||||
// t.DB,
|
||||
// models.TableNameUser,
|
||||
// models.TableNameTenant,
|
||||
// models.TableNameTenantUser,
|
||||
// )
|
||||
|
||||
// username := "test-user"
|
||||
// mUser01 := &models.User{
|
||||
// Username: username,
|
||||
// Password: "test-password",
|
||||
// Roles: types.NewArray([]consts.Role{consts.RoleUser}),
|
||||
// Status: consts.UserStatusPendingVerify,
|
||||
// }
|
||||
|
||||
// err := mUser01.Create(t.T().Context())
|
||||
// So(err, ShouldBeNil)
|
||||
|
||||
// tenantModel := &models.Tenant{
|
||||
// UserID: 1,
|
||||
// Code: "abc",
|
||||
// UUID: types.NewUUIDv4(),
|
||||
// Name: "T01",
|
||||
// Status: consts.TenantStatusVerified,
|
||||
// }
|
||||
|
||||
// err = tenantModel.Create(t.T().Context())
|
||||
// So(err, ShouldBeNil)
|
||||
|
||||
// count := 10
|
||||
// for i := 0; i < count; i++ {
|
||||
// mUser := &models.User{
|
||||
// Username: fmt.Sprintf("user_%d", i),
|
||||
// Password: "test-password",
|
||||
// Roles: types.NewArray([]consts.Role{consts.RoleUser}),
|
||||
// Status: consts.UserStatusPendingVerify,
|
||||
// }
|
||||
|
||||
// err = mUser.Create(t.T().Context())
|
||||
// So(err, ShouldBeNil)
|
||||
|
||||
// // create tenant user
|
||||
// err = Tenant.AddUser(t.T().Context(), 1, mUser.ID)
|
||||
// So(err, ShouldBeNil)
|
||||
// }
|
||||
|
||||
Convey("filter tenant users", func() {
|
||||
m, err := User.FindByID(t.T().Context(), 1)
|
||||
So(err, ShouldBeNil)
|
||||
// So(m.OwnedTenant, ShouldNotBeNil)
|
||||
// So(m.Tenants, ShouldHaveLength, 10)
|
||||
t.T().Logf("%s", utils.MustJsonString(m))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user