Skip to content

Commit

Permalink
Merge pull request #2258 from uktrade/LTD-5692-fix-crn-validation
Browse files Browse the repository at this point in the history
LTD-5692-fix-crn-validation
  • Loading branch information
depsiatwal authored Dec 4, 2024
2 parents 2fa5d68 + aac8874 commit c665057
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
2 changes: 1 addition & 1 deletion exporter/core/organisation/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Validation:
UK_VAT_VALIDATION_REGEX = r"^(GB|XI)?([0-9]{9}([0-9]{3})?|(GD|HA)[0-9]{3})$"
UK_EORI_STARTING_LETTERS_REGEX = r"^(GB|XI)"
SIC_NUMBERs_ONLY_REGEX = r"^\d+$"
REGISTRATION_NUM_VALIDATION_REGEX = r"^(RC\d+|\d+)$"
REGISTRATION_NUM_VALIDATION_REGEX = r"^((RC|NI)\d{6}|\d{8})$"

ADDRESS_LINE_MAX_LENGTH = 35
UK_EORI_MAX_LENGTH = 17
Expand Down
63 changes: 53 additions & 10 deletions unit_tests/exporter/core/organisation/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ def test_register_details_form_required_fields(
"Enter a SIC code that is 5 numbers long, like 12345",
"SIC code can only include numbers",
],
"registration_number": ["The CRN or RC number is too long"],
"registration_number": [
"The CRN or RC number is too long",
"Enter a CRN or RC number in the correct format",
],
},
forms.RegisterDetailsCommercialOverseasForm,
),
Expand All @@ -177,7 +180,10 @@ def test_register_details_form_required_fields(
{
"sic_number": ["Enter a SIC code that is 5 numbers long, like 12345"],
"vat_number": ["UK VAT number is too long", "Enter a UK VAT number in the correct format"],
"registration_number": ["The CRN or RC number is too long"],
"registration_number": [
"The CRN or RC number is too long",
"Enter a CRN or RC number in the correct format",
],
},
forms.RegisterDetailsCommercialUKForm,
),
Expand All @@ -200,7 +206,10 @@ def test_register_details_form_required_fields(
"UK VAT number can only include numbers and letters",
"Enter a UK VAT number in the correct format",
],
"registration_number": ["The CRN or RC number is too long"],
"registration_number": [
"The CRN or RC number is too long",
"Enter a CRN or RC number in the correct format",
],
},
forms.RegisterDetailsCommercialUKForm,
),
Expand All @@ -223,7 +232,10 @@ def test_register_details_form_required_fields(
"UK VAT number can only include numbers and letters",
"Enter a UK VAT number in the correct format",
],
"registration_number": ["The CRN or RC number is too long"],
"registration_number": [
"The CRN or RC number is too long",
"Enter a CRN or RC number in the correct format",
],
},
forms.RegisterDetailsCommercialUKForm,
),
Expand Down Expand Up @@ -311,7 +323,10 @@ def test_register_details_form_field_validation(
},
False,
{
"registration_number": ["The CRN or RC number is too long"],
"registration_number": [
"The CRN or RC number is too long",
"Enter a CRN or RC number in the correct format",
],
},
),
(
Expand All @@ -320,7 +335,10 @@ def test_register_details_form_field_validation(
},
False,
{
"registration_number": ["The CRN or RC number is too short"],
"registration_number": [
"The CRN or RC number is too short",
"Enter a CRN or RC number in the correct format",
],
},
),
(
Expand Down Expand Up @@ -350,7 +368,7 @@ def test_register_details_form_field_validation(
),
(
{
"registration_number": "FF123456",
"registration_number": "123456RC",
},
False,
{
Expand All @@ -359,7 +377,7 @@ def test_register_details_form_field_validation(
),
(
{
"registration_number": "123456RC",
"registration_number": "ABC12345",
},
False,
{
Expand All @@ -368,14 +386,39 @@ def test_register_details_form_field_validation(
),
(
{
"registration_number": "RC123456",
"registration_number": "A1234567",
},
False,
{
"registration_number": ["Enter a CRN or RC number in the correct format"],
},
),
(
{
"registration_number": "SO123456",
},
False,
{
"registration_number": ["Enter a CRN or RC number in the correct format"],
},
),
(
{
"registration_number": "12345678",
},
True,
None,
),
(
{
"registration_number": "12345678",
"registration_number": "NI123456",
},
True,
None,
),
(
{
"registration_number": "RC123456",
},
True,
None,
Expand Down

0 comments on commit c665057

Please sign in to comment.