From 050599d5d3284e27c63928690dbdbc9522abfa91 Mon Sep 17 00:00:00 2001 From: Febri Hidayan Date: Sat, 20 Jan 2024 18:14:53 +0700 Subject: [PATCH] add an ACL test tool --- go.mod | 2 +- .../acl/get_all_permission_by_role_test.go | 62 +++++++ .../usecases/acl/get_all_permission_test.go | 58 +++++++ .../usecases/acl/get_all_role_test.go | 58 +++++++ .../usecases/acl/get_all_user_test.go | 65 ++++++++ .../tests/internal/usecases/acl/init_test.go | 121 ++++++++++++++ .../acl/update_permission_by_role_test.go | 97 +++++++++++ .../internal/usecases/acl/update_user_test.go | 154 ++++++++++++++++++ .../mongo/permission_role_repository_mock.go | 11 +- .../mongo/permission_user_repository_mock.go | 10 ++ 10 files changed, 632 insertions(+), 6 deletions(-) create mode 100644 services/auth/tests/internal/usecases/acl/get_all_permission_by_role_test.go create mode 100644 services/auth/tests/internal/usecases/acl/get_all_permission_test.go create mode 100644 services/auth/tests/internal/usecases/acl/get_all_role_test.go create mode 100644 services/auth/tests/internal/usecases/acl/get_all_user_test.go create mode 100644 services/auth/tests/internal/usecases/acl/init_test.go create mode 100644 services/auth/tests/internal/usecases/acl/update_permission_by_role_test.go create mode 100644 services/auth/tests/internal/usecases/acl/update_user_test.go diff --git a/go.mod b/go.mod index 1c38b67..2c7df79 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/stretchr/testify v1.8.4 go.mongodb.org/mongo-driver v1.10.2 golang.org/x/crypto v0.17.0 + golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 google.golang.org/api v0.155.0 google.golang.org/grpc v1.60.1 google.golang.org/protobuf v1.31.0 @@ -75,7 +76,6 @@ require ( go.opentelemetry.io/otel v1.21.0 // indirect go.opentelemetry.io/otel/metric v1.21.0 // indirect go.opentelemetry.io/otel/trace v1.21.0 // indirect - golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 // indirect golang.org/x/net v0.19.0 // indirect golang.org/x/oauth2 v0.15.0 // indirect golang.org/x/sync v0.5.0 // indirect diff --git a/services/auth/tests/internal/usecases/acl/get_all_permission_by_role_test.go b/services/auth/tests/internal/usecases/acl/get_all_permission_by_role_test.go new file mode 100644 index 0000000..cc87466 --- /dev/null +++ b/services/auth/tests/internal/usecases/acl/get_all_permission_by_role_test.go @@ -0,0 +1,62 @@ +package acl + +import ( + "context" + "errors" + + "github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions" + "github.com/febrihidayan/go-architecture-monorepo/services/auth/domain/entities" + "github.com/hashicorp/go-multierror" + "github.com/stretchr/testify/mock" +) + +func (x *AclUsecaseSuite) TestGetAllPermissionByRole() { + var ( + permissionRoles []*entities.PermissionRole + permissions []*entities.Permission + ) + + permissionRoles = append(permissionRoles, x.permissionRole) + permissions = append(permissions, x.permission) + + args := []struct { + name string + args Any + tests func(arg Any) + }{ + { + name: "Success Positive Case", + tests: func(arg Any) { + x.permissionRoleRepo.Mock.On("AllByRoleId", x.id.String()).Return(permissionRoles, nil) + + x.permissionRepo.Mock.On("Find", x.permissionRole.PermissionId).Return(x.permission, nil) + + result, err := x.aclUsecase.GetAllPermissionByRole(context.Background(), x.id.String()) + x.Nil(err) + x.Equal(result, permissions) + }, + }, + { + name: "Failed Negatif Case", + tests: func(arg Any) { + x.permissionRoleRepo.Mock.On("AllByRoleId", x.id.String()).Return(nil, errors.New(mock.Anything)) + + _, err := x.aclUsecase.GetAllPermissionByRole(context.Background(), x.id.String()) + + e := &exceptions.CustomError{ + Status: exceptions.ERRREPOSITORY, + Errors: multierror.Append(errors.New(mock.Anything)), + } + + x.Equal(err, e) + }, + }, + } + + for _, arg := range args { + x.Run(arg.name, func() { + x.SetupTest() + arg.tests(arg.args) + }) + } +} diff --git a/services/auth/tests/internal/usecases/acl/get_all_permission_test.go b/services/auth/tests/internal/usecases/acl/get_all_permission_test.go new file mode 100644 index 0000000..4ddae45 --- /dev/null +++ b/services/auth/tests/internal/usecases/acl/get_all_permission_test.go @@ -0,0 +1,58 @@ +package acl + +import ( + "context" + "errors" + + "github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions" + "github.com/febrihidayan/go-architecture-monorepo/services/auth/domain/entities" + "github.com/hashicorp/go-multierror" + "github.com/stretchr/testify/mock" +) + +func (x *AclUsecaseSuite) TestGetAllPermission() { + var ( + permissions []*entities.Permission + ) + + permissions = append(permissions, x.permission) + + args := []struct { + name string + args Any + tests func(arg Any) + }{ + { + name: "Success Positive Case", + tests: func(arg Any) { + x.permissionRepo.Mock.On("All").Return(permissions, nil) + + result, err := x.aclUsecase.GetAllPermission(context.Background()) + x.Nil(err) + x.Equal(result, permissions) + }, + }, + { + name: "Failed Negatif Case", + tests: func(arg Any) { + x.permissionRepo.Mock.On("All").Return(nil, errors.New(mock.Anything)) + + _, err := x.aclUsecase.GetAllPermission(context.Background()) + + e := &exceptions.CustomError{ + Status: exceptions.ERRREPOSITORY, + Errors: multierror.Append(errors.New(mock.Anything)), + } + + x.Equal(err, e) + }, + }, + } + + for _, arg := range args { + x.Run(arg.name, func() { + x.SetupTest() + arg.tests(arg.args) + }) + } +} diff --git a/services/auth/tests/internal/usecases/acl/get_all_role_test.go b/services/auth/tests/internal/usecases/acl/get_all_role_test.go new file mode 100644 index 0000000..cbc13d9 --- /dev/null +++ b/services/auth/tests/internal/usecases/acl/get_all_role_test.go @@ -0,0 +1,58 @@ +package acl + +import ( + "context" + "errors" + + "github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions" + "github.com/febrihidayan/go-architecture-monorepo/services/auth/domain/entities" + "github.com/hashicorp/go-multierror" + "github.com/stretchr/testify/mock" +) + +func (x *AclUsecaseSuite) TestGetAllRole() { + var ( + roles []*entities.Role + ) + + roles = append(roles, x.role) + + args := []struct { + name string + args Any + tests func(arg Any) + }{ + { + name: "Success Positive Case", + tests: func(arg Any) { + x.roleRepo.Mock.On("All").Return(roles, nil) + + result, err := x.aclUsecase.GetAllRole(context.Background()) + x.Nil(err) + x.Equal(result, roles) + }, + }, + { + name: "Failed Negatif Case", + tests: func(arg Any) { + x.roleRepo.Mock.On("All").Return(nil, errors.New(mock.Anything)) + + _, err := x.aclUsecase.GetAllRole(context.Background()) + + e := &exceptions.CustomError{ + Status: exceptions.ERRREPOSITORY, + Errors: multierror.Append(errors.New(mock.Anything)), + } + + x.Equal(err, e) + }, + }, + } + + for _, arg := range args { + x.Run(arg.name, func() { + x.SetupTest() + arg.tests(arg.args) + }) + } +} diff --git a/services/auth/tests/internal/usecases/acl/get_all_user_test.go b/services/auth/tests/internal/usecases/acl/get_all_user_test.go new file mode 100644 index 0000000..73a3a14 --- /dev/null +++ b/services/auth/tests/internal/usecases/acl/get_all_user_test.go @@ -0,0 +1,65 @@ +package acl + +import ( + "context" + "errors" + + "github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions" + "github.com/febrihidayan/go-architecture-monorepo/services/auth/domain/entities" + "github.com/hashicorp/go-multierror" + "github.com/stretchr/testify/mock" +) + +func (x *AclUsecaseSuite) TestGetAllUser() { + var ( + roles []*entities.Role + permissions []*entities.Permission + ) + + roles = append(roles, x.role) + permissions = append(permissions, x.permission) + + args := []struct { + name string + args Any + tests func(arg Any) + }{ + { + name: "Success Positive Case", + tests: func(arg Any) { + x.authRepo.Mock.On("FindByUserId", x.id.String()).Return(x.auth, nil) + x.roleRepo.Mock.On("AllByUserId", x.id.String()).Return(roles, nil) + x.permissionRepo.Mock.On("AllByUserId", x.id.String()).Return(permissions, nil) + + result, err := x.aclUsecase.GetAllUser(context.Background(), x.id.String()) + x.Nil(err) + x.Equal(result, &entities.AclMeta{ + Permissions: permissions, + Roles: roles, + }) + }, + }, + { + name: "Failed Negatif Case", + tests: func(arg Any) { + x.authRepo.Mock.On("FindByUserId", x.id.String()).Return(nil, errors.New(mock.Anything)) + + _, err := x.aclUsecase.GetAllUser(context.Background(), x.id.String()) + + e := &exceptions.CustomError{ + Status: exceptions.ERRREPOSITORY, + Errors: multierror.Append(errors.New(mock.Anything)), + } + + x.Equal(err, e) + }, + }, + } + + for _, arg := range args { + x.Run(arg.name, func() { + x.SetupTest() + arg.tests(arg.args) + }) + } +} diff --git a/services/auth/tests/internal/usecases/acl/init_test.go b/services/auth/tests/internal/usecases/acl/init_test.go new file mode 100644 index 0000000..4ed57d4 --- /dev/null +++ b/services/auth/tests/internal/usecases/acl/init_test.go @@ -0,0 +1,121 @@ +package acl + +import ( + "testing" + "time" + + "bou.ke/monkey" + "github.com/febrihidayan/go-architecture-monorepo/pkg/common" + "github.com/febrihidayan/go-architecture-monorepo/pkg/middleware" + "github.com/febrihidayan/go-architecture-monorepo/pkg/utils" + "github.com/febrihidayan/go-architecture-monorepo/services/auth/domain/entities" + "github.com/febrihidayan/go-architecture-monorepo/services/auth/domain/usecases" + "github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/config" + "github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/repositories/factories" + "github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/usecases/acl" + mongo_repositories "github.com/febrihidayan/go-architecture-monorepo/services/auth/tests/mocks/repositories/mongo" + "github.com/google/uuid" + "github.com/stretchr/testify/suite" +) + +type AclUsecaseSuite struct { + suite.Suite + cfg *config.AuthConfig + mongoFactory *factories.MongoFactory + authRepo *mongo_repositories.AuthRepositoryMock + permissionRepo *mongo_repositories.PermissionRepositoryMock + permissionRoleRepo *mongo_repositories.PermissionRoleRepositoryMock + permissionUserRepo *mongo_repositories.PermissionUserRepositoryMock + roleRepo *mongo_repositories.RoleRepositoryMock + roleUserRepo *mongo_repositories.RoleUserRepositoryMock + aclUsecase usecases.AclUsecase + + role *entities.Role + roleUser *entities.RoleUser + permissionRole *entities.PermissionRole + permissionUser *entities.PermissionUser + permission *entities.Permission + auth *entities.Auth + id uuid.UUID +} + +func (x *AclUsecaseSuite) SetupTest() { + x.cfg = &config.AuthConfig{} + + x.authRepo = new(mongo_repositories.AuthRepositoryMock) + x.permissionRepo = new(mongo_repositories.PermissionRepositoryMock) + x.permissionRoleRepo = new(mongo_repositories.PermissionRoleRepositoryMock) + x.permissionUserRepo = new(mongo_repositories.PermissionUserRepositoryMock) + x.roleUserRepo = new(mongo_repositories.RoleUserRepositoryMock) + x.roleRepo = new(mongo_repositories.RoleRepositoryMock) + + x.mongoFactory = &factories.MongoFactory{ + AuthRepo: x.authRepo, + PermissionRepo: x.permissionRepo, + PermissionRoleRepo: x.permissionRoleRepo, + PermissionUserRepo: x.permissionUserRepo, + RoleUserRepo: x.roleUserRepo, + RoleRepo: x.roleRepo, + } + + x.aclUsecase = acl.NewAclInteractor(x.cfg, x.mongoFactory) + + // fake time now for testing + monkey.Patch(time.Now, func() time.Time { + return time.Date(2020, 1, 1, 1, 1, 1, 1, time.UTC) + }) + + // storage data + x.id, _ = common.StringToID("83f8619c-608c-4e5d-8941-3c394551085d") + + x.role = &entities.Role{ + ID: x.id, + Name: middleware.ROLE_SUPERADMINISTRATOR, + DisplayName: middleware.ROLE_SUPERADMINISTRATOR, + Description: middleware.ROLE_SUPERADMINISTRATOR, + CreatedAt: utils.TimeUTC(), + UpdatedAt: utils.TimeUTC(), + } + + x.roleUser = &entities.RoleUser{ + ID: x.id, + RoleId: x.id.String(), + UserId: x.id.String(), + } + + x.permission = &entities.Permission{ + ID: x.id, + Name: "users_create", + DisplayName: "users create", + Description: "users create", + CreatedAt: utils.TimeUTC(), + UpdatedAt: utils.TimeUTC(), + } + + x.permissionRole = &entities.PermissionRole{ + ID: x.id, + RoleId: x.id.String(), + PermissionId: x.id.String(), + } + + x.permissionUser = &entities.PermissionUser{ + ID: x.id, + UserId: x.id.String(), + PermissionId: x.id.String(), + } + + x.auth = &entities.Auth{ + ID: x.id, + UserId: x.id.String(), + } +} + +func TestAclUsecase(t *testing.T) { + suite.Run(t, new(AclUsecaseSuite)) +} + +type Any []interface{} + +func (a Any) Get(i int) interface{} { + return a[i] +} diff --git a/services/auth/tests/internal/usecases/acl/update_permission_by_role_test.go b/services/auth/tests/internal/usecases/acl/update_permission_by_role_test.go new file mode 100644 index 0000000..38fa0f9 --- /dev/null +++ b/services/auth/tests/internal/usecases/acl/update_permission_by_role_test.go @@ -0,0 +1,97 @@ +package acl + +import ( + "context" + "errors" + + "github.com/febrihidayan/go-architecture-monorepo/pkg/common" + "github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions" + "github.com/febrihidayan/go-architecture-monorepo/services/auth/domain/entities" + "github.com/hashicorp/go-multierror" + "github.com/stretchr/testify/mock" +) + +func (x *AclUsecaseSuite) TestUpdatePermissionByRole() { + var ( + newID = common.NewID() + newPermissionRoles []*entities.PermissionRole + permissionRoles []*entities.PermissionRole + deletes []string + ) + + payload := entities.AclPermissionDto{ + RoleId: x.role.ID.String(), + Permissions: []string{ + x.id.String(), + newID.String(), + }, + } + + payloadDeleteAll := entities.AclPermissionDto{ + RoleId: x.role.ID.String(), + Permissions: []string{}, + } + + deletes = []string{ + x.id.String(), + } + + newPermissionRoles = append(newPermissionRoles, entities.NewPermissionRole(entities.PermissionRoleDto{ + PermissionId: newID.String(), + RoleId: x.id.String(), + })) + + permissionRoles = append(permissionRoles, x.permissionRole) + + args := []struct { + name string + args Any + tests func(arg Any) + }{ + { + name: "Success Positive Case", + tests: func(arg Any) { + x.roleRepo.Mock.On("Find", x.id.String()).Return(x.role, nil) + x.permissionRoleRepo.Mock.On("AllByRoleId", x.role.ID.String()).Return(permissionRoles, nil) + x.permissionRoleRepo.Mock.On("CreateMany", newPermissionRoles).Return(nil) + x.permissionRoleRepo.Mock.On("DeleteByPermissionIds", deletes).Return(nil) + + err := x.aclUsecase.UpdatePermissionByRole(context.Background(), payload) + x.Nil(err) + }, + }, + { + name: "Success Delete Permissions Positive Case", + tests: func(arg Any) { + x.roleRepo.Mock.On("Find", x.id.String()).Return(x.role, nil) + x.permissionRoleRepo.Mock.On("AllByRoleId", x.role.ID.String()).Return(permissionRoles, nil) + x.permissionRoleRepo.Mock.On("DeleteByRoleId", x.role.ID.String()).Return(nil) + + err := x.aclUsecase.UpdatePermissionByRole(context.Background(), payloadDeleteAll) + x.Nil(err) + }, + }, + { + name: "Failed Find Role Negatif Case", + tests: func(arg Any) { + x.roleRepo.Mock.On("Find", x.id.String()).Return(nil, errors.New(mock.Anything)) + + err := x.aclUsecase.UpdatePermissionByRole(context.Background(), payload) + + e := &exceptions.CustomError{ + Status: exceptions.ERRREPOSITORY, + Errors: multierror.Append(errors.New(mock.Anything)), + } + + x.Equal(err, e) + }, + }, + } + + for _, arg := range args { + x.Run(arg.name, func() { + x.SetupTest() + arg.tests(arg.args) + }) + } +} diff --git a/services/auth/tests/internal/usecases/acl/update_user_test.go b/services/auth/tests/internal/usecases/acl/update_user_test.go new file mode 100644 index 0000000..b92d298 --- /dev/null +++ b/services/auth/tests/internal/usecases/acl/update_user_test.go @@ -0,0 +1,154 @@ +package acl + +import ( + "context" + "errors" + + "github.com/febrihidayan/go-architecture-monorepo/pkg/common" + "github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions" + "github.com/febrihidayan/go-architecture-monorepo/services/auth/domain/entities" + "github.com/hashicorp/go-multierror" + "github.com/stretchr/testify/mock" +) + +func (x *AclUsecaseSuite) TestUpdateUser() { + var ( + newID = common.NewID() + newPermissionUsers []*entities.PermissionUser + newRoleUsers []*entities.RoleUser + permissionUsers []*entities.PermissionUser + roleUsers []*entities.RoleUser + emptyDelete []string + ) + + payload := entities.AclUserDto{ + UserId: x.id.String(), + Permissions: []string{ + x.id.String(), + newID.String(), + }, + Roles: []string{ + x.id.String(), + newID.String(), + }, + } + + payloadChange := entities.AclUserDto{ + UserId: x.id.String(), + Permissions: []string{ + newID.String(), + }, + Roles: []string{ + newID.String(), + }, + } + + payloadDeleteAll := entities.AclUserDto{ + UserId: x.id.String(), + Permissions: []string{}, + Roles: []string{}, + } + + deleteChange := []string{ + x.id.String(), + } + + newPermissionUsers = append(newPermissionUsers, entities.NewPermissionUser(entities.PermissionUserDto{ + PermissionId: newID.String(), + UserId: x.id.String(), + })) + + newRoleUsers = append(newRoleUsers, entities.NewRoleUser(entities.RoleUserDto{ + RoleId: newID.String(), + UserId: x.id.String(), + })) + + permissionUsers = append(permissionUsers, x.permissionUser) + roleUsers = append(roleUsers, x.roleUser) + + args := []struct { + name string + args Any + tests func(arg Any) + }{ + { + name: "Success Positive Case", + tests: func(arg Any) { + x.authRepo.Mock.On("FindByUserId", x.id.String()).Return(x.auth, nil) + x.roleUserRepo.Mock.On("AllByUserId", x.auth.UserId).Return(roleUsers, nil) + x.permissionUserRepo.Mock.On("AllByUserId", x.auth.UserId).Return(permissionUsers, nil) + + // permission + x.permissionUserRepo.Mock.On("CreateMany", newPermissionUsers).Return(nil) + x.permissionUserRepo.Mock.On("DeleteByPermissionIds", emptyDelete).Return(nil) + x.permissionUserRepo.Mock.On("DeleteByUserId", x.auth.UserId).Return(nil) + + // role + x.roleUserRepo.Mock.On("CreateMany", newRoleUsers).Return(nil) + x.roleUserRepo.Mock.On("DeleteByRoleIds", emptyDelete).Return(nil) + x.roleUserRepo.Mock.On("DeleteByUserId", x.auth.UserId).Return(nil) + + err := x.aclUsecase.UpdateUser(context.Background(), payload) + x.Nil(err) + }, + }, + { + name: "Success Change Permissions and Roles Positive Case", + tests: func(arg Any) { + x.authRepo.Mock.On("FindByUserId", x.id.String()).Return(x.auth, nil) + x.roleUserRepo.Mock.On("AllByUserId", x.auth.UserId).Return(roleUsers, nil) + x.permissionUserRepo.Mock.On("AllByUserId", x.auth.UserId).Return(permissionUsers, nil) + + // permission + x.permissionUserRepo.Mock.On("CreateMany", newPermissionUsers).Return(nil) + x.permissionUserRepo.Mock.On("DeleteByPermissionIds", deleteChange).Return(nil) + x.permissionUserRepo.Mock.On("DeleteByUserId", x.auth.UserId).Return(nil) + + // role + x.roleUserRepo.Mock.On("CreateMany", newRoleUsers).Return(nil) + x.roleUserRepo.Mock.On("DeleteByRoleIds", deleteChange).Return(nil) + x.roleUserRepo.Mock.On("DeleteByUserId", x.auth.UserId).Return(nil) + + err := x.aclUsecase.UpdateUser(context.Background(), payloadChange) + x.Nil(err) + }, + }, + { + name: "Success Delete Permissions and Roles Positive Case", + tests: func(arg Any) { + x.authRepo.Mock.On("FindByUserId", x.id.String()).Return(x.auth, nil) + x.roleUserRepo.Mock.On("AllByUserId", x.auth.UserId).Return(roleUsers, nil) + x.permissionUserRepo.Mock.On("AllByUserId", x.auth.UserId).Return(permissionUsers, nil) + + // permission and delete + x.permissionUserRepo.Mock.On("DeleteByUserId", x.auth.UserId).Return(nil) + x.roleUserRepo.Mock.On("DeleteByUserId", x.auth.UserId).Return(nil) + + err := x.aclUsecase.UpdateUser(context.Background(), payloadDeleteAll) + x.Nil(err) + }, + }, + { + name: "Failed Find Auth Negatif Case", + tests: func(arg Any) { + x.authRepo.Mock.On("FindByUserId", x.id.String()).Return(nil, errors.New(mock.Anything)) + + err := x.aclUsecase.UpdateUser(context.Background(), payload) + + e := &exceptions.CustomError{ + Status: exceptions.ERRREPOSITORY, + Errors: multierror.Append(errors.New(mock.Anything)), + } + + x.Equal(err, e) + }, + }, + } + + for _, arg := range args { + x.Run(arg.name, func() { + x.SetupTest() + arg.tests(arg.args) + }) + } +} diff --git a/services/auth/tests/mocks/repositories/mongo/permission_role_repository_mock.go b/services/auth/tests/mocks/repositories/mongo/permission_role_repository_mock.go index 09b0121..ec4ef1b 100644 --- a/services/auth/tests/mocks/repositories/mongo/permission_role_repository_mock.go +++ b/services/auth/tests/mocks/repositories/mongo/permission_role_repository_mock.go @@ -35,8 +35,8 @@ func (x *PermissionRoleRepositoryMock) AllByRoleId(ctx context.Context, roleId s return } -func (x *PermissionRoleRepositoryMock) Delete(ctx context.Context, payload *entities.PermissionRole) (err error) { - args := x.Called(payload.RoleId, payload.PermissionId) +func (x *PermissionRoleRepositoryMock) DeleteByPermissionIds(ctx context.Context, ids []string) (err error) { + args := x.Called(ids) if n, ok := args.Get(0).(error); ok { err = n @@ -45,12 +45,13 @@ func (x *PermissionRoleRepositoryMock) Delete(ctx context.Context, payload *enti return } -func (x *PermissionRoleRepositoryMock) DeleteByPermissionIds(ctx context.Context, ids []string) (err error) { - args := x.Called(ids) + +func (x *PermissionRoleRepositoryMock) DeleteByRoleId(ctx context.Context, roleId string) (err error) { + args := x.Called(roleId) if n, ok := args.Get(0).(error); ok { err = n } return -} +} \ No newline at end of file diff --git a/services/auth/tests/mocks/repositories/mongo/permission_user_repository_mock.go b/services/auth/tests/mocks/repositories/mongo/permission_user_repository_mock.go index 30a0afc..0f5a1cb 100644 --- a/services/auth/tests/mocks/repositories/mongo/permission_user_repository_mock.go +++ b/services/auth/tests/mocks/repositories/mongo/permission_user_repository_mock.go @@ -44,3 +44,13 @@ func (x *PermissionUserRepositoryMock) DeleteByPermissionIds(ctx context.Context return } + +func (x *PermissionUserRepositoryMock) DeleteByUserId(ctx context.Context, userId string) (err error) { + args := x.Called(userId) + + if n, ok := args.Get(0).(error); ok { + err = n + } + + return +}