|
19 | 19 | import jakarta.mail.Address; |
20 | 20 | import org.junit.jupiter.api.Test; |
21 | 21 | import org.springframework.http.HttpStatus; |
| 22 | +import org.springframework.util.StringUtils; |
22 | 23 |
|
23 | 24 | import java.time.Instant; |
24 | 25 | import java.time.temporal.ChronoUnit; |
@@ -439,6 +440,9 @@ void deleteUser() throws JsonProcessingException { |
439 | 440 | super.remoteProvisionedGroupRepository.save(remoteProvisionedGroup); |
440 | 441 |
|
441 | 442 | User user = userRepository.findBySubIgnoreCase(KB_USER_SUB).get(); |
| 443 | + user.getUserRoles().removeIf(userRole -> !StringUtils.hasText(userRole.getRole().getCrmRoleId())); |
| 444 | + userRepository.save(user); |
| 445 | + |
442 | 446 | RemoteProvisionedUser remoteProvisionedUser = new RemoteProvisionedUser(user, UUID.randomUUID().toString(), "7"); |
443 | 447 | super.remoteProvisionedUserRepository.save(remoteProvisionedUser); |
444 | 448 | //Because of the PUT request of the change in the group, all users are fetched and checked if they exists in the remote SCIM |
@@ -467,6 +471,47 @@ void deleteUser() throws JsonProcessingException { |
467 | 471 | assertTrue(optionalUser.isEmpty()); |
468 | 472 | } |
469 | 473 |
|
| 474 | + @Test |
| 475 | + void deleteUserWithNativeInviteRoles() throws JsonProcessingException { |
| 476 | + CRMContact crmContact = new CRMContact(); |
| 477 | + crmContact.setContactId(CRM_CONTACT_ID); |
| 478 | + crmContact.setOrganisation(new CRMOrganisation(CRM_ORGANIZATION_ID, "abbr", "name")); |
| 479 | + |
| 480 | + stubForManageProvisioning(List.of("5")); |
| 481 | + Role role = roleRepository.findByName("Research").get(); |
| 482 | + RemoteProvisionedGroup remoteProvisionedGroup = new RemoteProvisionedGroup(role, UUID.randomUUID().toString(), "7"); |
| 483 | + super.remoteProvisionedGroupRepository.save(remoteProvisionedGroup); |
| 484 | + |
| 485 | + User user = userRepository.findBySubIgnoreCase(KB_USER_SUB).get(); |
| 486 | + RemoteProvisionedUser remoteProvisionedUser = new RemoteProvisionedUser(user, UUID.randomUUID().toString(), "7"); |
| 487 | + super.remoteProvisionedUserRepository.save(remoteProvisionedUser); |
| 488 | + //Because of the PUT request of the change in the group, all users are fetched and checked if they exists in the remote SCIM |
| 489 | + User guestUser = userRepository.findBySubIgnoreCase(GUEST_SUB).get(); |
| 490 | + RemoteProvisionedUser remoteProvisionedUserGuest = new RemoteProvisionedUser(guestUser, UUID.randomUUID().toString(), "7"); |
| 491 | + super.remoteProvisionedUserRepository.save(remoteProvisionedUserGuest); |
| 492 | + |
| 493 | + stubForUpdateScimRole(); |
| 494 | + stubForDeleteScimUser(); |
| 495 | + |
| 496 | + String response = given() |
| 497 | + .when() |
| 498 | + .accept(ContentType.JSON) |
| 499 | + .header(API_KEY_HEADER, "secret") |
| 500 | + .contentType(ContentType.JSON) |
| 501 | + .body(crmContact) |
| 502 | + .delete("/crm/profile") |
| 503 | + .then() |
| 504 | + .extract() |
| 505 | + .asString(); |
| 506 | + assertEquals("deleted", response); |
| 507 | + |
| 508 | + Organisation organisation = organisationRepository.findByCrmOrganisationId(CRM_ORGANIZATION_ID) |
| 509 | + .orElseThrow(() -> new NotFoundException("Organisation not found: " + CRM_ORGANIZATION_ID)); |
| 510 | + Optional<User> optionalUser = userRepository.findByCrmContactIdAndOrganisation(CRM_CONTACT_ID, organisation); |
| 511 | + assertFalse(optionalUser.isEmpty()); |
| 512 | + assertEquals(1, optionalUser.get().getUserRoles().size()); |
| 513 | + } |
| 514 | + |
470 | 515 | @Test |
471 | 516 | void scopeInviteRoleToUniqueCRMRoleIdAndOrganizationId() throws JsonProcessingException { |
472 | 517 | String converRoleId = "92b2b379-07e4-e811-8100-005056956c1a"; |
|
0 commit comments