tenant: add member management APIs
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"quyun/v2/app/commands/testx"
|
||||
"quyun/v2/database"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
"quyun/v2/pkg/utils"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
@@ -48,3 +49,52 @@ func (t *TenantTestSuite) Test_TenantUserCount() {
|
||||
t.T().Logf("%s", utils.MustJsonString(result))
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TenantTestSuite) Test_AddUser() {
|
||||
Convey("Tenant.AddUser", t.T(), func() {
|
||||
ctx := t.T().Context()
|
||||
tenantID := int64(1)
|
||||
userID := int64(2)
|
||||
|
||||
database.Truncate(ctx, t.DB, models.TableNameTenantUser)
|
||||
|
||||
Convey("首次添加成员成功", func() {
|
||||
err := Tenant.AddUser(ctx, tenantID, userID)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
m, err := Tenant.FindTenantUser(ctx, tenantID, userID)
|
||||
So(err, ShouldBeNil)
|
||||
So(m, ShouldNotBeNil)
|
||||
So(m.TenantID, ShouldEqual, tenantID)
|
||||
So(m.UserID, ShouldEqual, userID)
|
||||
})
|
||||
|
||||
Convey("重复添加应幂等返回成功", func() {
|
||||
So(Tenant.AddUser(ctx, tenantID, userID), ShouldBeNil)
|
||||
So(Tenant.AddUser(ctx, tenantID, userID), ShouldBeNil)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TenantTestSuite) Test_SetUserRole() {
|
||||
Convey("Tenant.SetUserRole", t.T(), func() {
|
||||
ctx := t.T().Context()
|
||||
tenantID := int64(1)
|
||||
userID := int64(2)
|
||||
|
||||
database.Truncate(ctx, t.DB, models.TableNameTenantUser)
|
||||
|
||||
So(Tenant.AddUser(ctx, tenantID, userID), ShouldBeNil)
|
||||
|
||||
Convey("设置为 tenant_admin 成功", func() {
|
||||
err := Tenant.SetUserRole(ctx, tenantID, userID, consts.TenantUserRoleTenantAdmin)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
m, err := Tenant.FindTenantUser(ctx, tenantID, userID)
|
||||
So(err, ShouldBeNil)
|
||||
So(m, ShouldNotBeNil)
|
||||
So(len(m.Role), ShouldEqual, 1)
|
||||
So(m.Role[0], ShouldEqual, consts.TenantUserRoleTenantAdmin)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user