diff --git a/src/main/java/de/caritas/cob/agencyservice/api/service/AgencyService.java b/src/main/java/de/caritas/cob/agencyservice/api/service/AgencyService.java index d81389d5..fdf35332 100644 --- a/src/main/java/de/caritas/cob/agencyservice/api/service/AgencyService.java +++ b/src/main/java/de/caritas/cob/agencyservice/api/service/AgencyService.java @@ -173,14 +173,8 @@ private List findAgencies(Optional postCode, Optional c Optional optionalTopicId, Optional age, Optional gender, Optional 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); @@ -194,16 +188,6 @@ private List findAgencies(Optional postCode, Optional c } } - private List findAgencies(String postCode, Integer topicId) { - - AgencySearch agencySearch = AgencySearch.builder() - .postCode(Optional.of(postCode)) - .topicId(Optional.of(topicId)) - .build(); - - return findAgenciesWithTopicForCurrentTenant(agencySearch); - } - private List findAgencies(AgencySearch agencySearch) { try { return getAgencyRepositoryForSearch() @@ -219,6 +203,28 @@ private List findAgencies(AgencySearch agencySearch) { } } + private List 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 postCode, + Optional consultingTypeId, Optional optionalTopicId, Optional age, + Optional gender, Optional counsellingRelation) { + return AgencySearch.builder() + .postCode(postCode) + .consultingTypeId(consultingTypeId) + .topicId(optionalTopicId) + .age(age) + .gender(gender) + .counsellingRelation(counsellingRelation) + .build(); + } + private void assertTopicIdIsProvided(Optional topicId) { if (!topicId.isPresent()) { throw new BadRequestException("Topic id not provided in the search"); diff --git a/src/test/java/de/caritas/cob/agencyservice/api/service/AgencyServiceIT.java b/src/test/java/de/caritas/cob/agencyservice/api/service/AgencyServiceIT.java index 053730ac..7da11a80 100644 --- a/src/test/java/de/caritas/cob/agencyservice/api/service/AgencyServiceIT.java +++ b/src/test/java/de/caritas/cob/agencyservice/api/service/AgencyServiceIT.java @@ -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(); + } } diff --git a/src/test/java/de/caritas/cob/agencyservice/api/service/AgencyServiceITBase.java b/src/test/java/de/caritas/cob/agencyservice/api/service/AgencyServiceITBase.java index a7a81317..0f39ddeb 100644 --- a/src/test/java/de/caritas/cob/agencyservice/api/service/AgencyServiceITBase.java +++ b/src/test/java/de/caritas/cob/agencyservice/api/service/AgencyServiceITBase.java @@ -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 resultAgencies = agencyService.getAgencies(postCode, topicId); + + assertThat(resultAgencies, hasSize(1)); + FullAgencyResponseDTO resultAgency = resultAgencies.get(0); + assertThat(resultAgency.getId(), is(14352L)); + } + }