@@ -1142,6 +1142,50 @@ void sendInvitationUnknownOrganisation() {
11421142 .statusCode (HttpStatus .NOT_FOUND .value ());
11431143 }
11441144
1145+ @ Test
1146+ void contactDeduplicateRoles () throws JsonProcessingException {
1147+ CRMRole crmRole = new CRMRole ("roleId" , "BVW" , "Super" );
1148+ CRMRole duplicateRole = new CRMRole ("roleId" , "BVW" , "Super" );
1149+ String crmContactID = UUID .randomUUID ().toString ();
1150+ String crmOrganisationID = UUID .randomUUID ().toString ();
1151+ CRMContact crmContact = new CRMContact (
1152+ "new_user" ,
1153+ "hardewijk.org" ,
1154+ true ,
1155+ crmContactID ,
1156+ "John" ,
1157+ "from" ,
1158+ "Doe" ,
1159+ "jdoe@example.com" ,
1160+ new CRMOrganisation (crmOrganisationID , "abbrec" , "Inc. Corporated" ),
1161+ List .of (crmRole , duplicateRole , duplicateRole )
1162+ );
1163+
1164+ stubForManageProviderByEntityID (EntityType .OIDC10_RP , "https://calendar" );
1165+ stubForManageProviderByEntityID (EntityType .SAML20_SP , "https://storage" );
1166+ stubForManageProvisioning (List .of ("5" ));
1167+ stubForCreateScimRole ();
1168+ stubForCreateScimUser ();
1169+ stubForUpdateScimRole ();
1170+
1171+ String response = given ()
1172+ .when ()
1173+ .accept (ContentType .JSON )
1174+ .header (API_KEY_HEADER , "secret" )
1175+ .contentType (ContentType .JSON )
1176+ .body (crmContact )
1177+ .post ("/crm/profile" )
1178+ .then ()
1179+ .extract ()
1180+ .asString ();
1181+ assertEquals ("created" , response );
1182+
1183+ Organisation organisation = organisationRepository .findByCrmOrganisationId (crmOrganisationID )
1184+ .orElseThrow (() -> new NotFoundException ("Organisation not found: " + crmOrganisationID ));
1185+ User user = userRepository .findByCrmContactIdAndOrganisation (crmContactID , organisation ).get ();
1186+ assertEquals (1 , user .getUserRoles ().size ());
1187+ }
1188+
11451189 private void seedCRMData () {
11461190 Organisation organisation = organisationRepository .findByCrmOrganisationId (CRM_ORGANIZATION_ID ).get ();
11471191 Role role = new Role ();
0 commit comments