Skip to content

fix: validate positive intra-bank transfer amounts#2012

Open
officialasishkumar wants to merge 2 commits intoopenMF:developmentfrom
officialasishkumar:fix/intrabank-positive-amount-validation
Open

fix: validate positive intra-bank transfer amounts#2012
officialasishkumar wants to merge 2 commits intoopenMF:developmentfrom
officialasishkumar:fix/intrabank-positive-amount-validation

Conversation

@officialasishkumar
Copy link
Copy Markdown

@officialasishkumar officialasishkumar commented Apr 29, 2026

Issue Fix

Fixes #2011
Jira Task: N/A

Screenshots

N/A - validation logic and regression test change only.

Description

  • Reject zero and negative intra-bank transfer amounts before a transfer payload can be submitted.
  • Reset the processing flag when client-side validation fails so validation errors do not leave the confirmation screen blocked.
  • Add common-state regression coverage for zero, negative, valid decimal, over-balance, and non-numeric amounts.

Validation

  • ./gradlew :feature:transfer-intrabank:compileTestKotlinDesktop --no-daemon --max-workers=2 --stacktrace
  • ./gradlew :feature:transfer-intrabank:desktopTest --no-daemon --max-workers=2 --stacktrace
  • ./gradlew :feature:transfer-intrabank:spotlessKotlinCheck --no-daemon --max-workers=2 --stacktrace

  • Apply the AndroidStyle.xml style template to your code in Android Studio.

  • Run the unit tests with ./gradlew check to make sure you didn't break anything

  • If you have multiple commits please combine them into one commit by squashing them.

Summary by CodeRabbit

  • Bug Fixes

    • Strengthened intrabank transfer amount validation to reject zero, negative, non-numeric, and amounts exceeding the available balance
    • Ensured processing state is cleared when validation errors occur
  • Tests

    • Added unit and integration-style tests covering amount validation scenarios and verification that processing state and error dialog are set appropriately

Reject zero and negative transfer amounts in the intra-bank confirmation flow before building a transfer payload. Also reset the processing flag when client-side validation fails so validation errors do not leave the screen in a blocked state.

Add desktop common-state regression coverage for valid, non-positive, over-balance, and non-numeric transfer amounts.
@officialasishkumar officialasishkumar requested a review from a team April 29, 2026 21:53
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3881e3b9-120e-4278-a8ae-500bc363fb1a

📥 Commits

Reviewing files that changed from the base of the PR and between d0d4fb8 and 1cd4370.

📒 Files selected for processing (1)
  • feature/transfer-intrabank/src/commonTest/kotlin/org/mifospay/feature/transfer/intrabank/confirm/TransferConfirmStateTest.kt
🚧 Files skipped from review as they are similar to previous changes (1)
  • feature/transfer-intrabank/src/commonTest/kotlin/org/mifospay/feature/transfer/intrabank/confirm/TransferConfirmStateTest.kt

📝 Walkthrough

Walkthrough

The transfer confirmation validation was rewritten to parse the amount once, reject non-positive values early, reset isProcessing on validation errors, and tighten amountIsValid to require parsed amounts > 0 and ≤ selected account balance. Tests covering zero, negative, invalid, and over-balance inputs were added.

Changes

