Skip to content

Commit

Permalink
fix: consultant agency deleted flag check
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuzynow committed Oct 18, 2024
1 parent f5ab90e commit 1e122b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public ConsultantAgencyResponseDTO findConsultantAgencies(String consultantId) {
public void appendAgenciesForConsultants(Set<ConsultantDTO> consultants) {
var consultantIds = consultants.stream().map(ConsultantDTO::getId).collect(Collectors.toSet());

var consultantAgencies = consultantAgencyRepository.findByConsultantIdIn(consultantIds);
var consultantAgencies =
consultantAgencyRepository.findByConsultantIdInAndDeleteDateIsNull(consultantIds);

var agencyIds =
consultantAgencies.stream().map(ConsultantAgency::getAgencyId).collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ ConsultantAgency findByConsultantIdAndAgencyIdAndStatusAndDeleteDateIsNull(

List<ConsultantAgency> findByConsultantIdIn(Set<String> consultantIds);

List<ConsultantAgency> findByConsultantIdInAndDeleteDateIsNull(Set<String> consultantIds);

@SuppressWarnings("all")
List<ConsultantAgencyBase> findByConsultantIdIn(List<String> consultantIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static org.mockito.Mockito.when;

import de.caritas.cob.userservice.api.adapters.web.dto.AgencyDTO;
import de.caritas.cob.userservice.api.adapters.web.dto.ConsultantDTO;
import de.caritas.cob.userservice.api.exception.httpresponses.CustomValidationHttpStatusException;
import de.caritas.cob.userservice.api.exception.httpresponses.InternalServerErrorException;
import de.caritas.cob.userservice.api.model.Consultant;
Expand All @@ -25,6 +26,7 @@
import de.caritas.cob.userservice.api.service.agency.AgencyService;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.jeasy.random.EasyRandom;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -137,6 +139,16 @@ public void removeConsultantsFromTeamSessionsByAgencyId_Should_changeTeamSession
});
}

@Test
void appendAgenciesForConsultants_Should_callConsultantAgencyRepositoryForNotDeletedEntries() {
ConsultantDTO consultantDTO = new EasyRandom().nextObject(ConsultantDTO.class);

this.consultantAgencyAdminService.appendAgenciesForConsultants(Set.of(consultantDTO));

verify(consultantAgencyRepository).findByConsultantIdInAndDeleteDateIsNull(any());
verify(agencyAdminService).retrieveAllAgencies();
}

@Test
public void
markConsultantAgencyForDeletion_Should_throwCustomValidationHttpStatusException_When_relationDoesNotExist() {
Expand Down

0 comments on commit 1e122b2

Please sign in to comment.