Skip to content

Commit f7aebd8

Browse files
committed
Added test for unique Role per CRM Org
1 parent de04a7d commit f7aebd8

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

server/src/main/java/invite/repository/RoleRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ SELECT COUNT(r.id) FROM roles r WHERE r.organization_guid = ?1
9898

9999
Optional<Role> findByCrmRoleIdAndCrmOrganisationId(String crmRoleId, String crmOrganisationId);
100100

101+
List<Role> findByCrmRoleId(String crmRoleId);
102+
101103
@Override
102104
default String rewrite(String query, Sort sort) {
103105
Sort.Order userRoleCount = sort.getOrderFor("userRoleCount");

server/src/test/java/invite/crm/CRMControllerTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,57 @@ void deleteUser() throws JsonProcessingException {
273273
assertTrue(optionalUser.isEmpty());
274274
}
275275

276+
@Test
277+
void scopeInviteRoleToUniqueCRMRoleIdAndOrganizationId() throws JsonProcessingException {
278+
String converRoleId = "92b2b379-07e4-e811-8100-005056956c1a";
279+
CRMRole crmRole = new CRMRole(converRoleId, "CONVER", "SURFconextverantwoordelijke");
280+
String crmContactID = UUID.randomUUID().toString();
281+
String crmOrganisationID = UUID.randomUUID().toString();
282+
CRMContact crmContact = createCrmContact(crmContactID, crmOrganisationID, crmRole, "total", "new.com", true);
283+
//These applications are linked to the 'AAI' CRM role
284+
super.stubForManageProviderByEntityID(EntityType.OIDC10_RP, "https://cloud");
285+
//Ignore the SCIM provisioning
286+
super.stubForManageProvisioning(List.of());
287+
288+
String response = given()
289+
.when()
290+
.accept(ContentType.JSON)
291+
.header(API_KEY_HEADER, "secret")
292+
.contentType(ContentType.JSON)
293+
.body(crmContact)
294+
.post("/api/internal/v1/crm")
295+
.then()
296+
.extract()
297+
.asString();
298+
assertEquals("created", response);
299+
300+
User user = userRepository.findBySubIgnoreCase("urn:collab:person:new.com:total").get();
301+
assertEquals(1, user.getUserRoles().size());
302+
//Now post the same CRMContact for a different user, but the same role. Enusure the role is not re-used
303+
String newOrganisationID = UUID.randomUUID().toString();
304+
crmContact.setOrganisation(new CRMOrganisation(newOrganisationID,"abbrev","name"));
305+
crmContact.setUid("second_user");
306+
response = given()
307+
.when()
308+
.accept(ContentType.JSON)
309+
.header(API_KEY_HEADER, "secret")
310+
.contentType(ContentType.JSON)
311+
.body(crmContact)
312+
.post("/api/internal/v1/crm")
313+
.then()
314+
.extract()
315+
.asString();
316+
assertEquals("created", response);
317+
318+
user = userRepository.findBySubIgnoreCase("urn:collab:person:new.com:total").get();
319+
assertEquals(1, user.getUserRoles().size());
320+
321+
user = userRepository.findBySubIgnoreCase("urn:collab:person:new.com:second_user").get();
322+
assertEquals(1, user.getUserRoles().size());
323+
324+
List<Role> roles = roleRepository.findByCrmRoleId(converRoleId);
325+
assertEquals(2, roles.size());
326+
}
327+
328+
276329
}

0 commit comments

Comments
 (0)