Fixed that balance of pre booked transactions may be empty
This commit is contained in:
parent
16284e5782
commit
75e77eb84a
|
@ -599,7 +599,7 @@ open class ResponseParser(
|
|||
// dataElementGroups[1] is account details
|
||||
|
||||
val balance = parseBalance(dataElementGroups[4])
|
||||
val balanceOfPreBookedTransactions = if (dataElementGroups.size > 5) parseBalanceToNullIfZero(dataElementGroups[5]) else null
|
||||
val balanceOfPreBookedTransactions = if (dataElementGroups.size > 5) parseBalanceToNullIfZeroOrNotSet(dataElementGroups[5]) else null
|
||||
|
||||
return BalanceSegment(
|
||||
balance.amount,
|
||||
|
@ -611,7 +611,11 @@ open class ResponseParser(
|
|||
)
|
||||
}
|
||||
|
||||
protected open fun parseBalanceToNullIfZero(dataElementGroup: String): Balance? {
|
||||
protected open fun parseBalanceToNullIfZeroOrNotSet(dataElementGroup: String): Balance? {
|
||||
if (dataElementGroup.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
|
||||
val parsedBalance = parseBalance(dataElementGroup)
|
||||
|
||||
if (BigDecimal.ZERO.equals(parsedBalance.amount)) {
|
||||
|
|
|
@ -989,7 +989,7 @@ class ResponseParserTest : FinTsTestBase() {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun parseBalance_BalanceOfPreBookedTransactionsIsOmitted() {
|
||||
fun parseBalance_BalanceOfPreBookedTransactionsIsZero() {
|
||||
|
||||
// given
|
||||
val balance = BigDecimal.ZERO
|
||||
|
@ -1015,6 +1015,33 @@ class ResponseParserTest : FinTsTestBase() {
|
|||
?: run { fail("No segment of type BalanceSegment found in ${result.receivedSegments}") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseBalance_BalanceOfPreBookedTransactionsIsEmpty() {
|
||||
|
||||
// given
|
||||
val balance = BigDecimal.ZERO
|
||||
val date = com.soywiz.klock.Date(2020, 6, 11)
|
||||
val bankCode = "12345678"
|
||||
val accountId = "0987654321"
|
||||
val accountProductName = "Girokonto"
|
||||
|
||||
// when
|
||||
// "HISAL:7:5:3+0987654321:Girokonto:280:12345678+Girokonto+EUR++0,:EUR'"
|
||||
val result = underTest.parse("HISAL:7:5:3+$accountId:$accountProductName:280:$bankCode+$accountProductName+EUR+C:0,:EUR:${convertDate(date)}:204204++0,:EUR'")
|
||||
|
||||
// then
|
||||
assertSuccessfullyParsedSegment(result, InstituteSegmentId.Balance, 7, 5, 3)
|
||||
|
||||
result.getFirstSegmentById<BalanceSegment>(InstituteSegmentId.Balance)?.let { segment ->
|
||||
expect(segment.balance).toBe(balance)
|
||||
expect(segment.currency).toBe("EUR")
|
||||
expect(segment.date).toBe(date)
|
||||
expect(segment.accountProductName).toBe(accountProductName)
|
||||
expect(segment.balanceOfPreBookedTransactions).toBe(null)
|
||||
}
|
||||
?: run { fail("No segment of type BalanceSegment found in ${result.receivedSegments}") }
|
||||
}
|
||||
|
||||
|
||||
private fun assertSuccessfullyParsedSegment(result: Response, segmentId: ISegmentId, segmentNumber: Int,
|
||||
segmentVersion: Int, referenceSegmentNumber: Int? = null) {
|
||||
|
|
Loading…
Reference in New Issue