Skip to content

Enhance FraudFundsTransferRequest with optional fields and validation…#414

Merged
rogelioLpz merged 6 commits into
mainfrom
feat/add-bank-code-and-payment-type
Jun 18, 2026
Merged

Enhance FraudFundsTransferRequest with optional fields and validation…#414
rogelioLpz merged 6 commits into
mainfrom
feat/add-bank-code-and-payment-type

Conversation

@rcabrera-py

@rcabrera-py rcabrera-py commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

… logic

  • Added optional fields: clabe, bank_code, and tipo_pago.
  • Implemented validation to ensure either clabe or bank_code is provided, and tipo_pago is required when bank_code is used.
  • Updated tests to cover new validation scenarios and parameterized input for better coverage.

Summary by CodeRabbit

Release Notes

  • New Features

    • Fraud funds transfer requests now accept bank code as an alternative to CLABE for specifying destination accounts
    • Validation has been enhanced to ensure either CLABE or bank code is provided with each transfer request
  • Tests

    • Test suite updated to verify proper bank code validation and required destination identifier enforcement

… logic

- Added optional fields: clabe, bank_code, and tipo_pago.
- Implemented validation to ensure either clabe or bank_code is provided, and tipo_pago is required when bank_code is used.
- Updated tests to cover new validation scenarios and parameterized input for better coverage.
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b80887a7-b02b-41aa-86e8-ae0c347082f5

📥 Commits

Reviewing files that changed from the base of the PR and between c31ff54 and a535409.

📒 Files selected for processing (1)
  • cuenca_validations/types/requests.py

Walkthrough

FraudFundsTransferRequest in cuenca_validations/types/requests.py is updated so that the transfer destination can be specified as either an optional clabe or a new optional bank_code field. The import is extended to include BANK_NAMES. A field_validator on bank_code rejects values not present in BANK_NAMES, and an after model validator raises a ValueError when both clabe and bank_code are None. Tests in test_fraud_funds_transfer_request are rewritten to cover the bank_code path, missing-destination errors, and invalid bank code errors. The version constant is bumped from 2.1.37 to 2.1.38.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • cuenca-mx/cuenca-validations#403: Modifies the same FraudFundsTransferRequest model and its tests, changing how transfer destination fields (including CLABE) are validated.

Suggested reviewers

  • gmorales96
  • rogelioLpz
🚥 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 accurately summarizes the main enhancement: making FraudFundsTransferRequest fields optional and adding validation logic.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/add-bank-code-and-payment-type

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

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (cb83524) to head (a535409).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #414   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        16           
  Lines         1490      1502   +12     
=========================================
+ Hits          1490      1502   +12     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cuenca_validations/types/requests.py 100.00% <100.00%> (ø)
cuenca_validations/version.py 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb83524...a535409. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/test_types.py (1)

720-734: ⚡ Quick win

Add invalid cases for blank bank_code to lock the new contract.

Current invalid coverage misses bank_code='' / whitespace-only, which should fail under the “destination required” rule. Adding these cases will prevent regressions once the model validator is tightened.

Suggested test additions
 `@pytest.mark.parametrize`(
     'data, expected_error',
     [
         (dict(user_id='US123'), 'clabe or bank_code required'),
+        (
+            dict(user_id='US123', bank_code=''),
+            'clabe or bank_code required',
+        ),
+        (
+            dict(user_id='US123', bank_code='   '),
+            'clabe or bank_code required',
+        ),
         (
             dict(user_id='US123', bank_code='40012'),
             'tipo_pago required when using bank_code',
         ),
     ],
 )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_types.py` around lines 720 - 734, Test coverage misses
blank/whitespace-only bank_code cases: update the param list in
test_fraud_funds_transfer_request_invalid to include entries for
dict(user_id='US123', bank_code='') and dict(user_id='US123', bank_code='  ')
with expected_error 'clabe or bank_code required' so FraudFundsTransferRequest
validation (the model used in test_fraud_funds_transfer_request_invalid) rejects
empty/whitespace bank_code values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cuenca_validations/types/requests.py`:
- Around line 330-340: validate_destination currently treats empty or
whitespace-only bank_code as present because it only checks for None; update the
validation to consider bank_code missing when it's None or blank/whitespace by
checking trimmed/string truthiness (e.g., treat bank_code as provided only if
bank_code and bank_code.strip()); use that same presence logic for both the
clabe-or-bank_code requirement and the tipo_pago dependency so that an empty
bank_code does not bypass the "clabe or bank_code required" rule and does not
trigger the tipo_pago-required branch incorrectly.

