From 1b8ded20e03f2c9f2a55bc905c767cb7b9afb71c Mon Sep 17 00:00:00 2001 From: meawong Date: Wed, 4 Mar 2026 11:13:53 -0800 Subject: [PATCH] 32594 - Add validation and unit tests --- .../filings/validations/restoration.py | 11 ++++ .../filings/validations/test_restoration.py | 66 +++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/legal-api/src/legal_api/services/filings/validations/restoration.py b/legal-api/src/legal_api/services/filings/validations/restoration.py index 06a19ba760..5bd814ba36 100644 --- a/legal-api/src/legal_api/services/filings/validations/restoration.py +++ b/legal-api/src/legal_api/services/filings/validations/restoration.py @@ -51,6 +51,7 @@ def validate(business: Business, restoration: dict) -> Optional[Error]: "limitedRestoration") if restoration_type in ("limitedRestoration", "limitedRestorationExtension"): msg.extend(validate_expiry_date(business, restoration, restoration_type)) + msg.extend(validate_contact_point(restoration)) elif restoration_type in ("fullRestoration", "limitedRestorationToFull"): msg.extend(validate_relationship(restoration)) @@ -81,6 +82,16 @@ def validate(business: Business, restoration: dict) -> Optional[Error]: return None +def validate_contact_point(filing: dict) -> list: + """Validate that no contact point is provided for limited restoration filings.""" + msg = [] + if filing.get("filing", {}).get("restoration", {}).get("contactPoint", None): + msg.append({"error": "Contact point must not be provided. " + "The corporation will be restored with the contact information it had prior to dissolution.", + "path": "/filing/restoration/contactPoint"}) + return msg + + def validate_expiry_date(business: Business, filing: dict, restoration_type: str) -> list: """Validate expiry date.""" msg = [] diff --git a/legal-api/tests/unit/services/filings/validations/test_restoration.py b/legal-api/tests/unit/services/filings/validations/test_restoration.py index 8df3e4f38d..ffc7e1b1b4 100644 --- a/legal-api/tests/unit/services/filings/validations/test_restoration.py +++ b/legal-api/tests/unit/services/filings/validations/test_restoration.py @@ -95,6 +95,9 @@ def execute_test_restoration_nr(mocker, filing_sub_type, legal_type, nr_number, mock_nr_response = MockResponse(temp_nr_response, HTTPStatus.OK) mocker.patch('legal_api.services.NameXService.query_nr_number', return_value=mock_nr_response) + + if filing['filing']['restoration']['type'] in ('limitedRestoration', 'limitedRestorationExtension'): + del filing['filing']['restoration']['contactPoint'] with patch.object(Filing, 'get_most_recent_filing', return_value=limited_restoration_filing): err = validate(business, filing) @@ -141,6 +144,10 @@ def test_validate_party(session, test_name, party_role, expected_msg): filing['filing']['restoration']['parties'][0]['roles'][0]['roleType'] = party_role else: filing['filing']['restoration']['parties'] = [] + + if filing['filing']['restoration']['type'] in ('limitedRestoration', 'limitedRestorationExtension'): + del filing['filing']['restoration']['contactPoint'] + err = validate(business, filing) if expected_msg: @@ -177,6 +184,7 @@ def test_validate_relationship(session, test_status, restoration_type, expected_ filing['filing']['restoration']['nameRequest']['legalName'] = legal_name if restoration_type in ('limitedRestoration', 'limitedRestorationExtension'): + del filing['filing']['restoration']['contactPoint'] expiry_date = LegislationDatetime.now() + relativedelta(months=1) filing['filing']['restoration']['expiry'] = expiry_date.strftime(date_format) elif test_status == 'SUCCESS' and restoration_type in ('fullRestoration', 'limitedRestorationToFull'): @@ -233,6 +241,9 @@ def test_validate_expiry_date(session, test_name, restoration_type, delta_date, filing['filing']['restoration']['type'] = restoration_type if delta_date: filing['filing']['restoration']['expiry'] = expiry_date.strftime(date_format) + + if restoration_type in ('limitedRestoration', 'limitedRestorationExtension'): + del filing['filing']['restoration']['contactPoint'] with patch.object(Filing, 'get_most_recent_filing', return_value=limited_restoration_filing): err = validate(business, filing) @@ -283,6 +294,9 @@ def test_approval_type(session, test_status, restoration_types, legal_types, app filing['filing']['restoration']['applicationDate'] = '2023-03-30' filing['filing']['restoration']['noticeDate'] = '2023-03-30' + if restoration_type in ('limitedRestoration', 'limitedRestorationExtension'): + del filing['filing']['restoration']['contactPoint'] + with patch.object(Filing, 'get_most_recent_filing', return_value=limited_restoration_filing): err = validate(business, filing) @@ -339,6 +353,9 @@ def test_restoration_court_orders(session, test_status, restoration_types, legal else: del filing['filing']['restoration']['courtOrder'] + if restoration_type in ('limitedRestoration', 'limitedRestorationExtension'): + del filing['filing']['restoration']['contactPoint'] + with patch.object(Filing, 'get_most_recent_filing', return_value=limited_restoration_filing): err = validate(business, filing) @@ -396,6 +413,9 @@ def test_restoration_registrar(session, test_status, restoration_types, legal_ty if notice_date: filing['filing']['restoration']['noticeDate'] = notice_date + if restoration_type in ('limitedRestoration', 'limitedRestorationExtension'): + del filing['filing']['restoration']['contactPoint'] + with patch.object(Filing, 'get_most_recent_filing', return_value=limited_restoration_filing): err = validate(business, filing) @@ -533,3 +553,49 @@ def test_validate_restoration_name_translation(session, test_name, name_translat if err: print(err, err.code, err.msg) assert err is None + +@pytest.mark.parametrize( + 'test_status, restoration_type, has_contact_point, expected_code, expected_msg', + [ + ('SUCCESS', 'limitedRestoration', False, None, None), + ('SUCCESS', 'limitedRestorationExtension', False, None, None), + ('FAIL', 'limitedRestoration', True, HTTPStatus.BAD_REQUEST, + 'Contact point must not be provided. ' + 'The corporation will be restored with the contact information it had prior to dissolution.'), + ('FAIL', 'limitedRestorationExtension', True, HTTPStatus.BAD_REQUEST, + 'Contact point must not be provided. ' + 'The corporation will be restored with the contact information it had prior to dissolution.'), + ] +) +def test_validate_contact_point(session, test_status, restoration_type, has_contact_point, expected_code, expected_msg): + """Assert that contact point is not allowed for limited restoration filings.""" + business = Business(identifier='BC1234567', legal_type='BC', restoration_expiry_date=LegislationDatetime.now()) + limited_restoration_filing = None + if restoration_type == 'limitedRestorationExtension': + limited_restoration_filing = factory_limited_restoration_filing() + + filing = copy.deepcopy(FILING_HEADER) + filing['filing']['restoration'] = copy.deepcopy(RESTORATION) + filing['filing']['header']['name'] = 'restoration' + filing['filing']['restoration']['type'] = restoration_type + + expiry_date = LegislationDatetime.now() + relativedelta(months=1) + filing['filing']['restoration']['expiry'] = expiry_date.strftime(date_format) + + if restoration_type == 'limitedRestorationExtension': + del filing['filing']['restoration']['nameRequest'] + else: + filing['filing']['restoration']['nameRequest']['legalName'] = legal_name + + if not has_contact_point: + del filing['filing']['restoration']['contactPoint'] + + with patch.object(Filing, 'get_most_recent_filing', + return_value=limited_restoration_filing): + err = validate(business, filing) + + if expected_code: + assert expected_code == err.code + assert expected_msg == err.msg[0]['error'] + else: + assert not err