Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FINERACT-2156: Confirm existance of elements before accessing them #4202

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

wkigenyi
Copy link
Contributor

@wkigenyi wkigenyi commented Dec 1, 2024

Description

Describe the changes made and why they were made.

Ignore if these details are present on the associated Apache Fineract JIRA ticket.

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Write the commit message as per https://github.com/apache/fineract/#pull-requests

  • Acknowledge that we will not review PRs that are not passing the build ("green") - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.

  • Create/update unit or integration tests for verifying the changes made.

  • Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.

  • Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes

  • Submission is not a "code dump". (Large changes can be made "in repository" via a branch. Ask on the developer mailing list for guidance, if required.)

FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.

@@ -0,0 +1,1068 @@
#
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this.

@@ -0,0 +1,1093 @@
#
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Copy link
Contributor

@adamsaghy adamsaghy left a comment

Choose a reason for hiding this comment

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

Please kindly remove the log files!

@wkigenyi wkigenyi force-pushed the 2156 branch 2 times, most recently from d1052ab to 07b94e7 Compare December 30, 2024 21:52
@wkigenyi wkigenyi marked this pull request as ready for review December 31, 2024 06:58
@wkigenyi
Copy link
Contributor Author

wkigenyi commented Jan 1, 2025

@adamsaghy this is now ready for review

@@ -1594,12 +1594,19 @@ public void validateAccountBalanceDoesNotBecomeNegative(final String transaction
public void validateAccountBalanceDoesNotViolateOverdraft(final List<SavingsAccountTransaction> savingsAccountTransaction,
final BigDecimal amountPaid) {
if (savingsAccountTransaction != null) {
SavingsAccountTransaction savingsAccountTransactionFirst = savingsAccountTransaction.get(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind to simplify the logic a little bit further?

You can merge the savingsAccountTransaction != null and savingsAccountTransaction.size() > 0 condition together and if they are TRUE take the running balance of the first element otherwise it is BigDecimal.ZERO (if there are no any transaction the running balance must be 0).
After you can deduct the amountPaid from the above balance and if the balance is negative and allowOverdraft is FALSE then InsufficientAccountBalanceException to be thrown.

I believe it would be easier to read and cover better the requirements!

Also kindly asking you to write a test (it can be unit tests), which covers the following situations:

  • savingsAccountTransaction is empty and amountPaid is positive and allowOverdraft = true -> No exception!
  • savingsAccountTransaction is empty and amountPaid is positive and allowOverdraft = false -> Exception to be thrown!
  • savingsAccountTransaction is not empty and amountPaid is positive and amountPaid is higher than the running balance of the 1st transaciton and allowOverdraft = true -> No exception!
  • savingsAccountTransaction is not empty and amountPaid is positive and amountPaid is lower than the running balance of the 1st transaction and allowOverdraft = false -> Exception to be thrown!
  • savingsAccountTransaction is not empty and amountPaid is positive and amountPaid is equal with the running balance of the 1st transaction and allowOverdraft = false -> No exception!

Copy link
Contributor

Choose a reason for hiding this comment

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

@wkigenyi Are you still working on the ticket?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adamsaghy should the case in bullet 4 throw an exception ? amountPaid is LOWER than the runningBalance. In this case I think the exception should not be thrown

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the bullet 3 and 4 might be should do the opposite!

Copy link
Contributor

@adamsaghy adamsaghy left a comment

Choose a reason for hiding this comment

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

@wkigenyi Kindly see my review!

Copy link

github-actions bot commented Feb 1, 2025

This pull request seems to be stale. Are you still planning to work on it? We will automatically close it in 30 days.

@github-actions github-actions bot added the stale label Feb 1, 2025
@galovics
Copy link
Contributor

galovics commented Feb 4, 2025

@wkigenyi any plans to continue this PR?

@wkigenyi
Copy link
Contributor Author

wkigenyi commented Feb 4, 2025

Yes I work on it. Been busy with some back log.

@github-actions github-actions bot removed the stale label Feb 5, 2025
@wkigenyi
Copy link
Contributor Author

wkigenyi commented Mar 3, 2025 via email

@wkigenyi wkigenyi force-pushed the 2156 branch 3 times, most recently from 2589c4d to 25a5d52 Compare March 10, 2025 16:38
@wkigenyi
Copy link
Contributor Author

@adamsaghy could you guide me on how to fix this test? The result says it got status 403 instead of the 400 that was expected. In the test I specified:

assertEquals("error.msg.savingsaccount.transaction.insufficient.account.balance",
                savingsAccountErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));

I am not sure that status code is being considered instead of the string I specified.

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.

4 participants