Skip to content

Commit

Permalink
feat: CARITAS-286
Browse files Browse the repository at this point in the history
* add it tests for new getAgenciesTopics method
  • Loading branch information
Leandro13Silva13 committed Oct 28, 2024
1 parent 5c76bcf commit edbffa1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public ResponseEntity<List<AgencyTopicsDTO>> getAgenciesTopics() {
var topics = this.agencyService.getAgenciesTopics();
var enrichedTopics = topicEnrichmentService.enrichTopicIdsWithTopicData(topics);

return enrichedTopics.isEmpty() ? new ResponseEntity<>(HttpStatus.NOT_FOUND)
return enrichedTopics.isEmpty() ? new ResponseEntity<>(HttpStatus.NO_CONTENT)
: new ResponseEntity<>(enrichedTopics, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import static de.caritas.cob.agencyservice.testHelper.PathConstants.PATH_GET_AGENCIES_WITH_IDS;
import static de.caritas.cob.agencyservice.testHelper.PathConstants.PATH_GET_LIST_OF_AGENCIES;
import static de.caritas.cob.agencyservice.testHelper.PathConstants.PATH_GET_LIST_OF_AGENCIES_TOPICS;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.AGENCY_ID;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.AGENCY_RESPONSE_DTO;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.AGENCY_RESPONSE_DTO_LIST;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.AGENCY_TOPICS_DTO;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.FULL_AGENCY_RESPONSE_DTO;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.INVALID_AGENCY_ID;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.INVALID_CONSULTING_TYPE_QUERY;
Expand All @@ -23,6 +25,7 @@

import de.caritas.cob.agencyservice.api.authorization.RoleAuthorizationAuthorityMapper;
import de.caritas.cob.agencyservice.api.exception.httpresponses.InternalServerErrorException;
import de.caritas.cob.agencyservice.api.model.AgencyTopicsDTO;
import de.caritas.cob.agencyservice.api.model.FullAgencyResponseDTO;
import de.caritas.cob.agencyservice.api.service.AgencyService;
import de.caritas.cob.agencyservice.api.service.LogService;
Expand Down Expand Up @@ -250,4 +253,32 @@ void getAgenciesByConsultingType_Should_ReturnOk_When_consultingTypeIsValid()
.andExpect(status().isOk());
}

@Test
void getAgenciesTopics_Should_ReturnNoContent_When_ServiceReturnsEmptyList() throws Exception {

when(agencyService.getAgenciesTopics())
.thenReturn(null);

mvc.perform(
get(PATH_GET_LIST_OF_AGENCIES_TOPICS)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNoContent());
}

@Test
void getAgenciesTopics_Should_ReturnListAndOk_When_ServiceReturnsList() throws Exception {

List<AgencyTopicsDTO> agenciesTopics = new ArrayList<>();
agenciesTopics.add(AGENCY_TOPICS_DTO);

when(topicEnrichmentService.enrichTopicIdsWithTopicData(Mockito.anyList()))
.thenReturn(agenciesTopics);

mvc.perform(
get(PATH_GET_LIST_OF_AGENCIES_TOPICS))
.andExpect(status().isOk());

verify(topicEnrichmentService, atLeastOnce()).enrichTopicIdsWithTopicData(Mockito.anyList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class PathConstants {
public static final String PAGE_PARAM = "page";
public static final String PER_PAGE_PARAM = "perPage";
public static final String PATH_GET_LIST_OF_AGENCIES = "/agencies";
public static final String PATH_GET_LIST_OF_AGENCIES_TOPICS = "/agencies/topics";
public static final String PATH_GET_AGENCIES_WITH_IDS = "/agencies/";
public static final String GET_AGENCY_PATH = ROOT_PATH + "/agencies";
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.caritas.cob.agencyservice.api.manager.consultingtype.registration.Registration;
import de.caritas.cob.agencyservice.api.manager.consultingtype.whiteSpot.WhiteSpot;
import de.caritas.cob.agencyservice.api.model.AgencyResponseDTO;
import de.caritas.cob.agencyservice.api.model.AgencyTopicsDTO;
import de.caritas.cob.agencyservice.api.model.FullAgencyResponseDTO;
import de.caritas.cob.agencyservice.api.repository.agency.Agency;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.model.ExtendedConsultingTypeResponseDTO;
Expand Down Expand Up @@ -185,6 +186,8 @@ public class TestConstants {
new FullAgencyResponseDTO().id(AGENCY_ID).name(AGENCY_NAME).postcode(POSTCODE)
.city(AGENCY_CITY).description(AGENCY_DESCRIPTION).teamAgency(false).offline(false)
.consultingType(CONSULTING_TYPE_SUCHT).url(null).external(false);
public static final AgencyTopicsDTO AGENCY_TOPICS_DTO =
new AgencyTopicsDTO().id(AGENCY_ID).name(AGENCY_NAME);
public static final List<FullAgencyResponseDTO> FULL_AGENCY_RESPONSE_DTO_LIST = Collections.singletonList(
FULL_AGENCY_RESPONSE_DTO);
public static final int MIN_POSTCODE_SIZE_3 = 3;
Expand Down

0 comments on commit edbffa1

Please sign in to comment.