diff --git a/application/CohortManager/src/Functions/ParticipantManagementServices/UpdateBlockedFlag/BlockParticipantHandler.cs b/application/CohortManager/src/Functions/ParticipantManagementServices/UpdateBlockedFlag/BlockParticipantHandler.cs index 0c7646d8eb..05464039bb 100644 --- a/application/CohortManager/src/Functions/ParticipantManagementServices/UpdateBlockedFlag/BlockParticipantHandler.cs +++ b/application/CohortManager/src/Functions/ParticipantManagementServices/UpdateBlockedFlag/BlockParticipantHandler.cs @@ -53,8 +53,20 @@ public async Task BlockParticipant(BlockParticipantDto b return new BlockParticipantResult(false, "Participant Already Blocked"); } + var pdsParticipant = await GetPDSParticipant(blockParticipantRequest.NhsNumber); + + if (pdsParticipant == null ) + { + return new BlockParticipantResult(false, "Participant details do not match a record in PDS"); + } + var participantDemographic = await _participantDemographicDataService.GetSingleByFilter(x => x.NhsNumber == blockParticipantRequest.NhsNumber); + if (participantDemographic == null) + { + return new BlockParticipantResult(false, "Can not retrieve record from demographic"); + } + if (!ValidateRecordsMatch(participantDemographic, blockParticipantRequest)) { _logger.LogWarning("Participant didn't pass three point check and cannot be blocked"); diff --git a/tests/UnitTests/ParticipantManagementServicesTests/UpdateBlockedFlagTests/UpdateBlockedFlagTests.cs b/tests/UnitTests/ParticipantManagementServicesTests/UpdateBlockedFlagTests/UpdateBlockedFlagTests.cs index 209b8bead4..4da5f0348d 100644 --- a/tests/UnitTests/ParticipantManagementServicesTests/UpdateBlockedFlagTests/UpdateBlockedFlagTests.cs +++ b/tests/UnitTests/ParticipantManagementServicesTests/UpdateBlockedFlagTests/UpdateBlockedFlagTests.cs @@ -86,6 +86,18 @@ public async Task BlockParticipant_ExistingParticipant_ReturnsSuccess() DateOfBirth = "19231012" }); + var pdsDemoResponse = JsonSerializer.Serialize( + new PdsDemographic + { + NhsNumber = "6427635034", + FamilyName = "Jones", + DateOfBirth = "1923-10-12" + }); + + _mockHttpClient.Setup(x => x.SendGet("RetrievePdsDemographicUrl", It.IsAny>())) + .ReturnsAsync(pdsDemoResponse); + + _mockParticipantManagementClient.Setup(x => x.Update(It.IsAny())) .ReturnsAsync(true); _mockHttpClient.Setup(x => x.SendPost("NemsUnsubscribeUrl", It.IsAny>())) @@ -94,13 +106,13 @@ public async Task BlockParticipant_ExistingParticipant_ReturnsSuccess() StatusCode = HttpStatusCode.OK }); - //act var result = await _sut.BlockParticipant(_request.Object); //asset Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); _mockHttpClient.Verify(x => x.SendPost("NemsUnsubscribeUrl", It.IsAny>()), Times.Once); + _mockHttpClient.Verify(x => x.SendGet("RetrievePdsDemographicUrl", It.IsAny>()), Times.Once); _mockParticipantManagementClient.Verify(x => x.Update(It.IsAny()), Times.Once); _mockHttpClient.VerifyNoOtherCalls(); } @@ -232,10 +244,11 @@ public async Task BlockParticipant_ExistingParticipantFailsThreePointCheck_Retur //asset Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); _mockHttpClient.Verify(x => x.SendPost("NemsUnsubscribeUrl", It.IsAny>()), Times.Never); + _mockHttpClient.Verify(x => x.SendGet("RetrievePdsDemographicUrl", It.IsAny>()), Times.Once); _mockHttpClient.VerifyNoOtherCalls(); _mockParticipantManagementClient.Verify(x => x.GetSingleByFilter(It.IsAny>>()), Times.Once); _mockParticipantManagementClient.VerifyNoOtherCalls(); - _mockParticipantDemographicClient.Verify(x => x.GetSingleByFilter(It.IsAny>>()), Times.Once); + _mockParticipantDemographicClient.Verify(x => x.GetSingleByFilter(It.IsAny>>()), Times.Never); _mockParticipantDemographicClient.VerifyNoOtherCalls(); } [TestMethod]