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 AgencyService
  • Loading branch information
Leandro13Silva13 committed Oct 29, 2024
1 parent 2f54ccc commit a81ced7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,8 @@ private List<Agency> findAgencies(Optional<String> postCode, Optional<Integer> c
Optional<Integer> optionalTopicId, Optional<Integer> age,
Optional<String> gender, Optional<String> counsellingRelation) {

AgencySearch agencySearch = AgencySearch.builder()
.postCode(postCode)
.consultingTypeId(consultingTypeId)
.topicId(optionalTopicId)
.age(age)
.gender(gender)
.counsellingRelation(counsellingRelation)
.build();
AgencySearch agencySearch = buildAgencySearch(postCode,
consultingTypeId, optionalTopicId, age, gender, counsellingRelation);

if (demographicsFeatureEnabled) {
assertAgeAndGenderAreProvided(age, gender);
Expand All @@ -194,16 +188,6 @@ private List<Agency> findAgencies(Optional<String> postCode, Optional<Integer> c
}
}

private List<Agency> findAgencies(String postCode, Integer topicId) {

AgencySearch agencySearch = AgencySearch.builder()
.postCode(Optional.of(postCode))
.topicId(Optional.of(topicId))
.build();

return findAgenciesWithTopicForCurrentTenant(agencySearch);
}

private List<Agency> findAgencies(AgencySearch agencySearch) {
try {
return getAgencyRepositoryForSearch()
Expand All @@ -219,6 +203,28 @@ private List<Agency> findAgencies(AgencySearch agencySearch) {
}
}

private List<Agency> findAgencies(String postCode, Integer topicId) {

AgencySearch agencySearch = buildAgencySearch(Optional.of(postCode),
Optional.empty(), Optional.of(topicId), Optional.empty(),
Optional.empty(), Optional.empty());

return findAgenciesWithTopicForCurrentTenant(agencySearch);
}

private static AgencySearch buildAgencySearch(Optional<String> postCode,
Optional<Integer> consultingTypeId, Optional<Integer> optionalTopicId, Optional<Integer> age,
Optional<String> gender, Optional<String> counsellingRelation) {
return AgencySearch.builder()
.postCode(postCode)
.consultingTypeId(consultingTypeId)
.topicId(optionalTopicId)
.age(age)
.gender(gender)
.counsellingRelation(counsellingRelation)
.build();
}

private void assertTopicIdIsProvided(Optional<Integer> topicId) {
if (!topicId.isPresent()) {
throw new BadRequestException("Topic id not provided in the search");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public void getAgenciesByConsultingType_Should_returnResults_When_ConsultingType
public void getAgenciesTopics_Should_ReturnResults_When_topics_exist() {
super.getAgenciesTopics_Should_ReturnResults_When_topics_exist();
}

@Test
public void getAgencies_Should_returnMatchingAgencies_When_postcodeAndTopicIdIsGiven() {
super.getAgencies_Should_returnMatchingAgencies_When_postcodeAndTopicIdIsGiven();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,16 @@ public void getAgenciesTopics_Should_ReturnResults_When_topics_exist() {
assertThat(topicIds, hasSize(greaterThan(0)));
}

public void getAgencies_Should_returnMatchingAgencies_When_postcodeAndTopicIdIsGiven() {

String postCode = "45501";
Integer topicId = 1;

List<FullAgencyResponseDTO> resultAgencies = agencyService.getAgencies(postCode, topicId);

assertThat(resultAgencies, hasSize(1));
FullAgencyResponseDTO resultAgency = resultAgencies.get(0);
assertThat(resultAgency.getId(), is(14352L));
}

}

0 comments on commit a81ced7

Please sign in to comment.