Skip to content

32910 Add Validation for Foreign Business Identifier Format and MRAS …#4419

Merged
mruff-aeq merged 3 commits into
bcgov:mainfrom
mruff-aeq:32910_Add_Validation_for_Foreign_Business_Identifier_Format_and_MRAS_Requirement
May 20, 2026
Merged

32910 Add Validation for Foreign Business Identifier Format and MRAS …#4419
mruff-aeq merged 3 commits into
bcgov:mainfrom
mruff-aeq:32910_Add_Validation_for_Foreign_Business_Identifier_Format_and_MRAS_Requirement

Conversation

@mruff-aeq
Copy link
Copy Markdown
Collaborator

#32910 : /bcgov/entity#32910

Description of changes:

For any foreign amalgamating business, the backend previously failed to validate the identifier. The frontend required an identifier when the foreign jurisdiction was MRAS — meaning country = CA and region in AB, MB, NS, ON, QC, SK — and enforced:

  • 3–40 character length
  • Pattern: ^[0-9a-zA-Z-]+$

However, the backend only used the identifier for duplicate detection and did not validate format, length, or MRAS-based conditionality. As a result, invalid values could be saved.

The backend now mirrors the frontend rules:

  • If the jurisdiction is MRAS, the identifier is required.
  • If an identifier is present (MRAS or not), it must:
    • Be 3–40 characters
    • Match ^[0-9a-zA-Z-]+$
  • Any violation returns HTTP 400.

Example:

POST to
/api/v2/businesses/<T-id>/filings?only_validate=true

Case Payload change to the foreign business Result
A — baseline (valid identifier, MRAS jurisdiction) "identifier": "A1234567", "foreignJurisdiction": { "country": "CA", "region": "AB" } 200 — no error
B — MRAS jurisdiction, missing identifier "identifier": "", "foreignJurisdiction": { "country": "CA", "region": "AB" } 400 — "Identifier is required for foreign businesses from MRAS jurisdictions."
C — identifier too short "identifier": "AB", "foreignJurisdiction": { "country": "CA", "region": "AB" } 400 — "Foreign business identifier must be between 3 and 40 characters."
D — identifier too long (41 chars) "identifier": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "foreignJurisdiction": { "country": "CA", "region": "AB" } 400 — "Foreign business identifier must be between 3 and 40 characters."
E — disallowed character (ticket example) "identifier": "SK#99001", "foreignJurisdiction": { "country": "CA", "region": "SK" } 400 — "Foreign business identifier may only contain letters, numbers, and hyphens."
F — non-MRAS jurisdiction, no identifier "identifier": "", "foreignJurisdiction": { "country": "CA", "region": "NB" } 200 — no error; outside MRAS the identifier is optional, matching the frontend

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the lear license (Apache 2.0).

@mruff-aeq mruff-aeq requested review from kialj876, loneil and meawong May 20, 2026 09:29
Copy link
Copy Markdown
Collaborator

@loneil loneil left a comment

Choose a reason for hiding this comment

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

Change looks good, let's just add a unit test for _validate_foreign_identifier with parameterized data covering the examples in the PR description (that's a good list for coverage).

Can take a look in /home/loneil/development/registries/lear/legal-api/tests/unit/services/filings/validations/test_amalgamation_application.py

Can be just an atomic test importing _validate_foreign_identifier, running it against the params (take a look at other @pytest.mark.parametrize examples if needed) asserting the errors. Can search for test_validate_incorporation_party_names as an example of this pattern

@mruff-aeq mruff-aeq requested a review from loneil May 20, 2026 19:27
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Collaborator

@loneil loneil left a comment

Choose a reason for hiding this comment

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

Looks good

@mruff-aeq mruff-aeq merged commit 0514c80 into bcgov:main May 20, 2026
8 checks passed
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