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

fix: Sabadell Bank regression, missing date field during normalization #474

Merged
merged 2 commits into from
Oct 12, 2024

Conversation

davidmartos96
Copy link
Contributor

@davidmartos96 davidmartos96 commented Oct 5, 2024

Fixes a regression from a PR of mine from some weeks ago #445. I forgot to include the date field in the normalized transaction, which fails when syncing.

@actual-github-bot actual-github-bot bot changed the title fix: Sabadell Bank regression, missing date field during normalization [WIP] fix: Sabadell Bank regression, missing date field during normalization Oct 5, 2024
Copy link
Contributor

coderabbitai bot commented Oct 5, 2024

Walkthrough

The pull request introduces changes to the bancsabadell-bsabesbbb.js file, specifically enhancing the normalizeTransaction method. A new property, date, is added to the return object of this method. The value of date is derived from transaction.bookingDate if it exists; otherwise, it defaults to transaction.valueDate. The method's overall structure remains unchanged, including the logic for determining creditorName and debtorName based on transaction amounts. Additionally, modifications are made to the test suite in bancsabadell-bsabesbbb.spec.js to accommodate these changes. The test cases for both debtor and creditor roles are updated to include a bookingDate property in the transaction objects. A new test case is also added to verify that the normalizeTransaction method correctly extracts the bookingDate, ensuring that the date extraction functionality is validated.

Possibly related PRs

Suggested labels

::sparkles: Merged


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@davidmartos96 davidmartos96 changed the title [WIP] fix: Sabadell Bank regression, missing date field during normalization fix: Sabadell Bank regression, missing date field during normalization Oct 5, 2024
Copy link
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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
src/app-gocardless/banks/bancsabadell-bsabesbbb.js (1)

Line range hint 1-37: Consider reviewing date handling across all bank integrations.

While this change effectively addresses the Sabadell Bank regression, it might be beneficial to:

  1. Review date handling in other bank integrations to ensure consistency and prevent similar issues.
  2. Assess any potential impacts on other parts of the system that consume normalized transaction data, especially those that rely on transaction dates.

To help with this review, you can use the following script to check date-related fields in other bank integration files:

#!/bin/bash
# Description: Check date-related fields in bank integration files

echo "Date-related fields in bank integration files:"
rg --type js '\b(date|Date)\b' src/app-gocardless/banks/ -C 2

echo "\nNormalization methods in bank integration files:"
rg --type js 'normalizeTransaction' src/app-gocardless/banks/ -C 5

This will help identify any inconsistencies in date handling across different bank integrations and highlight areas that might need similar updates.

src/app-gocardless/banks/tests/bancsabadell-bsabesbbb.spec.js (3)

12-12: LGTM! Consider adding an assertion for the date field.

The addition of the bookingDate property is in line with the PR objectives. However, to ensure complete coverage, consider adding an assertion to verify that the date field is correctly set in the normalized transaction.

You could add the following assertion:

expect(normalizedTransaction.date).toEqual('2022-05-01');

30-30: LGTM! Consider adding an assertion for the date field.

The addition of the bookingDate property is consistent with the changes in the first test case. To ensure complete coverage, consider adding an assertion to verify that the date field is correctly set in the normalized transaction.

You could add the following assertion:

expect(normalizedTransaction.date).toEqual('2022-05-01');

41-55: Great addition! Consider adding a test for fallback behavior.

This new test case effectively verifies the correct extraction of the date field from the transaction, addressing the PR objectives. It's a valuable addition to the test suite.

To make the test suite more robust, consider adding another test case that verifies the fallback behavior when bookingDate is not present. This would ensure that the valueDate is used correctly in such scenarios. For example:

it('extract date fallback to valueDate', () => {
  const transaction = {
    transactionAmount: { amount: '-100', currency: 'EUR' },
    remittanceInformationUnstructuredArray: ['some-creditor-name'],
    internalTransactionId: 'd7dca139cf31d9',
    transactionId: '04704109322',
    valueDate: '2024-10-05',
  };
  const normalizedTransaction = Sabadell.normalizeTransaction(
    transaction,
    true,
  );
  expect(normalizedTransaction.date).toEqual('2024-10-05');
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6658dc2 and 60ee209.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/474.md is excluded by !**/*.md
📒 Files selected for processing (2)
  • src/app-gocardless/banks/bancsabadell-bsabesbbb.js (1 hunks)
  • src/app-gocardless/banks/tests/bancsabadell-bsabesbbb.spec.js (3 hunks)
🔇 Additional comments (2)
src/app-gocardless/banks/bancsabadell-bsabesbbb.js (1)

34-34: LGTM. Please verify date field usage across all transaction types.

The addition of the date field with a fallback mechanism (transaction.bookingDate || transaction.valueDate) addresses the regression issue mentioned in the PR objectives. This implementation looks correct and should resolve the missing date field during normalization.

However, to ensure robustness:

  1. Please verify that this date extraction works correctly for all transaction types supported by Sabadell Bank.
  2. Consider adding test cases that cover scenarios where:
    a) Only bookingDate is present
    b) Only valueDate is present
    c) Both bookingDate and valueDate are present
    d) Neither bookingDate nor valueDate is present (edge case)

To assist in verifying the usage of bookingDate and valueDate across the codebase, you can run the following script:

This will help ensure that the date field usage is consistent across the codebase and that we haven't missed any other relevant date fields.

✅ Verification successful

Verified: date field usage is consistent across all transaction types.

The addition of the date field with the fallback mechanism (transaction.bookingDate || transaction.valueDate) aligns with existing implementations throughout the codebase. This change effectively addresses the regression issue and maintains uniformity across all transaction handling modules.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check usage of bookingDate and valueDate in the codebase

# Search for bookingDate usage
echo "Usage of bookingDate:"
rg --type js 'bookingDate' -C 2

echo "\nUsage of valueDate:"
rg --type js 'valueDate' -C 2

echo "\nCheck for any other date fields that might be relevant:"
rg --type js '\b\w+Date\b' -C 2

Length of output: 157218

src/app-gocardless/banks/tests/bancsabadell-bsabesbbb.spec.js (1)

Line range hint 1-55: Overall, the changes effectively address the regression issue.

The updates to the existing test cases and the addition of the new "extract date" test case align well with the PR objectives. These changes provide good coverage for the date field normalization functionality.

To further enhance the test suite:

  1. Consider adding assertions for the date field in the existing test cases.
  2. Add a test case to verify the fallback behavior when bookingDate is not present.

These additions would ensure comprehensive coverage of the date normalization logic.

@MikesGlitch MikesGlitch self-assigned this Oct 12, 2024
Copy link
Contributor

@MikesGlitch MikesGlitch left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks

@MikesGlitch MikesGlitch merged commit a8c4c5f into actualbudget:master Oct 12, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants