Skip to content

Commit a200ca9

Browse files
fix: fixing unit tests
1 parent 30ec864 commit a200ca9

3 files changed

Lines changed: 35 additions & 10 deletions

File tree

application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/TransformDataLookupFacade.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ public bool ValidateOutcode(string postcode)
6868
?? throw new TransformationException("Postcode format invalid");
6969

7070
// we can bypass checking the database if it's a dummy postcode
71-
if (!parsedOutCode.isDummyPostCode)
71+
if (parsedOutCode.isDummyPostCode)
7272
{
73-
var result = _outcodeClient.GetSingle(parsedOutCode.outcode).Result;
74-
return result != null;
73+
return true;
7574
}
7675

77-
return true;
76+
var result = _outcodeClient.GetSingle(parsedOutCode.outcode).Result;
77+
return result != null;
78+
7879
}
7980

8081
/// <summary>

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Common;
22

33
using System.Globalization;
4+
using System.Linq.Expressions;
45
using System.Text.RegularExpressions;
56
using Hl7.Fhir.Validation;
67
using Model;
@@ -111,20 +112,26 @@ public static bool ValidatePostcode(string postcode)
111112
/// </remarks>
112113
public static (string? outcode, bool isDummyPostCode) ParseOutcode(string postcode)
113114
{
114-
bool isDummyPostCode = false;
115115
string pattern = @"^([A-Za-z][A-Za-z]?[0-9][A-Za-z0-9]?) ?[0-9][A-Za-z]{2}$";
116-
string dummyOutCodePattern = @"(([A-Za-z][A-Za-z]?[0-9][A-Za-z0-9]?) ?[0-9][A-Za-z]{2}|[A-Z]{8})$";
116+
string specialDummyOutCode = "ZZZSECUR";
117117

118118
Match match = Regex.Match(postcode, pattern, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(2));
119-
Match matchDummyOutcode = Regex.Match(postcode, dummyOutCodePattern, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(2));
120-
if (!match.Success && !matchDummyOutcode.Success)
119+
120+
if (postcode == specialDummyOutCode)
121+
{
122+
return (postcode, true);
123+
}
124+
125+
if (!match.Success)
121126
{
122-
return (null, isDummyPostCode);
127+
return (null, false);
123128
}
124129

130+
131+
125132
string outcode = match.Groups[1].Value;
126133

127-
return (outcode, matchDummyOutcode.Success);
134+
return (outcode, false);
128135
}
129136

130137
private static bool ParseInt32(char value, out int integerValue)

tests/UnitTests/TransformDataServiceTests/TransformDataServiceTests/TransformDataLookupFacadeTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,23 @@ public void ValidateOutcode_OutcodeNotFound_ReturnFalse()
9595
Assert.IsFalse(result);
9696
}
9797

98+
[TestMethod]
99+
public void ValidateOutcode_OutCodeIsSpecial_ReturnTrue()
100+
{
101+
// Arrange
102+
_outcodeClientMock
103+
.Setup(x => x.GetSingle(It.IsAny<string>()))
104+
.ReturnsAsync((BsSelectOutCode)null);
105+
106+
string postcode = "ZZZSECUR";
107+
108+
// Act
109+
bool result = _sut.ValidateOutcode(postcode);
110+
111+
// Assert
112+
Assert.IsTrue(result);
113+
}
114+
98115
[TestMethod]
99116
[DataRow("")]
100117
[DataRow("ABC123")]

0 commit comments

Comments
 (0)