@@ -112,7 +112,7 @@ void givenValidIdAndValidUpdateRequest_whenAllFieldsChanged_thenUpdateUser() {
112
112
Mockito .verify (userReadPort , Mockito .times (1 ))
113
113
.findById (Mockito .anyString ());
114
114
115
- Mockito .verify (identity , Mockito .times (mockRoles . size () + 1 ))
115
+ Mockito .verify (identity , Mockito .times (1 ))
116
116
.getInstitutionId ();
117
117
118
118
Mockito .verify (userReadPort , Mockito .times (1 ))
@@ -128,6 +128,78 @@ void givenValidIdAndValidUpdateRequest_whenAllFieldsChanged_thenUpdateUser() {
128
128
.save (Mockito .any (AysUser .class ));
129
129
}
130
130
131
+ @ Test
132
+ void givenValidIdAndValidUpdateRequest_whenRolesUpdatedOnly_thenUpdateUser () {
133
+
134
+ // Given
135
+ String mockId = "3c57d56b-4a97-4f70-86a9-b4c9235cbe13" ;
136
+
137
+ Set <String > mockRoleIds = Set .of (
138
+ "00a07704-8d7c-4048-b001-9fb69b22bfe8" ,
139
+ "7913e093-ae70-4029-ad8d-efbb21d79f26"
140
+ );
141
+ AysUserUpdateRequest mockUpdateRequest = new AysUserUpdateRequestBuilder ()
142
+ .withValidValues ()
143
+ .withRoleIds (mockRoleIds )
144
+ .build ();
145
+
146
+ // When
147
+ Institution mockInstitution = new InstitutionBuilder ()
148
+ .withValidValues ()
149
+ .build ();
150
+ Mockito .when (identity .getInstitutionId ())
151
+ .thenReturn (mockInstitution .getId ());
152
+
153
+ AysUser mockUser = new AysUserBuilder ()
154
+ .withValidValues ()
155
+ .withId (mockId )
156
+ .withFirstName (mockUpdateRequest .getFirstName ())
157
+ .withLastName (mockUpdateRequest .getLastName ())
158
+ .withEmailAddress (mockUpdateRequest .getEmailAddress ())
159
+ .withPhoneNumber (AysPhoneNumber .builder ().build ())
160
+ .withCity (mockUpdateRequest .getCity ())
161
+ .withRoles (List .of (
162
+ new AysRoleBuilder ()
163
+ .withValidValues ()
164
+ .build ()
165
+ ))
166
+ .withInstitution (mockInstitution )
167
+ .build ();
168
+ Mockito .when (userReadPort .findById (Mockito .anyString ()))
169
+ .thenReturn (Optional .of (mockUser ));
170
+
171
+ List <AysRole > mockRoles = new ArrayList <>();
172
+ mockUpdateRequest .getRoleIds ().forEach (roleId -> {
173
+ AysRole mockRole = new AysRoleBuilder ()
174
+ .withValidValues ()
175
+ .withId (roleId )
176
+ .withInstitution (mockInstitution )
177
+ .build ();
178
+ mockRoles .add (mockRole );
179
+ });
180
+ Mockito .when (roleReadPort .findAllByIds (Mockito .anySet ()))
181
+ .thenReturn (mockRoles );
182
+
183
+ Mockito .when (userSavePort .save (Mockito .any (AysUser .class )))
184
+ .thenReturn (Mockito .mock (AysUser .class ));
185
+
186
+ // Then
187
+ userUpdateService .update (mockId , mockUpdateRequest );
188
+
189
+ // Verify
190
+ Mockito .verify (userReadPort , Mockito .times (1 ))
191
+ .findById (Mockito .anyString ());
192
+
193
+ Mockito .verify (identity , Mockito .times (1 ))
194
+ .getInstitutionId ();
195
+
196
+ Mockito .verify (roleReadPort , Mockito .times (1 ))
197
+ .findAllByIds (Mockito .anySet ());
198
+
199
+ Mockito .verify (userSavePort , Mockito .times (1 ))
200
+ .save (Mockito .any (AysUser .class ));
201
+ }
202
+
131
203
@ Test
132
204
void givenValidIdAndValidUpdateRequest_whenPhoneNumberChanged_thenUpdateUser () {
133
205
@@ -566,7 +638,7 @@ void givenValidId_whenUserIsPassive_thenActivateUser() {
566
638
}
567
639
568
640
@ Test
569
- void givenValidId_whenUserNotFound_thenThrowAysUserNotExistByIdException (){
641
+ void givenValidId_whenUserNotFound_thenThrowAysUserNotExistByIdException () {
570
642
571
643
// Given
572
644
String mockId = "9f1eb072-7830-4c43-9a32-d77b62ccddd3" ;
@@ -593,7 +665,7 @@ void givenValidId_whenUserNotFound_thenThrowAysUserNotExistByIdException(){
593
665
}
594
666
595
667
@ Test
596
- void givenValidId_whenUserIsNotPassive_thenThrowAysUserIsNotPassiveException (){
668
+ void givenValidId_whenUserIsNotPassive_thenThrowAysUserIsNotPassiveException () {
597
669
598
670
// Given
599
671
String mockId = "bf7cc8d4-eab7-487d-8564-19be0f439b4a" ;
@@ -863,7 +935,7 @@ void givenValidId_whenUserIsActive_thenPassivateUser() {
863
935
}
864
936
865
937
@ Test
866
- void givenValidUserId_whenUserNotFound_thenThrowAysUserNotExistByIdException (){
938
+ void givenValidUserId_whenUserNotFound_thenThrowAysUserNotExistByIdException () {
867
939
868
940
// Given
869
941
String mockId = "9f1eb072-7830-4c43-9a32-d77b62ccddd3" ;
@@ -890,7 +962,7 @@ void givenValidUserId_whenUserNotFound_thenThrowAysUserNotExistByIdException(){
890
962
}
891
963
892
964
@ Test
893
- void givenValidId_whenUserIsNotActive_thenThrowAysUserNotActiveException (){
965
+ void givenValidId_whenUserIsNotActive_thenThrowAysUserNotActiveException () {
894
966
895
967
// Given
896
968
String mockId = "bf7cc8d4-eab7-487d-8564-19be0f439b4a" ;
0 commit comments