diff --git a/DigitalLearningSolutions.Web.Tests/Controllers/Register/RegisterDelegateByCentreControllerTests.cs b/DigitalLearningSolutions.Web.Tests/Controllers/Register/RegisterDelegateByCentreControllerTests.cs index 0040c2b514..0d4a77fc61 100644 --- a/DigitalLearningSolutions.Web.Tests/Controllers/Register/RegisterDelegateByCentreControllerTests.cs +++ b/DigitalLearningSolutions.Web.Tests/Controllers/Register/RegisterDelegateByCentreControllerTests.cs @@ -176,7 +176,7 @@ public void LearnerInformationPost_updates_tempdata_correctly() const string answer4 = "answer4"; const string answer5 = "answer5"; const string answer6 = "answer6"; - const string professionalRegistrationNumber = "PR123456"; + const string professionalRegistrationNumber = "PRN1234"; var model = new LearnerInformationViewModel { JobGroup = jobGroupId, diff --git a/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Delegates/EditDelegateControllerTests.cs b/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Delegates/EditDelegateControllerTests.cs index c08f3dbe35..5c5df8ac44 100644 --- a/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Delegates/EditDelegateControllerTests.cs +++ b/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Delegates/EditDelegateControllerTests.cs @@ -175,7 +175,7 @@ public void Index_post_returns_view_with_model_error_with_invalid_prn() result.As().Model.Should().BeOfType(); AssertModelStateErrorIsExpected( result, - ErrorMessagesTestHelper.InvalidFormatError + "Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed" ); A.CallTo(() => userService.GetDelegateById(A._)).MustNotHaveHappened(); } diff --git a/DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs b/DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs index a7270f280d..d78c74f042 100644 --- a/DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs +++ b/DigitalLearningSolutions.Web.Tests/Helpers/ProfessionalRegistrationNumberHelperTests.cs @@ -1,12 +1,11 @@ namespace DigitalLearningSolutions.Web.Tests.Helpers { + using System.Linq; using DigitalLearningSolutions.Web.Helpers; - using DigitalLearningSolutions.Web.Tests.TestHelpers; using FluentAssertions; using FluentAssertions.Execution; using Microsoft.AspNetCore.Mvc.ModelBinding; using NUnit.Framework; - using System.Linq; public class ProfessionalRegistrationNumberHelperTests { @@ -71,7 +70,7 @@ public void ValidateProfessionalRegistrationNumber_does_not_set_errors_when_vali { // Given var state = new ModelStateDictionary(); - const string validPrn = "AB123456"; + const string validPrn = "abc-123"; // When ProfessionalRegistrationNumberHelper.ValidateProfessionalRegistrationNumber( @@ -105,13 +104,22 @@ public void ValidateProfessionalRegistrationNumber_sets_error_when_hasPrn_is_not } } - [TestCase(null, ErrorMessagesTestHelper.MissingNumberError)] - [TestCase("", ErrorMessagesTestHelper.MissingNumberError)] - [TestCase("1234", ErrorMessagesTestHelper.LengthError)] - [TestCase("1234", ErrorMessagesTestHelper.LengthError)] - [TestCase("01234_", ErrorMessagesTestHelper.InvalidFormatError)] - [TestCase("01234 ", ErrorMessagesTestHelper.InvalidFormatError)] - [TestCase("01234$", ErrorMessagesTestHelper.InvalidFormatError)] + [TestCase(null, "Enter a professional registration number")] + [TestCase("", "Enter a professional registration number")] + [TestCase("123", "Professional registration number must be between 5 and 20 characters")] + [TestCase("0123456789-0123456789", "Professional registration number must be between 5 and 20 characters")] + [TestCase( + "01234_", + "Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed" + )] + [TestCase( + "01234 ", + "Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed" + )] + [TestCase( + "01234$", + "Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed" + )] public void ValidateProfessionalRegistrationNumber_sets_error_when_prn_is_invalid( string prn, string expectedError diff --git a/DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs b/DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs deleted file mode 100644 index 7636944e7a..0000000000 --- a/DigitalLearningSolutions.Web.Tests/TestHelpers/ErrorMessagesTestHelper.cs +++ /dev/null @@ -1,17 +0,0 @@ - -namespace DigitalLearningSolutions.Web.Tests.TestHelpers -{ - public static class ErrorMessagesTestHelper - { - public const string InvalidFormatError = - "Invalid professional registration number format. " + - "Valid formats include: 7 digits (e.g., 1234567), 1–2 letters followed by 6 digits (e.g., AB123456), " + - "4–8 digits, an optional 'P' plus 5–6 digits, 'C' or 'P' plus 6 digits, " + - "an optional letter plus 5–6 digits, 'L' plus 4–6 digits, " + - "or 2 digits followed by a hyphen and 4–5 alphanumeric characters (e.g., 12-AB123)."; - - public const string MissingNumberError = "Enter a professional registration number"; - public const string LengthError = "Professional registration number must be between 5 and 20 characters"; - - } -} diff --git a/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs b/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs index 130c8d52b6..461d7ae46b 100644 --- a/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs +++ b/DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs @@ -1,7 +1,7 @@ namespace DigitalLearningSolutions.Web.Helpers { - using Microsoft.AspNetCore.Mvc.ModelBinding; using System.Text.RegularExpressions; + using Microsoft.AspNetCore.Mvc.ModelBinding; public class ProfessionalRegistrationNumberHelper { @@ -48,17 +48,13 @@ public static void ValidateProfessionalRegistrationNumber( ); } - const string pattern = @"^(\d{7}|[A-Za-z]{1,2}\d{6}|\d{4,8}|P?\d{5,6}|[C|P]\d{6}|[A-Za-z]?\d{5,6}|L\d{4,6}|\d{2}-[A-Za-z\d]{4,5})$"; + const string pattern = @"^[a-z\d-]+$"; var rg = new Regex(pattern, RegexOptions.IgnoreCase); if (!rg.Match(prn).Success) { modelState.AddModelError( "ProfessionalRegistrationNumber", - "Invalid professional registration number format. " + - "Valid formats include: 7 digits (e.g., 1234567), 1–2 letters followed by 6 digits (e.g., AB123456), " + - "4–8 digits, an optional 'P' plus 5–6 digits, 'C' or 'P' plus 6 digits, " + - "an optional letter plus 5–6 digits, 'L' plus 4–6 digits, " + - "or 2 digits followed by a hyphen and 4–5 alphanumeric characters (e.g., 12-AB123)." + "Invalid professional registration number format - Only alphanumeric characters (a-z, A-Z and 0-9) and hyphens (-) allowed" ); } }