@@ -1061,14 +1061,14 @@ func TestHandler_AddOrganizationUser(t *testing.T) {
1061
1061
func TestHandler_RemoveOrganizationUser (t * testing.T ) {
1062
1062
tests := []struct {
1063
1063
name string
1064
- setup func (os * mocks.OrganizationService , us * mocks.UserService )
1064
+ setup func (os * mocks.OrganizationService , us * mocks.UserService , ds * mocks. CascadeDeleter )
1065
1065
req * frontierv1beta1.RemoveOrganizationUserRequest
1066
1066
want * frontierv1beta1.RemoveOrganizationUserResponse
1067
1067
wantErr error
1068
1068
}{
1069
1069
{
1070
1070
name : "should return internal error if org service return some error" ,
1071
- setup : func (os * mocks.OrganizationService , us * mocks.UserService ) {
1071
+ setup : func (os * mocks.OrganizationService , us * mocks.UserService , ds * mocks. CascadeDeleter ) {
1072
1072
os .EXPECT ().Get (mock .AnythingOfType ("*context.emptyCtx" ), testOrgID ).Return (organization.Organization {}, errors .New ("some error" ))
1073
1073
},
1074
1074
req : & frontierv1beta1.RemoveOrganizationUserRequest {
@@ -1080,12 +1080,12 @@ func TestHandler_RemoveOrganizationUser(t *testing.T) {
1080
1080
},
1081
1081
{
1082
1082
name : "should return the error and not remove user if it is the last admin user" ,
1083
- setup : func (os * mocks.OrganizationService , us * mocks.UserService ) {
1083
+ setup : func (os * mocks.OrganizationService , us * mocks.UserService , ds * mocks. CascadeDeleter ) {
1084
1084
os .EXPECT ().Get (mock .AnythingOfType ("*context.emptyCtx" ), testOrgID ).Return (testOrgMap [testOrgID ], nil )
1085
1085
us .EXPECT ().ListByOrg (mock .AnythingOfType ("*context.emptyCtx" ), testOrgID , "update" ).Return ([]user.User {
1086
1086
testUserMap [testUserID ],
1087
1087
}, nil )
1088
- os .EXPECT ().RemoveUsers (mock .AnythingOfType ("*context.emptyCtx" ), testOrgID , []string {testUserID }).Return (nil )
1088
+ ds .EXPECT ().RemoveUsersFromOrg (mock .AnythingOfType ("*context.emptyCtx" ), testOrgID , []string {testUserID }).Return (nil )
1089
1089
},
1090
1090
req : & frontierv1beta1.RemoveOrganizationUserRequest {
1091
1091
Id : testOrgID ,
@@ -1096,7 +1096,7 @@ func TestHandler_RemoveOrganizationUser(t *testing.T) {
1096
1096
},
1097
1097
{
1098
1098
name : "should remove user from org successfully" ,
1099
- setup : func (os * mocks.OrganizationService , us * mocks.UserService ) {
1099
+ setup : func (os * mocks.OrganizationService , us * mocks.UserService , ds * mocks. CascadeDeleter ) {
1100
1100
os .EXPECT ().Get (mock .AnythingOfType ("*context.emptyCtx" ), testOrgID ).Return (testOrgMap [testOrgID ], nil )
1101
1101
us .EXPECT ().ListByOrg (mock .AnythingOfType ("*context.emptyCtx" ), testOrgID , "update" ).Return ([]user.User {
1102
1102
testUserMap [testUserID ],
@@ -1110,7 +1110,7 @@ func TestHandler_RemoveOrganizationUser(t *testing.T) {
1110
1110
UpdatedAt : time.Time {},
1111
1111
},
1112
1112
}, nil )
1113
- os .EXPECT ().RemoveUsers (mock .AnythingOfType ("*context.emptyCtx" ), testOrgID , []string {"some-user-id" }).Return (nil )
1113
+ ds .EXPECT ().RemoveUsersFromOrg (mock .AnythingOfType ("*context.emptyCtx" ), testOrgID , []string {"some-user-id" }).Return (nil )
1114
1114
},
1115
1115
req : & frontierv1beta1.RemoveOrganizationUserRequest {
1116
1116
Id : testOrgID ,
@@ -1125,11 +1125,16 @@ func TestHandler_RemoveOrganizationUser(t *testing.T) {
1125
1125
t .Run (tt .name , func (t * testing.T ) {
1126
1126
mockOrgService := new (mocks.OrganizationService )
1127
1127
mockUserService := new (mocks.UserService )
1128
+ mockDeleterService := new (mocks.CascadeDeleter )
1128
1129
ctx := context .Background ()
1129
1130
if tt .setup != nil {
1130
- tt .setup (mockOrgService , mockUserService )
1131
+ tt .setup (mockOrgService , mockUserService , mockDeleterService )
1132
+ }
1133
+ mockDep := Handler {
1134
+ orgService : mockOrgService ,
1135
+ userService : mockUserService ,
1136
+ deleterService : mockDeleterService ,
1131
1137
}
1132
- mockDep := Handler {orgService : mockOrgService , userService : mockUserService }
1133
1138
got , err := mockDep .RemoveOrganizationUser (ctx , tt .req )
1134
1139
assert .EqualValues (t , tt .wantErr , err )
1135
1140
assert .EqualValues (t , tt .want , got )
0 commit comments