Skip to content

Commit

Permalink
feat: CARITAS-286
Browse files Browse the repository at this point in the history
* add new IT tests for the AgencyController
  • Loading branch information
Leandro13Silva13 committed Oct 29, 2024
1 parent 33b8c1b commit 2f54ccc
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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_PRIVATE;
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;
Expand All @@ -14,6 +15,7 @@
import static de.caritas.cob.agencyservice.testHelper.TestConstants.VALID_AGE_QUERY;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.VALID_CONSULTING_TYPE_QUERY;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.VALID_POSTCODE_QUERY;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.VALID_TOPIC_ID_QUERY;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.atLeastOnce;
Expand Down Expand Up @@ -281,4 +283,62 @@ void getAgenciesTopics_Should_ReturnListAndOk_When_ServiceReturnsList() throws E
verify(topicEnrichmentService, atLeastOnce()).enrichTopicIdsWithTopicData(Mockito.anyList());
}

@Test
void getTenantAgencies_Should_ReturnNoContent_When_ServiceReturnsEmptyList() throws Exception {

when(agencyService.getAgencies(Mockito.anyString(), Mockito.anyInt()))
.thenReturn(null);

mvc.perform(
get(PATH_GET_LIST_OF_AGENCIES_PRIVATE + "?" + VALID_POSTCODE_QUERY + "&"
+ VALID_TOPIC_ID_QUERY)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNoContent());
}

@Test
void getTenantAgencies_Should_ReturnBadRequest_When_PostcodeParamIsInvalid() throws Exception {

mvc.perform(
get(PATH_GET_LIST_OF_AGENCIES_PRIVATE + "?" + INVALID_POSTCODE_QUERY + "&"
+ VALID_TOPIC_ID_QUERY)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());
}

@Test
void getTenantAgencies_Should_ReturnBadRequest_When_topicIdParamIsNotProvided()
throws Exception {

mvc.perform(get(PATH_GET_LIST_OF_AGENCIES_PRIVATE + "?" + VALID_POSTCODE_QUERY)
.accept(MediaType.APPLICATION_JSON)).andExpect(status().isBadRequest());
}

@Test
void getTenantAgencies_Should_ReturnBadRequest_When_PostCodeParamIsNotProvided()
throws Exception {

mvc.perform(get(PATH_GET_LIST_OF_AGENCIES_PRIVATE + "?" + VALID_TOPIC_ID_QUERY)
.accept(MediaType.APPLICATION_JSON)).andExpect(status().isBadRequest());
}

@Test
void getTenantAgencies_Should_ReturnListAndOk_When_ServiceReturnsList() throws Exception {

List<FullAgencyResponseDTO> agencies = new ArrayList<>();
agencies.add(FULL_AGENCY_RESPONSE_DTO);

when(agencyService.getAgencies(Mockito.anyString(), Mockito.anyInt()))
.thenReturn(agencies);

mvc.perform(
get(PATH_GET_LIST_OF_AGENCIES_PRIVATE + "?" + VALID_POSTCODE_QUERY + "&"
+ VALID_TOPIC_ID_QUERY)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("[0].name").value(AGENCY_RESPONSE_DTO.getName()));

verify(agencyService, atLeastOnce()).getAgencies(Mockito.anyString(), Mockito.anyInt());
}

}
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_PRIVATE = "/agencies/private";
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.List;
import java.util.Map;
import org.assertj.core.util.Lists;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties.Retry.Topic;

public class TestConstants {

Expand Down Expand Up @@ -150,6 +149,7 @@ public class TestConstants {
public static final String VALID_POSTCODE_6 = "33445";
public static final String AGENCY_CITY = "Test city";
public static final String VALID_POSTCODE_QUERY = "postcode=88488";
public static final String VALID_TOPIC_ID_QUERY = "topicId=1";
public static final int VALID_POSTCODE_LENGTH = 5;
public static final Long AGENCY_ID = 98L;
public static final String AGENCY_NAME = "Test agency";
Expand Down

0 comments on commit 2f54ccc

Please sign in to comment.