Skip to content

Commit e557d0d

Browse files
fix: added logic to get data from PDS and update Demographic table (#1857)
* fix: added logic to get data from PDS and update Demographic table * updated test class * updated test class * test class update
1 parent 930ce96 commit e557d0d

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

application/CohortManager/src/Functions/ParticipantManagementServices/UpdateBlockedFlag/BlockParticipantHandler.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,20 @@ public async Task<BlockParticipantResult> BlockParticipant(BlockParticipantDto b
5353
return new BlockParticipantResult(false, "Participant Already Blocked");
5454
}
5555

56+
var pdsParticipant = await GetPDSParticipant(blockParticipantRequest.NhsNumber);
57+
58+
if (pdsParticipant == null )
59+
{
60+
return new BlockParticipantResult(false, "Participant details do not match a record in PDS");
61+
}
62+
5663
var participantDemographic = await _participantDemographicDataService.GetSingleByFilter(x => x.NhsNumber == blockParticipantRequest.NhsNumber);
5764

65+
if (participantDemographic == null)
66+
{
67+
return new BlockParticipantResult(false, "Can not retrieve record from demographic");
68+
}
69+
5870
if (!ValidateRecordsMatch(participantDemographic, blockParticipantRequest))
5971
{
6072
_logger.LogWarning("Participant didn't pass three point check and cannot be blocked");

tests/UnitTests/ParticipantManagementServicesTests/UpdateBlockedFlagTests/UpdateBlockedFlagTests.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ public async Task BlockParticipant_ExistingParticipant_ReturnsSuccess()
8686
DateOfBirth = "19231012"
8787
});
8888

89+
var pdsDemoResponse = JsonSerializer.Serialize(
90+
new PdsDemographic
91+
{
92+
NhsNumber = "6427635034",
93+
FamilyName = "Jones",
94+
DateOfBirth = "1923-10-12"
95+
});
96+
97+
_mockHttpClient.Setup(x => x.SendGet("RetrievePdsDemographicUrl", It.IsAny<Dictionary<string, string>>()))
98+
.ReturnsAsync(pdsDemoResponse);
99+
100+
89101
_mockParticipantManagementClient.Setup(x => x.Update(It.IsAny<ParticipantManagement>()))
90102
.ReturnsAsync(true);
91103
_mockHttpClient.Setup(x => x.SendPost("NemsUnsubscribeUrl", It.IsAny<Dictionary<string, string>>()))
@@ -94,13 +106,13 @@ public async Task BlockParticipant_ExistingParticipant_ReturnsSuccess()
94106
StatusCode = HttpStatusCode.OK
95107
});
96108

97-
98109
//act
99110
var result = await _sut.BlockParticipant(_request.Object);
100111

101112
//asset
102113
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
103114
_mockHttpClient.Verify(x => x.SendPost("NemsUnsubscribeUrl", It.IsAny<Dictionary<string, string>>()), Times.Once);
115+
_mockHttpClient.Verify(x => x.SendGet("RetrievePdsDemographicUrl", It.IsAny<Dictionary<string, string>>()), Times.Once);
104116
_mockParticipantManagementClient.Verify(x => x.Update(It.IsAny<ParticipantManagement>()), Times.Once);
105117
_mockHttpClient.VerifyNoOtherCalls();
106118
}
@@ -232,10 +244,11 @@ public async Task BlockParticipant_ExistingParticipantFailsThreePointCheck_Retur
232244
//asset
233245
Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);
234246
_mockHttpClient.Verify(x => x.SendPost("NemsUnsubscribeUrl", It.IsAny<Dictionary<string, string>>()), Times.Never);
247+
_mockHttpClient.Verify(x => x.SendGet("RetrievePdsDemographicUrl", It.IsAny<Dictionary<string, string>>()), Times.Once);
235248
_mockHttpClient.VerifyNoOtherCalls();
236249
_mockParticipantManagementClient.Verify(x => x.GetSingleByFilter(It.IsAny<Expression<Func<ParticipantManagement, bool>>>()), Times.Once);
237250
_mockParticipantManagementClient.VerifyNoOtherCalls();
238-
_mockParticipantDemographicClient.Verify(x => x.GetSingleByFilter(It.IsAny<Expression<Func<ParticipantDemographic, bool>>>()), Times.Once);
251+
_mockParticipantDemographicClient.Verify(x => x.GetSingleByFilter(It.IsAny<Expression<Func<ParticipantDemographic, bool>>>()), Times.Never);
239252
_mockParticipantDemographicClient.VerifyNoOtherCalls();
240253
}
241254
[TestMethod]

0 commit comments

Comments
 (0)