diff --git a/legal-api/pyproject.toml b/legal-api/pyproject.toml index f4905a4ce0..4ff8ae3594 100644 --- a/legal-api/pyproject.toml +++ b/legal-api/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "legal-api" -version = "3.1.38" +version = "3.1.39" description = "" authors = [ {name = "thor",email = "1042854+thorwolpert@users.noreply.github.com"} diff --git a/legal-api/src/legal_api/services/filings/validations/amalgamation_application.py b/legal-api/src/legal_api/services/filings/validations/amalgamation_application.py index 62435b114a..6a1b839aa0 100644 --- a/legal-api/src/legal_api/services/filings/validations/amalgamation_application.py +++ b/legal-api/src/legal_api/services/filings/validations/amalgamation_application.py @@ -127,7 +127,11 @@ def _validate_name_request_section(amalgamation_json, amalgamation_type, legal_t "path": f"/filing/{filing_type}/nameRequest/nrNumber" }] - return validate_name_request(amalgamation_json, legal_type, filing_type) + # a BC or BEN resulting business may use an NR of either type + bc_ben_legal_types = [Business.LegalTypes.COMP.value, Business.LegalTypes.BCOMP.value] + accepted_legal_types = bc_ben_legal_types if legal_type in bc_ben_legal_types else None + return validate_name_request(amalgamation_json, legal_type, filing_type, + accepted_legal_types=accepted_legal_types) def _structural_validation_errors(amalgamation_json, legal_type, filing_type) -> list: diff --git a/legal-api/src/legal_api/services/filings/validations/common_validations.py b/legal-api/src/legal_api/services/filings/validations/common_validations.py index 86498a63e8..6068396ec3 100644 --- a/legal-api/src/legal_api/services/filings/validations/common_validations.py +++ b/legal-api/src/legal_api/services/filings/validations/common_validations.py @@ -1059,11 +1059,12 @@ def _validate_relationship_date(date_value: date, return msg -def validate_name_request(filing_json: dict, # pylint: disable=too-many-locals +def validate_name_request(filing_json: dict, # noqa: PLR0913 # pylint: disable=too-many-locals legal_type: str, filing_type: str, accepted_request_types: list | None = None, - filing_id: int | None = None) -> list: + filing_id: int | None = None, + accepted_legal_types: list | None = None) -> list: """Validate name request section.""" nr_path = f"/filing/{filing_type}/nameRequest" nr_number_path = f"{nr_path}/nrNumber" @@ -1076,12 +1077,11 @@ def validate_name_request(filing_json: dict, # pylint: disable=too-many-locals if not nr_number and not legal_name: if legal_type in Business.CORPS: return [] # It's numbered company - else: - # CP, SP, GP doesn't support numbered company - return [{"error": _("Legal name and nrNumber is missing in nameRequest."), "path": nr_path}] - elif nr_number and not legal_name: + # CP, SP, GP doesn't support numbered company + return [{"error": _("Legal name and nrNumber is missing in nameRequest."), "path": nr_path}] + if nr_number and not legal_name: return [{"error": _("Legal name is missing in nameRequest."), "path": legal_name_path}] - elif not nr_number and legal_name: + if not nr_number and legal_name: # expecting nrNumber when legalName provided return [{ "error": _("nrNumber is missing for the legal name provided in nameRequest."), @@ -1108,7 +1108,7 @@ def validate_name_request(filing_json: dict, # pylint: disable=too-many-locals # ensure business type nr_legal_type = nr_response_json.get("legalType") - if legal_type != nr_legal_type: + if nr_legal_type not in (accepted_legal_types or [legal_type]): msg.append({"error": _("Name Request legal type is not same as the business legal type."), "path": legal_type_path}) diff --git a/legal-api/tests/unit/services/filings/validations/test_amalgamation_application.py b/legal-api/tests/unit/services/filings/validations/test_amalgamation_application.py index 7243e26db3..ed6db10eb7 100644 --- a/legal-api/tests/unit/services/filings/validations/test_amalgamation_application.py +++ b/legal-api/tests/unit/services/filings/validations/test_amalgamation_application.py @@ -104,6 +104,40 @@ def test_invalid_nr_amalgamation(mocker, app, session): assert err.msg[0]['error'] == 'Name Request is not approved.' +@pytest.mark.parametrize( + 'test_name, legal_type, nr_legal_type, expected_msg', + [ + ('SUCCESS_BC_NR_BC', Business.LegalTypes.COMP.value, Business.LegalTypes.COMP.value, None), + ('SUCCESS_BEN_NR_BEN', Business.LegalTypes.BCOMP.value, Business.LegalTypes.BCOMP.value, None), + ('SUCCESS_BEN_NR_BC', Business.LegalTypes.BCOMP.value, Business.LegalTypes.COMP.value, None), + ('SUCCESS_BC_NR_BEN', Business.LegalTypes.COMP.value, Business.LegalTypes.BCOMP.value, None), + ('FAIL_BC_NR_ULC', Business.LegalTypes.COMP.value, Business.LegalTypes.BC_ULC_COMPANY.value, + 'Name Request legal type is not same as the business legal type.'), + ('FAIL_ULC_NR_BC', Business.LegalTypes.BC_ULC_COMPANY.value, Business.LegalTypes.COMP.value, + 'Name Request legal type is not same as the business legal type.'), + ('FAIL_CC_NR_BEN', Business.LegalTypes.BC_CCC.value, Business.LegalTypes.BCOMP.value, + 'Name Request legal type is not same as the business legal type.'), + ] +) +def test_amalgamation_nr_legal_type(mocker, app, session, test_name, legal_type, nr_legal_type, expected_msg): + """Assert a BC or BEN resulting business accepts an NR of either type; other mismatches are rejected.""" + filing = _get_amalg_template() + filing['filing']['amalgamationApplication']['nameRequest']['nrNumber'] = 'NR 1234567' + filing['filing']['amalgamationApplication']['nameRequest']['legalType'] = legal_type + + mocker.patch('legal_api.services.filings.validations.amalgamation_application.validate_amalgamating_businesses', + return_value=[]) + with patch.object(NameXService, 'query_nr_number', return_value=_mock_nr_response(nr_legal_type)): + err = validate(None, filing) + + if expected_msg: + assert err.code == HTTPStatus.BAD_REQUEST + assert lists_are_equal(err.msg, [{'error': expected_msg, + 'path': '/filing/amalgamationApplication/nameRequest/legalType'}]) + else: + assert err is None + + @pytest.mark.parametrize( 'amalgamation_type', [