Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
hotfix: remove check user when update institution (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuraf committed Apr 29, 2024
1 parent 471b595 commit 3e03be9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,8 @@ public Optional<GeographicTaxonomies> retrieveGeoTaxonomies(String code) {

@Override
public Institution updateInstitution(String institutionId, InstitutionUpdate institutionUpdate, String userId) {
if (userService.checkIfInstitutionUser(userId, institutionId)) {
List<InstitutionGeographicTaxonomies> geographicTaxonomies = retrieveGeographicTaxonomies(institutionUpdate);
return institutionConnector.findAndUpdate(institutionId, null, geographicTaxonomies, institutionUpdate);
} else {
throw new ResourceForbiddenException(String.format(CustomError.RELATIONSHIP_NOT_FOUND.getMessage(), institutionId, userId, "admin roles"), CustomError.RELATIONSHIP_NOT_FOUND.getCode());
}
List<InstitutionGeographicTaxonomies> geographicTaxonomies = retrieveGeographicTaxonomies(institutionUpdate);
return institutionConnector.findAndUpdate(institutionId, null, geographicTaxonomies, institutionUpdate);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,6 @@ void updateInstitution_shouldThrowExceptionIfGeotaxNotFound() {
when(partyRegistryProxyConnector.getExtByCode(any()))
.thenThrow(new ResourceNotFoundException("An error occurred", "Code"));

when(userService.checkIfInstitutionUser(any(), any())).thenReturn(true);

ArrayList<InstitutionGeographicTaxonomies> institutionGeographicTaxonomiesList = new ArrayList<>();
institutionGeographicTaxonomiesList
.add(new InstitutionGeographicTaxonomies("Code", "The characteristics of someone or something"));
Expand All @@ -616,41 +614,6 @@ void updateInstitution_shouldThrowExceptionIfGeotaxNotFound() {
assertThrows(MsCoreException.class,
() -> institutionServiceImpl.updateInstitution("42", institutionUpdate, "42"));
verify(partyRegistryProxyConnector).getExtByCode(any());
verify(userService).checkIfInstitutionUser(any(), any());
}

/**
* Method under test: {@link InstitutionServiceImpl#updateInstitution(String, InstitutionUpdate, String)}
*/
@Test
void testUpdateInstitution7() {
when(userService.checkIfInstitutionUser(any(), any())).thenReturn(false);

ArrayList<InstitutionGeographicTaxonomies> institutionGeographicTaxonomiesList = new ArrayList<>();
institutionGeographicTaxonomiesList
.add(new InstitutionGeographicTaxonomies("Code", "The characteristics of someone or something"));

InstitutionUpdate institutionUpdate = new InstitutionUpdate();
institutionUpdate.setAddress("42 Main St");
institutionUpdate.setBusinessRegisterPlace("Business Register Place");
institutionUpdate
.setDataProtectionOfficer(new DataProtectionOfficer("42 Main St", "[email protected]", "Pec"));
institutionUpdate.setDescription("The characteristics of someone or something");
institutionUpdate.setDigitalAddress("42 Main St");
institutionUpdate.setGeographicTaxonomies(institutionGeographicTaxonomiesList);
institutionUpdate.setImported(true);
institutionUpdate.setInstitutionType(InstitutionType.PA);
institutionUpdate
.setPaymentServiceProvider(new PaymentServiceProvider("Abi Code", "42", "Legal Register Name", "42", true));
institutionUpdate.setRea("Rea");
institutionUpdate.setShareCapital("Share Capital");
institutionUpdate.setSupportEmail("[email protected]");
institutionUpdate.setSupportPhone("6625550144");
institutionUpdate.setTaxCode("Tax Code");
institutionUpdate.setZipCode("21654");
assertThrows(ResourceForbiddenException.class,
() -> institutionServiceImpl.updateInstitution("42", institutionUpdate, "42"));
verify(userService).checkIfInstitutionUser(any(), any());
}

/**
Expand Down Expand Up @@ -1303,17 +1266,10 @@ void testRetrieveInstitutionsWithFilter6() {

@Test
void testUpdateInstitutionDescription() {
when(userService.checkIfInstitutionUser(any(), any())).thenReturn(true);
when(institutionConnector.findAndUpdate(any(), any(), any(), any())).thenReturn(new Institution());
assertDoesNotThrow(() -> institutionServiceImpl.updateInstitution("42", new InstitutionUpdate(), "userId"));
}

@Test
void testUpdateInstitutionDescriptionException() {
when(userService.checkIfInstitutionUser(any(), any())).thenReturn(false);
assertThrows(ResourceForbiddenException.class, () -> institutionServiceImpl.updateInstitution("42", new InstitutionUpdate(), "userId"));
}

@Test
void updateCreatedAt() {
// Given
Expand Down

0 comments on commit 3e03be9

Please sign in to comment.