Skip to content

Commit

Permalink
chore: [bulk transaction] group by id and aggragate payment-info.deta…
Browse files Browse the repository at this point in the history
…il (#177)

* chore: group by id and aggragate payment-info.detail

* chore: spoteless minor fix
  • Loading branch information
infantesimone authored Jan 10, 2025
1 parent 426fdc5 commit f73625c
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,25 @@ class PmService(
)
pmBulkTransactionDataProvider.findResult(pmSearchBulkTransactionRequestDto)
}
.map { transactionList ->
transactionList
.groupBy { it.id }
.map { (id, transactions) ->
val baseTransaction = transactions.first()
val aggregatedDetails =
transactions.flatMap { it.paymentInfo.details.orEmpty() }
TransactionBulkResultDto()
.id(baseTransaction.id)
.userInfo(baseTransaction.userInfo)
.transactionInfo(baseTransaction.transactionInfo)
.paymentInfo(
PaymentInfoDto()
.origin(baseTransaction.paymentInfo.origin)
.details(aggregatedDetails)
)
.pspInfo(baseTransaction.pspInfo)
.product(baseTransaction.product)
}
}
}
}
46 changes: 46 additions & 0 deletions src/test/kotlin/it/pagopa/ecommerce/helpdesk/HelpdeskTestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,52 @@ object HelpdeskTestUtils {
)
.product(product)

fun buildBulkTransactionResultDtoWithSingleElement(id: String): List<TransactionBulkResultDto> =
listOf(
TransactionBulkResultDto()
.id(id)
.userInfo(
UserInfoBulkDto()
.userFiscalCode("user fiscal code")
.notificationEmail(TransactionTestUtils.EMAIL_STRING)
.authenticationType("auth type")
)
.transactionInfo(
TransactionInfoDto()
.status("status")
.statusDetails("status detail")
.amount(500)
.fee(200)
.grandTotal(700)
.rrn("rrn")
.authorizationCode("authorization code")
.paymentMethodName("payment method name")
.brand(null)
)
.paymentInfo(
PaymentInfoDto()
.origin("origin")
.details(
listOf(
PaymentDetailInfoDto()
.iuv("IUV")
.rptId(null)
.idTransaction(TransactionTestUtils.TRANSACTION_ID)
.paymentToken(null)
.creditorInstitution("creditor institution")
.paFiscalCode(TransactionTestUtils.PA_FISCAL_CODE)
)
)
)
.pspInfo(
PspInfoDto()
.pspId(TransactionTestUtils.PSP_ID)
.businessName(TransactionTestUtils.PSP_BUSINESS_NAME)
.idChannel(TransactionTestUtils.PSP_CHANNEL_CODE)
)
.product(ProductDto.PM)
)

fun buildSearchPaymentMethodResponseDto(): SearchPaymentMethodResponseDto =
SearchPaymentMethodResponseDto()
.name("name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class PmServiceTest {
.endTransactionId("10")
val searchCriteria =
HelpdeskTestUtils.buildBulkSearchRequest("TRANSACTION_ID_RANGE", transactionIdRangeDto)
val transactions = listOf(TransactionBulkResultDto(), TransactionBulkResultDto())
val transactions = HelpdeskTestUtils.buildBulkTransactionResultDtoWithSingleElement("1")

given(
pmBulkTransactionDataProvider.findResult(
Expand All @@ -153,4 +153,54 @@ class PmServiceTest {

verify(pmBulkTransactionDataProvider, times(1)).findResult(any())
}

@Test
fun `should return found bulk transaction aggregated successfully`() {
val transactionIdRangeDto =
SearchTransactionRequestTransactionIdRangeTransactionIdRangeDto()
.startTransactionId("1")
.endTransactionId("10")
val searchCriteria =
HelpdeskTestUtils.buildBulkSearchRequest("TRANSACTION_ID_RANGE", transactionIdRangeDto)
val transactions =
listOf(
HelpdeskTestUtils.buildBulkTransactionResultDtoWithSingleElement("1000000000")
.first(),
HelpdeskTestUtils.buildBulkTransactionResultDtoWithSingleElement("1000000000")
.first(),
HelpdeskTestUtils.buildBulkTransactionResultDtoWithSingleElement("992992929")
.first()
)

given(
pmBulkTransactionDataProvider.findResult(
searchParams = searchCriteria,
)
)
.willReturn(Mono.just(transactions))
val expectedResponse =
transactions
.groupBy { it.id }
.map { (id, transactions) ->
val baseTransaction = transactions.first()
val aggregatedDetails =
transactions.flatMap { it.paymentInfo.details.orEmpty() }
TransactionBulkResultDto()
.id(baseTransaction.id)
.userInfo(baseTransaction.userInfo)
.transactionInfo(baseTransaction.transactionInfo)
.paymentInfo(
PaymentInfoDto()
.origin(baseTransaction.paymentInfo.origin)
.details(aggregatedDetails)
)
.pspInfo(baseTransaction.pspInfo)
.product(baseTransaction.product)
}
StepVerifier.create(pmService.searchBulkTransaction(searchCriteria))
.expectNext(expectedResponse)
.verifyComplete()

verify(pmBulkTransactionDataProvider, times(1)).findResult(any())
}
}

0 comments on commit f73625c

Please sign in to comment.