|
5 | 5 | import de.bogenliga.application.common.errorhandling.exception.BusinessException; |
6 | 6 | import de.bogenliga.application.services.v1.vereine.model.VereineDTO; |
7 | 7 | import de.bogenliga.application.springconfiguration.security.permissions.RequiresOnePermissionAspect; |
| 8 | +import de.bogenliga.application.springconfiguration.security.types.UserPermission; |
8 | 9 | import org.junit.Before; |
9 | 10 | import org.junit.Rule; |
10 | 11 | import org.junit.Test; |
@@ -247,6 +248,68 @@ public void updateNoPermission() { |
247 | 248 | .isThrownBy(()-> underTest.update(input, principal)); |
248 | 249 | } |
249 | 250 |
|
| 251 | + @Test |
| 252 | + public void update_sportleiter_darf_editierbare_felder_aendern() throws NoPermissionException { |
| 253 | + // prepare test data |
| 254 | + final VereineDTO input = getVereineDTO(); |
| 255 | + input.setWebsite("https://neu.de"); |
| 256 | + input.setDescription("Neue Beschreibung"); |
| 257 | + input.setIcon("neuesIcon"); |
| 258 | + |
| 259 | + final VereinDO existing = getVereinDO(); |
| 260 | + final VereinDO updated = getVereinDO(); |
| 261 | + updated.setWebsite("https://neu.de"); |
| 262 | + updated.setDescription("Neue Beschreibung"); |
| 263 | + updated.setIcon("neuesIcon"); |
| 264 | + |
| 265 | + // configure mocks |
| 266 | + when(requiresOnePermissionAspect.hasPermission(UserPermission.CAN_MODIFY_STAMMDATEN)).thenReturn(false); |
| 267 | + when(requiresOnePermissionAspect.hasPermission(UserPermission.CAN_MODIFY_STAMMDATEN_LIGALEITER)).thenReturn(false); |
| 268 | + when(requiresOnePermissionAspect.hasSpecificPermissionSportleiter(UserPermission.CAN_MODIFY_MY_VEREIN, VEREIN_ID)) |
| 269 | + .thenReturn(true); |
| 270 | + |
| 271 | + when(vereinComponent.findById(VEREIN_ID)).thenReturn(existing); |
| 272 | + when(vereinComponent.update(any(), anyLong())).thenReturn(updated); |
| 273 | + |
| 274 | + // act |
| 275 | + final VereineDTO actual = underTest.update(input, principal); |
| 276 | + |
| 277 | + // assert |
| 278 | + assertThat(actual).isNotNull(); |
| 279 | + verify(vereinComponent).update(vereinDOArgumentCaptor.capture(), anyLong()); |
| 280 | + |
| 281 | + final VereinDO updatedVerein = vereinDOArgumentCaptor.getValue(); |
| 282 | + assertThat(updatedVerein).isNotNull(); |
| 283 | + assertThat(updatedVerein.getWebsite()).isEqualTo("https://neu.de"); |
| 284 | + assertThat(updatedVerein.getDescription()).isEqualTo("Neue Beschreibung"); |
| 285 | + assertThat(updatedVerein.getIcon()).isEqualTo("neuesIcon"); |
| 286 | + } |
| 287 | + |
| 288 | + @Test |
| 289 | + public void update_sportleiter_darf_name_identifier_und_region_nicht_aendern() { |
| 290 | + // prepare test data |
| 291 | + final VereineDTO input = getVereineDTO(); |
| 292 | + input.setName("Neuer Vereinsname"); |
| 293 | + input.setIdentifier("NEU12345"); |
| 294 | + input.setRegionId(999L); |
| 295 | + |
| 296 | + final VereinDO existing = getVereinDO(); |
| 297 | + |
| 298 | + // configure mocks |
| 299 | + when(requiresOnePermissionAspect.hasPermission(UserPermission.CAN_MODIFY_STAMMDATEN)).thenReturn(false); |
| 300 | + when(requiresOnePermissionAspect.hasPermission(UserPermission.CAN_MODIFY_STAMMDATEN_LIGALEITER)).thenReturn(false); |
| 301 | + when(requiresOnePermissionAspect.hasSpecificPermissionSportleiter(UserPermission.CAN_MODIFY_MY_VEREIN, VEREIN_ID)) |
| 302 | + .thenReturn(true); |
| 303 | + |
| 304 | + when(vereinComponent.findById(VEREIN_ID)).thenReturn(existing); |
| 305 | + |
| 306 | + // assert |
| 307 | + assertThatExceptionOfType(NoPermissionException.class) |
| 308 | + .isThrownBy(() -> underTest.update(input, principal)); |
| 309 | + |
| 310 | + verify(vereinComponent).findById(VEREIN_ID); |
| 311 | + } |
| 312 | + |
250 | 313 |
|
251 | 314 | @Test |
252 | 315 | public void delete() { |
|
0 commit comments