Enhance FraudFundsTransferRequest with optional fields and validation…#414
Enhance FraudFundsTransferRequest with optional fields and validation…#414rcabrera-py wants to merge 3 commits into
Conversation
… 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.
WalkthroughFraudFundsTransferRequest now accepts destination via either CLABE or bank_code with tipo_pago. The clabe field is now optional; new optional fields bank_code and tipo_pago were added. An after-model validator requires at least one of clabe or bank_code, and requires tipo_pago when bank_code is provided. A new FraudFundsTransferTipoPago IntEnum was introduced and exported. A BankCode annotated type and validator were added and exported. Tests were expanded with parametrized valid and invalid cases. Package version bumped to 2.1.38.dev2. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #414 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 16 16
Lines 1490 1509 +19
=========================================
+ Hits 1490 1509 +19
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/test_types.py (1)
720-734: ⚡ Quick winAdd invalid cases for blank
bank_codeto 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
📒 Files selected for processing (3)
cuenca_validations/types/requests.pycuenca_validations/version.pytests/test_types.py
- 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.
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
cuenca_validations/types/__init__.pycuenca_validations/types/general.pycuenca_validations/types/requests.pycuenca_validations/version.pytests/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
… logic
Summary by CodeRabbit