Cohort / File(s) Summary
Transfer Validation Logic
feature/transfer-intrabank/src/commonMain/kotlin/org/mifospay/feature/transfer/intrabank/confirm/TransferConfirmViewModel.kt
Refactored validation to parse amount once and use early returns; reject amounts ≤ 0.0; reset isProcessing on validation error; tightened amountIsValid to require parsed amount > 0 and within selectedAccountBalance.
Transfer Validation Tests
feature/transfer-intrabank/src/commonTest/kotlin/org/mifospay/feature/transfer/intrabank/confirm/TransferConfirmStateTest.kt
Added tests asserting amountIsValid for zero, negative, positive-within-balance, over-balance, and non-numeric inputs; integration-style test ensures isProcessing is cleared and a validation error dialog is set when submitting an invalid amount.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through digits, sniffed the sum,
No zeros or negatives may come,
I parsed it once, I hopped away—
Only positives make the day! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely describes the main change: adding validation to reject zero and negative intra-bank transfer amounts.
Linked Issues check ✅ Passed The PR fully addresses issue #2011: amounts > 0 are validated, zero/negative values are rejected, processing state resets on validation failure, and regression tests cover the edge cases.
Out of Scope Changes check ✅ Passed All changes directly support the objective of validating positive transfer amounts. Test additions and validation logic restructuring are in scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
feature/transfer-intrabank/src/commonTest/kotlin/org/mifospay/feature/transfer/intrabank/confirm/TransferConfirmStateTest.kt (1)

18-66: Add a regression that exercises the blocked-screen fix.

These cases only verify TransferConfirmState.amountIsValid. They never drive TransferConfirmViewModel through InitiateTransfer, so the new isProcessing = false recovery path on validation errors is still untested. That matters because isProcessing controls the disabled button, spinner, and overlay in TransferConfirmScreen.kt:310-332.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@feature/transfer-intrabank/src/commonTest/kotlin/org/mifospay/feature/transfer/intrabank/confirm/TransferConfirmStateTest.kt`
around lines 18 - 66, Tests currently only exercise
TransferConfirmState.amountIsValid and don't exercise the
TransferConfirmViewModel.InitiateTransfer path that must reset isProcessing on
validation errors; add a unit test that constructs a TransferConfirmViewModel,
sets a state with an invalid amount (e.g., "abc" or amount >
selectedAccountBalance), invokes the viewModel.initiateTransfer() action, and
then asserts that viewModel.state.isProcessing is false after the call and any
validation error event/state is emitted. Locate and use the
TransferConfirmViewModel class and its initiateTransfer()/InitiateTransfer
intent, and assert the isProcessing flag along with any validation error
flag/message to verify the blocked-screen recovery path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@feature/transfer-intrabank/src/commonTest/kotlin/org/mifospay/feature/transfer/intrabank/confirm/TransferConfirmStateTest.kt`:
- Around line 18-66: Tests currently only exercise
TransferConfirmState.amountIsValid and don't exercise the
TransferConfirmViewModel.InitiateTransfer path that must reset isProcessing on
validation errors; add a unit test that constructs a TransferConfirmViewModel,
sets a state with an invalid amount (e.g., "abc" or amount >
selectedAccountBalance), invokes the viewModel.initiateTransfer() action, and
then asserts that viewModel.state.isProcessing is false after the call and any
validation error event/state is emitted. Locate and use the
TransferConfirmViewModel class and its initiateTransfer()/InitiateTransfer
intent, and assert the isProcessing flag along with any validation error
flag/message to verify the blocked-screen recovery path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 71816aa4-9a70-4227-a9de-882f4ebc6f65

📥 Commits

Reviewing files that changed from the base of the PR and between d399e0a and d0d4fb8.

📒 Files selected for processing (2)
  • feature/transfer-intrabank/src/commonMain/kotlin/org/mifospay/feature/transfer/intrabank/confirm/TransferConfirmViewModel.kt
  • feature/transfer-intrabank/src/commonTest/kotlin/org/mifospay/feature/transfer/intrabank/confirm/TransferConfirmStateTest.kt

@officialasishkumar
Copy link
Copy Markdown
Author

Added the requested regression coverage in 1cd4370: the test now drives TransferConfirmViewModel through InitiateTransfer with an invalid amount and asserts processing is cleared with a validation error. ./gradlew :feature:transfer-intrabank:desktopTest --tests org.mifospay.feature.transfer.intrabank.confirm.TransferConfirmStateTest passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Intra-bank transfer accepts zero and negative amounts

1 participant