---

Nitpick comments:
In `@tests/test_types.py`:
- Around line 720-734: Test coverage misses blank/whitespace-only bank_code
cases: update the param list in test_fraud_funds_transfer_request_invalid to
include entries for dict(user_id='US123', bank_code='') and
dict(user_id='US123', bank_code='  ') with expected_error 'clabe or bank_code
required' so FraudFundsTransferRequest validation (the model used in
test_fraud_funds_transfer_request_invalid) rejects empty/whitespace bank_code
values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 497b4363-fe43-4a81-b457-71dce0dbb1d0

📥 Commits

Reviewing files that changed from the base of the PR and between cb83524 and 7532356.

📒 Files selected for processing (3)
  • cuenca_validations/types/requests.py
  • cuenca_validations/version.py
  • tests/test_types.py

Comment thread cuenca_validations/types/requests.py Outdated
- Bumped version to 2.1.38.dev1.
- Introduced FraudFundsTransferTipoPago enum for payment types.
- Updated FraudFundsTransferRequest to use FraudFundsTransferTipoPago for tipo_pago field.
- Modified tests to validate new tipo_pago values.
- Introduced BankCode as a validated type for bank codes.
- Implemented validation logic to ensure bank codes are valid.
- Updated FraudFundsTransferRequest to use BankCode for the bank_code field.
- Enhanced tests to cover invalid bank code scenarios.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cuenca_validations/types/general.py`:
- Line 5: The current import of BANK_NAMES and membership check in
validate_bank_code is using a non-public symbol; replace the usage with
clabe.get_bank_name(bank_code) instead: import get_bank_name (or call
clabe.get_bank_name) and call it inside validate_bank_code, treat any
falsy/exception result as invalid and raise the same validation error message
("Not a valid bank code"); ensure you remove the BANK_NAMES import and validate
that bank_code is the expected 3-digit code before calling get_bank_name to
match clabe's API.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a9821e9f-dcb7-40b7-9bf5-e2fd86757deb

📥 Commits

Reviewing files that changed from the base of the PR and between c1bee88 and 4e2bede.

📒 Files selected for processing (5)
  • cuenca_validations/types/__init__.py
  • cuenca_validations/types/general.py
  • cuenca_validations/types/requests.py
  • cuenca_validations/version.py
  • tests/test_types.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • cuenca_validations/version.py
  • cuenca_validations/types/requests.py
  • tests/test_types.py

Comment thread cuenca_validations/types/general.py Outdated
@rcabrera-py rcabrera-py requested a review from gmorales96 June 12, 2026 20:17
…um and update related tests to reflect the changes in valid payment types.
Comment thread cuenca_validations/types/requests.py Outdated
clabe: Clabe
clabe: Optional[Clabe] = None
bank_code: Optional[BankCode] = None
tipo_pago: Optional[FraudFundsTransferTipoPago] = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Quitar el campo tipo_pago y el enum.
No tiene sentido enviarlo desde el cliente

Comment thread cuenca_validations/version.py Outdated
@@ -1 +1 @@
__version__ = '2.1.37'
__version__ = '2.1.38.dev2'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Poner version final

Comment thread tests/test_types.py Outdated
Comment on lines +678 to +717
@pytest.mark.parametrize(
'data, expected_dump',
[
(
dict(
user_id='US123',
clabe='646180157098510917',
amount=10000,
concepto=' Devolución fraude ',
),
dict(
user_id='US123',
clabe='646180157098510917',
amount=10000,
concepto='Devolución fraude',
),
),
(
dict(user_id='US123', clabe='646180157098510917'),
dict(user_id='US123', clabe='646180157098510917'),
),
(
dict(
user_id='US123',
bank_code='40012',
tipo_pago=7,
amount=5000,
),
dict(
user_id='US123',
bank_code='40012',
tipo_pago=7,
amount=5000,
),
),
],
)
def test_fraud_funds_transfer_request(data, expected_dump):
request = FraudFundsTransferRequest(**data)
assert request.model_dump() == expected_dump

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Este test esta de sobra, estas validando que pydantic sirva

Comment thread tests/test_types.py Outdated
),
],
)
def test_fraud_funds_transfer_request_invalid(data, expected_error):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Deja solo un caso simple, sin bank_code ni clabe y borra el resto

- Bumped version to 2.1.38.
- Removed FraudFundsTransferTipoPago enum and its references from the codebase.
- Updated tests to reflect changes in the FraudFundsTransferRequest validation logic.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/test_types.py (1)

678-691: ⚡ Quick win

Consider adding test coverage for the clabe field.

While the new bank_code tests are well-structured and cover the key validation paths, the rewrite has removed all test coverage for the clabe field. Since clabe remains a valid way to specify the destination (per the validator in requests.py:328-339), consider adding at least one test case to verify backward compatibility.

For example:

def test_fraud_funds_transfer_request():
    # Test with bank_code
    assert FraudFundsTransferRequest(
        user_id='US123',
        bank_code='40012',
    ).model_dump() == {'user_id': 'US123', 'bank_code': '40012'}

    # Test with clabe (backward compatibility)
    assert FraudFundsTransferRequest(
        user_id='US123',
        clabe='646180157098510917',
    ).model_dump() == {'user_id': 'US123', 'clabe': '646180157098510917'}

    # Test missing both fields
    with pytest.raises(ValidationError) as exc:
        FraudFundsTransferRequest(user_id='US123')
    assert 'clabe or bank_code required' in str(exc.value)

    # Test invalid bank_code
    with pytest.raises(ValidationError) as exc:
        FraudFundsTransferRequest(user_id='US123', bank_code='99999')
    assert 'Not a valid bank code' in str(exc.value)

Note: I see past review comments suggesting simplification, but given that this PR introduces dual-destination support, comprehensive coverage of both paths seems appropriate.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_types.py` around lines 678 - 691, The
test_fraud_funds_transfer_request function lacks coverage for the clabe field,
which is still a valid destination option according to the validator in
requests.py. Add a test case after the initial bank_code test that verifies
FraudFundsTransferRequest correctly accepts and preserves the clabe field (e.g.,
with a valid clabe value like '646180157098510917'), ensuring backward
compatibility is maintained alongside the new bank_code functionality.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/test_types.py`:
- Around line 678-691: The test_fraud_funds_transfer_request function lacks
coverage for the clabe field, which is still a valid destination option
according to the validator in requests.py. Add a test case after the initial
bank_code test that verifies FraudFundsTransferRequest correctly accepts and
preserves the clabe field (e.g., with a valid clabe value like
'646180157098510917'), ensuring backward compatibility is maintained alongside
the new bank_code functionality.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9d6b9821-e5e4-43f9-9580-15d64b0548bb

📥 Commits

Reviewing files that changed from the base of the PR and between 4e2bede and c31ff54.

📒 Files selected for processing (4)
  • cuenca_validations/types/__init__.py
  • cuenca_validations/types/requests.py
  • cuenca_validations/version.py
  • tests/test_types.py
💤 Files with no reviewable changes (2)
  • cuenca_validations/types/init.py
  • cuenca_validations/types/requests.py
✅ Files skipped from review due to trivial changes (1)
  • cuenca_validations/version.py

Comment thread cuenca_validations/types/requests.py Outdated
user_id: NonEmptyStr
clabe: Clabe
clabe: Optional[Clabe] = None
bank_code: Optional[BankCode] = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Borra el type BankCode

Dejalo así bank_code:str y que tenga el validator este model

- Removed the BankCode type and its validation logic from the codebase.
- Updated FraudFundsTransferRequest to use a simple string for bank_code.
- Implemented a new field validator for bank_code to ensure it matches valid bank names.
- Adjusted related imports and cleaned up unused code in general.py and __init__.py.
@rogelioLpz rogelioLpz merged commit 62957a5 into main Jun 18, 2026
21 checks passed
@rogelioLpz rogelioLpz deleted the feat/add-bank-code-and-payment-type branch June 18, 2026 21:29
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.

2 participants