Skip to content

Commit

Permalink
feat(Gate): Add LegalEntityController new endpoint and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiodmota committed Apr 18, 2023
1 parent 28a3139 commit 433dc60
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ interface GateLegalEntityApi {
@GetExchange("/input/legal-entities/{externalId}")
fun getLegalEntityByExternalId(@Parameter(description = "External identifier") @PathVariable externalId: String): LegalEntityGateInputResponse

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

@Operation(
summary = "Get page of legal entities",
description = "Get page of legal entities."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class LegalEntityController(
return legalEntityService.getLegalEntityByExternalId(externalId)
}

override fun getLegalEntitiesByExternalIds(
paginationRequest: PaginationStartAfterRequest,
externalIds: Collection<String>
): PageStartAfterResponse<LegalEntityGateInputResponse> {
return legalEntityService.getLegalEntities(limit = paginationRequest.limit, startAfter = paginationRequest.startAfter, externalIds = externalIds)
}

override fun getLegalEntities(paginationRequest: PaginationStartAfterRequest): PageStartAfterResponse<LegalEntityGateInputResponse> {
return legalEntityService.getLegalEntities(paginationRequest.limit, paginationRequest.startAfter)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class LegalEntityService(
}
}

fun getLegalEntities(limit: Int, startAfter: String?): PageStartAfterResponse<LegalEntityGateInputResponse> {
val partnerCollection = saasClient.getLegalEntities(limit, startAfter)
fun getLegalEntities(limit: Int, startAfter: String?, externalIds: Collection<String>? = null): PageStartAfterResponse<LegalEntityGateInputResponse> {
val partnerCollection = saasClient.getLegalEntities(limit, startAfter, externalIds)

val validEntries = toValidLegalEntities(partnerCollection.values)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,63 @@ internal class LegalEntityControllerInputIT @Autowired constructor(
)
}


/**
* Given legal entity exists in SaaS
* When getting legal entities page based on external id list
* Then legal entities page mapped to the catena data model should be returned
*/
@Test
fun `get legal entity filter by external ids`() {
val legalEntitiesSaas = listOf(
SaasValues.legalEntityResponse1,
SaasValues.legalEntityResponse2,
)

val expectedLegalEntities = listOf(
ResponseValues.legalEntityGateInputResponse1,
ResponseValues.legalEntityGateInputResponse2,
)

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 = legalEntitiesSaas
)
)
)
)
)

val paginationValue = PaginationStartAfterRequest(startAfter, limit)
val listExternalIds = legalEntitiesSaas.mapNotNull { it.externalId }
val pageResponse = gateClient.legalEntities().getLegalEntitiesByExternalIds(paginationValue, listExternalIds)

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

/**
* Given legal entity without legal address in SaaS
* When getting legal entities page
Expand Down

0 comments on commit 433dc60

Please sign in to comment.