Skip to content

Commit 75320b4

Browse files
authored
fix: DTOSS-10107 fix rule 30 (#1453)
* DTOSS-10107 fix rule 30 * DTOSS-10107 unit test added * DTOSS-10107 resolve PR comments
1 parent da1be74 commit 75320b4

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

application/CohortManager/src/Functions/ScreeningValidationService/StaticValidation/Breast_Screening_staticRules.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"Rules": [
9898
{
9999
"RuleName": "30.Postcode.NBO.NonFatal",
100-
"Expression": "string.IsNullOrEmpty(participant.Postcode) OR ValidationHelper.ValidatePostcode(participant.Postcode)",
100+
"Expression": "string.IsNullOrEmpty(participant.Postcode) OR ValidationHelper.ValidatePostcode(participant.Postcode) OR participant.Postcode == \"ZZZSECUR\"",
101101
"Actions": {
102102
"OnFailure": {
103103
"Name": "OutputExpression",

application/CohortManager/src/Functions/Shared/Common/ValidationHelper.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,12 @@ public static bool ValidateNHSNumber(string nhsNumber)
8888
public static bool ValidatePostcode(string postcode)
8989
{
9090
string validPostcodePattern = "^([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})$";
91-
string dummyPostcodePattern1 = "^ZZ99 ?[0-9][A-Z]{2}$";
92-
string dummyPostcodePattern2 = "^ZZZSECUR$";
91+
string dummyPostcodePattern = "^ZZ99 ?[0-9][A-Z]{2}$";
9392

9493
Match validPostcodeMatch = Regex.Match(postcode, validPostcodePattern, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(2));
95-
Match dummyPostcodeMatch1 = Regex.Match(postcode, dummyPostcodePattern1, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(2));
96-
Match dummyPostcodeMatch2 = Regex.Match(postcode, dummyPostcodePattern2, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(2));
94+
Match dummyPostcodeMatch = Regex.Match(postcode, dummyPostcodePattern, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(2));
9795

98-
if (validPostcodeMatch.Success || dummyPostcodeMatch1.Success || dummyPostcodeMatch2.Success)
96+
if (validPostcodeMatch.Success || dummyPostcodeMatch.Success)
9997
return true;
10098

10199
return false;

tests/UnitTests/ScreeningValidationServiceTests/StaticValidation/StaticValidationTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ public async Task Run_DelRecord_DoNotRunCommonRules()
210210
[DataRow("ZZ99 9FZ")]
211211
[DataRow("ZZ999FZ")]
212212
[DataRow("ZZ99 3WZ")]
213+
[DataRow("ZZZSECUR")]
213214
public async Task Run_ValidPostcode_ReturnNoContent(string postcode)
214215
{
215216
// Arrange

tests/UnitTests/StaticTests/ValidationHelperTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,29 @@ public void ValidatePastDate_InvalidPastDateAlwaysFuture_ReturnsFalse()
7373

7474
Assert.IsFalse(result);
7575
}
76+
77+
[TestMethod]
78+
[DataRow("B33 8TH")] // Valid postcode format
79+
[DataRow("SW1A 1AA")] // Valid postcode format
80+
[DataRow("SM1 1AA")] // Valid postcode format
81+
[DataRow("ZZ99 3CZ")] // dummy postcode format
82+
public void ValidatePostcode_ValidPostcode_ReturnsTrue(string postCode)
83+
{
84+
var result = ValidationHelper.ValidatePostcode(postCode);
85+
86+
Assert.IsTrue(result);
87+
}
88+
89+
[TestMethod]
90+
[DataRow("A1")]
91+
[DataRow("ABCDE 123")]
92+
[DataRow("123 ABC")]
93+
[DataRow("W1A")]
94+
[DataRow("SW1A1AAA")]
95+
public void ValidatePostcode_InvalidPostcode_ReturnsFalse(string postCode)
96+
{
97+
var result = ValidationHelper.ValidatePostcode(postCode);
98+
99+
Assert.IsFalse(result);
100+
}
76101
}

0 commit comments

Comments
 (0)