Skip to content

Commit

Permalink
feat(Gate): Add SiteController new endpoint and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiodmota committed Apr 21, 2023
1 parent 4d2e35c commit 305318c
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ interface GateSiteApi {
@GetExchange("/input/sites/{externalId}")
fun getSiteByExternalId(@Parameter(description = "External identifier") @PathVariable externalId: String): SiteGateInputResponse

@Operation(
summary = "Get page of sites filtered by a collection of externalIds",
description = "Get page of sites filtered by a collection of externalIds."
)
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "The requested page of sites"),
ApiResponse(responseCode = "400", description = "On malformed pagination request", content = [Content()]),
]
)
@PostMapping("/input/sites/search")
@PostExchange("/input/sites/search")
fun getSitesByExternalIds(
@ParameterObject @Valid paginationRequest: PaginationStartAfterRequest,
@RequestBody externalIds: Collection<String>
): PageStartAfterResponse<SiteGateInputResponse>

@Operation(
summary = "Get page of sites",
description = "Get page of sites."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class SiteController(
return siteService.getSiteByExternalId(externalId)
}

override fun getSitesByExternalIds(
paginationRequest: PaginationStartAfterRequest,
externalIds: Collection<String>
): PageStartAfterResponse<SiteGateInputResponse> {
return siteService.getSites(paginationRequest.limit, paginationRequest.startAfter, externalIds)
}

override fun getSites(paginationRequest: PaginationStartAfterRequest): PageStartAfterResponse<SiteGateInputResponse> {
return siteService.getSites(paginationRequest.limit, paginationRequest.startAfter)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class SiteService(
) {
private val logger = KotlinLogging.logger { }

fun getSites(limit: Int, startAfter: String?): PageStartAfterResponse<SiteGateInputResponse> {
val sitesPage = saasClient.getSites(limit, startAfter)
fun getSites(limit: Int, startAfter: String?, externalIds: Collection<String>? = null): PageStartAfterResponse<SiteGateInputResponse> {
val sitesPage = saasClient.getSites(limit, startAfter, externalIds)

val validEntries = sitesPage.values.filter { validateSiteBusinessPartner(it) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,62 @@ internal class SiteControllerInputIT @Autowired constructor(
)
}

/**
* Given sites exists in SaaS
* When getting sites page based on externalId
* Then sites page mapped to the catena data model should be returned
*/
@Test
fun `get sites by external id`() {
val sitesSaas = listOf(
SaasValues.siteBusinessPartnerWithRelations1,
SaasValues.siteBusinessPartnerWithRelations2
)

val expectedSites = listOf(
ResponseValues.siteGateInputResponse1,
ResponseValues.siteGateInputResponse2
)

val limit = 2
val startAfter = "Aaa111"
val nextStartAfter = "Aaa222"
val total = 10
val invalidEntries = 0

wireMockServer.stubFor(
get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH))
.willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withBody(
objectMapper.writeValueAsString(
PagedResponseSaas(
limit = limit,
startAfter = startAfter,
nextStartAfter = nextStartAfter,
total = total,
values = sitesSaas
)
)
)
)
)

val externalIds = sitesSaas.mapNotNull { it.externalId }
val paginationValue = PaginationStartAfterRequest(startAfter, limit)
val pageResponse = gateClient.sites().getSitesByExternalIds(paginationValue, externalIds)

assertThat(pageResponse).isEqualTo(
PageStartAfterResponse(
total = total,
nextStartAfter = nextStartAfter,
content = expectedSites,
invalidEntries = invalidEntries
)
)
}

/**
* Given invalid sites in SaaS
* When getting sites page
Expand Down

0 comments on commit 305318c

Please sign in to comment.