Skip to content

Commit a30260d

Browse files
feat: TC_4B_Manage-mark_existing_participant_record_as_blocked_in _CohortManager - Participant Management (#1496)
* feat: adding tests for 7667 * fix: remvoing unwanted changes * chore:adrressing comments on PR * fix: removing uneeded changes * fix: removing uneeded changes * fix: making sure all tests pass * fix: removing unwanted changes * fix: removing unwanted changes * Update tests/playwright-tests/src/tests/e2e/epic4b-block-participant-tests/epic4b-7667-block-paricipant-tessuite.spec.ts Co-authored-by: Michael Clayson <michael.clayson1@nhs.net> * chore: addressing comments --------- Co-authored-by: Michael Clayson <michael.clayson1@nhs.net>
1 parent 2060772 commit a30260d

9 files changed

Lines changed: 283 additions & 5 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*.suo
2424
*.user
2525

26+
*host.json
27+
2628
# Visual Studio 2015/2017 cache/options directory
2729
.vs/
2830

@@ -115,3 +117,4 @@ application/CohortManager/src/Functions/*.json
115117
# Explicitly include test JSON files
116118
!**/playwright-tests/src/tests/e2e/testFiles/**/*.json
117119

120+

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,16 @@ private async Task<PdsDemographic> GetPDSParticipant(long nhsNumber)
236236
private static bool ValidateRecordsMatch(ParticipantDemographic participant, BlockParticipantDto dto)
237237
{
238238

239-
if (!DateOnly.TryParseExact(dto.DateOfBirth, "yyyy-MM-dd",new CultureInfo("en-GB"),DateTimeStyles.None, out var dtoDateOfBirth ))
239+
if (!DateOnly.TryParseExact(dto.DateOfBirth, "yyyy-MM-dd", new CultureInfo("en-GB"), DateTimeStyles.None, out var dtoDateOfBirth))
240240
{
241241
throw new FormatException("Date of Birth not in the correct format");
242242
}
243243

244-
if (!DateOnly.TryParseExact(participant.DateOfBirth, "yyyyMMdd",new CultureInfo("en-GB"),DateTimeStyles.None, out var parsedDob))
244+
if (!DateOnly.TryParseExact(participant.DateOfBirth, "yyyyMMdd", new CultureInfo("en-GB"), DateTimeStyles.None, out var parsedDob))
245245
{
246246
return false;
247247
}
248+
248249
return string.Equals(participant.FamilyName, dto.FamilyName, StringComparison.InvariantCultureIgnoreCase)
249250
&& participant.NhsNumber == dto.NhsNumber
250251
&& parsedDob == dtoDateOfBirth;
@@ -253,12 +254,12 @@ private static bool ValidateRecordsMatch(ParticipantDemographic participant, Blo
253254
private static bool ValidateRecordsMatch(PdsDemographic participant, BlockParticipantDto dto)
254255
{
255256

256-
if (!DateOnly.TryParseExact(dto.DateOfBirth, "yyyy-MM-dd",new CultureInfo("en-GB"),DateTimeStyles.None, out var dtoDateOfBirth ))
257+
if (!DateOnly.TryParseExact(dto.DateOfBirth, "yyyy-MM-dd", new CultureInfo("en-GB"), DateTimeStyles.None, out var dtoDateOfBirth))
257258
{
258259
throw new FormatException("Date of Birth not in the correct format");
259260
}
260261

261-
if (!DateOnly.TryParseExact(participant.DateOfBirth, "yyyyMMdd",new CultureInfo("en-GB"),DateTimeStyles.None, out var parsedDob))
262+
if (!DateOnly.TryParseExact(participant.DateOfBirth, "yyyyMMdd", new CultureInfo("en-GB"), DateTimeStyles.None, out var parsedDob))
262263
{
263264
return false;
264265
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public override async Task<HttpResponseMessage> SendPdsGet(string url, string be
5454
{
5555

5656
string path = nhsNumber is null ? "MockedPDSData/complete-patient.json" : $"MockedPDSData/complete-patient-{nhsNumber}.json";
57-
if(!File.Exists(path))
57+
if (!File.Exists(path))
5858
{
5959
return null;
6060
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export const sendHttpPOSTCall =
2+
async (
3+
url: string,
4+
body: string
5+
): Promise<Response> =>
6+
{
7+
const response = await fetch(url, {
8+
method: "POST",
9+
headers: {
10+
"Content-Type": "application/json",
11+
},
12+
body: body
13+
});
14+
15+
return response;
16+
}
17+
18+
export const sendHttpGet =
19+
async (
20+
url: string
21+
): Promise<Response> =>
22+
{
23+
const response = await fetch(url);
24+
return response;
25+
}
26+

tests/playwright-tests/src/api/distributionService/bsSelectService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const BlockParticipant = (
5555
return apiClient.postWithQuery(request, endpoint, payload);
5656
};
5757

58+
5859
export const UnblockParticipant = (
5960
request: APIRequestContext,
6061
payload: {

tests/playwright-tests/src/config/env.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const endpointBsSelectGetValidationExceptions = process.env.ENDPOINT_BS_SELECT_G
2121
const endpointSerNowReceiveParticipant = process.env.ENDPOINT_SERVICE_NOW_MESSAGE_HANDLER ?? '';
2222
const invalidEndpointSerNow = process.env.INVALID_ENDPOINT_SERVICE_NOW_MESSAGE_HANDLER ?? '';
2323
const participantPayloadPath = process.env.PARTICIPANT_PAYLOAD_PATH ?? '';
24+
const createPDSDemographicEnv = process.env.ENDPOINT_PDS_DEMOGRAPHIC ?? '';
25+
const subToNemsEndPoint = process.env.ENDPOINT_SUB_TO_NEMS ?? ''
2426

2527
export const config = {
2628
baseURL,
@@ -36,7 +38,10 @@ export const config = {
3638
endpointBsSelectUpdateBlockFlag: endpointBsSelectUpdateBlockFlag,
3739
endpointBsSelectGetValidationExceptions: endpointBsSelectGetValidationExceptions,
3840
endpointSerNowReceiveParticipant: endpointSerNowReceiveParticipant,
41+
createPDSDemographic: createPDSDemographicEnv,
3942
invalidEndpointSerNow: invalidEndpointSerNow,
43+
SubToNems: subToNemsEndPoint,
44+
SubToNemsPath: 'api/Subscribe',
4045
routeBsSelectRetrieveCohortDistributionData: 'api/RetrieveCohortDistributionData',
4146
routeBsSelectRetrieveCohortRequestAudit: 'api/RetrieveCohortRequestAudit',
4247
routeBsSelectDeleteParticipant: 'api/DeleteParticipant',
@@ -49,6 +54,7 @@ export const config = {
4954
participantManagementService: 'ParticipantManagementDataService',
5055
exceptionManagementService: 'ExceptionManagementDataService',
5156
participantDemographicDataService: 'ParticipantDemographicDataService',
57+
createPDSDemographicPath: 'api/RetrievePdsDemographic',
5258
participantPayloadPath: 'src/tests/api/testFiles',
5359
e2eTestFilesPath: 'e2e/testFiles',
5460
apiTestFilesPath: 'api/testFiles',
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"validations": [
3+
{
4+
"validations": {
5+
"apiEndpoint": "api/CohortDistributionDataService",
6+
"NHSNumber": 9998380197
7+
}
8+
}
9+
],
10+
"inputParticipantRecord": [
11+
{
12+
"record_type": "ADD",
13+
"change_time_stamp": null,
14+
"serial_change_number": 1,
15+
"nhs_number": 9998380197,
16+
"superseded_by_nhs_number": null,
17+
"primary_care_provider": "A81623",
18+
"primary_care_effective_from_date": "20240101",
19+
"current_posting": "LA",
20+
"current_posting_effective_from_date": "20240101",
21+
"name_prefix": "BRO",
22+
"given_name": "smith",
23+
"other_given_name": "OtherGivenName 1",
24+
"family_name": "smith",
25+
"previous_family_name": "PreviousFamilyName 1",
26+
"date_of_birth": "20101022",
27+
"gender": 2,
28+
"address_line_1": "1 Test Street",
29+
"address_line_2": "Test Area",
30+
"address_line_3": "TestAddress",
31+
"address_line_4": "Chelmsford",
32+
"address_line_5": "United Kingdom",
33+
"postcode": "LS1 1AA",
34+
"paf_key": "Z3S4Q5X9",
35+
"address_effective_from_date": "20240101",
36+
"reason_for_removal": "ORR",
37+
"reason_for_removal_effective_from_date": null,
38+
"date_of_death": null,
39+
"death_status": null,
40+
"home_telephone_number": "01619999999",
41+
"home_telephone_effective_from_date": "20240101",
42+
"mobile_telephone_number": "07888888888",
43+
"mobile_telephone_effective_from_date": "20240101",
44+
"email_address": "blockedadd@example.com",
45+
"email_address_effective_from_date": "20240101",
46+
"preferred_language": "en",
47+
"is_interpreter_required": false,
48+
"invalid_flag": false,
49+
"eligibility": true
50+
}
51+
],
52+
"nhsNumbers": [
53+
"9998380197"
54+
]
55+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import { expect, test } from '../../fixtures/test-fixtures';
2+
import { createParquetFromJson } from '../../../parquet/parquet-multiplier';
3+
import { getApiTestData, processFileViaStorage, validateSqlDatabaseFromAPI, cleanupDatabaseFromAPI } from '../../steps/steps';
4+
import { getRecordsFromParticipantManagementService} from '../../../api/distributionService/bsSelectService';
5+
import { TestHooks } from '../../hooks/test-hooks';
6+
import { APIRequestContext, TestInfo } from '@playwright/test';
7+
import { config } from '../../../config/env';
8+
import { getRecordsFromExceptionService } from '../../../api/dataService/exceptionService';
9+
import { sendHttpGet, sendHttpPOSTCall } from '../../../api/core/sendHTTPRequest';
10+
11+
annotation: [{
12+
type: 'Requirement',
13+
description: 'Tests - https://nhsd-jira.digital.nhs.uk/browse/DTOSS-7667'
14+
}]
15+
16+
test.describe('@regression @e2e @epic4b-block-tests @smoke Tests', async () => {
17+
TestHooks.setupAllTestHooks();
18+
19+
test('@DTOSS-7667-01 - AC1 - Verify participant is deleted from CohortDistributionDataService', async ({ request }: { request: APIRequestContext }, testInfo: TestInfo) => {
20+
// Arrange: Get test data
21+
const [addValidations, inputParticipantRecord, nhsNumbers, testFilesPath] = await getApiTestData(testInfo.title, 'ADD_BLOCKED');
22+
const nhsNumber = nhsNumbers[0];
23+
await cleanupDatabaseFromAPI(request, [nhsNumber]);
24+
25+
26+
const parquetFile = await createParquetFromJson(nhsNumbers, inputParticipantRecord, testFilesPath);
27+
28+
await test.step(`When I ADD participant is processed via storage ready to be blocked by the block function`, async () => {
29+
await processFileViaStorage(parquetFile);
30+
});
31+
32+
let nhsNumberFromPds = 0;
33+
let familyName = "";
34+
let dateOfBirth = "";
35+
36+
await test.step(`Then participant should be in the participant management table`, async () => {
37+
38+
await validateSqlDatabaseFromAPI(request, addValidations);
39+
});
40+
41+
42+
// Call the block participant function
43+
await test.step(`Go to PDS and get the participant data for the blocking of a participant that already exists in the database`, async () => {
44+
// Call the block participant function
45+
let url = `${config.createPDSDemographic}${config.createPDSDemographicPath}?nhsNumber=${nhsNumbers[0]}`;
46+
47+
let response = await sendHttpGet(url)
48+
expect(response.status).toBe(200)
49+
50+
let json = await response.json();
51+
nhsNumberFromPds = json["NhsNumber"];
52+
familyName = json["FamilyName"]
53+
dateOfBirth = json["DateOfBirth"];
54+
55+
expect(nhsNumberFromPds).toBeDefined()
56+
});
57+
58+
const blockPayload = {
59+
NhsNumber: Number(nhsNumberFromPds),
60+
FamilyName: familyName,
61+
DateOfBirth: dateOfBirth
62+
};
63+
64+
await test.step(`running step to make sure that item can be subscribed to in nems`, async () => {
65+
let subscribeToNemsResponse = await sendHttpPOSTCall(`${config.SubToNems}${config.SubToNemsPath}?nhsNumber=${nhsNumbers[0]}`, "");
66+
67+
expect(subscribeToNemsResponse.status).toBe(200);
68+
});
69+
70+
await test.step(`Send block to existing participant and make sure they are blocked`, async () => {
71+
72+
let url = `${config.endpointBsSelectUpdateBlockFlag}${config.routeBsSelectBlockParticipant}`;
73+
let body = JSON.stringify(blockPayload);
74+
let response = await sendHttpPOSTCall(url, body);
75+
expect(response.status).toBe(200);
76+
});
77+
78+
79+
await test.step(`the participant has been blocked`, async () => {
80+
let blocked = false;
81+
for(let i =0; i<10; i++) {
82+
const resp = await getRecordsFromParticipantManagementService(request);
83+
if (resp?.data?.[0]?.BlockedFlag === 1) {
84+
blocked = true;
85+
break;
86+
}
87+
console.log(`Waiting for participant to be blocked...(${i}/10)`);
88+
await new Promise(res => setTimeout(res, 2000));
89+
}
90+
expect(blocked).toBe(true);
91+
});
92+
93+
94+
95+
96+
await test.step(`send the participant again and expect the participant has not been added and it has not been validated and there is a error in the database that shows that participant is blocked `, async () => {
97+
98+
const parquetFile = await createParquetFromJson(nhsNumbers, inputParticipantRecord, testFilesPath);
99+
100+
await processFileViaStorage(parquetFile);
101+
102+
let validationExceptions;
103+
for(let i =0; i<10; i++)
104+
{
105+
const responseFromExceptions = await getRecordsFromExceptionService(request);
106+
if(responseFromExceptions.data !== null)
107+
{
108+
validationExceptions = responseFromExceptions.data
109+
break;
110+
}
111+
console.log(`waiting for exception for participant blocked to be added to exception table...({${i}/10)`);
112+
await new Promise(res => setTimeout(res, 2000));
113+
}
114+
115+
let getUrl = `${config.endpointParticipantManagementDataService}api/${config.participantManagementService}`;
116+
var response = await sendHttpGet(getUrl);
117+
118+
119+
120+
let cohortDistributionServiceUrl = `${config.endpointCohortDistributionDataService}api/${config.cohortDistributionService}`
121+
122+
var response = await sendHttpGet(cohortDistributionServiceUrl);
123+
var jsonResponse = await response.json();
124+
125+
expect(response.status).toBe(200)
126+
expect(jsonResponse.length).toBe(1);
127+
expect(validationExceptions.length).toBe(1);
128+
expect(validationExceptions[0].RuleDescription).toBe("Participant is blocked");
129+
});
130+
});
131+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"validations": [
3+
{
4+
"validations": {
5+
"apiEndpoint": "api/CohortDistributionDataService",
6+
"NHSNumber": 9998380197
7+
}
8+
}
9+
],
10+
"inputParticipantRecord": [
11+
{
12+
"record_type": "ADD",
13+
"change_time_stamp": null,
14+
"serial_change_number": 1,
15+
"nhs_number": 9998380197,
16+
"superseded_by_nhs_number": null,
17+
"primary_care_provider": "A81623",
18+
"primary_care_effective_from_date": "20240101",
19+
"current_posting": "LA",
20+
"current_posting_effective_from_date": "20240101",
21+
"name_prefix": "BRO",
22+
"given_name": "smith",
23+
"other_given_name": "OtherGivenName 1",
24+
"family_name": "smith",
25+
"previous_family_name": "PreviousFamilyName 1",
26+
"date_of_birth": "20101022",
27+
"gender": 2,
28+
"address_line_1": "1 Test Street",
29+
"address_line_2": "Test Area",
30+
"address_line_3": "TestAddress",
31+
"address_line_4": "Chelmsford",
32+
"address_line_5": "United Kingdom",
33+
"postcode": "LS1 1AA",
34+
"paf_key": "Z3S4Q5X9",
35+
"address_effective_from_date": "20240101",
36+
"reason_for_removal": null,
37+
"reason_for_removal_effective_from_date": null,
38+
"date_of_death": null,
39+
"death_status": null,
40+
"home_telephone_number": "01619999999",
41+
"home_telephone_effective_from_date": "20240101",
42+
"mobile_telephone_number": "07888888888",
43+
"mobile_telephone_effective_from_date": "20240101",
44+
"email_address": "blockedadd@example.com",
45+
"email_address_effective_from_date": "20240101",
46+
"preferred_language": "en",
47+
"is_interpreter_required": false,
48+
"invalid_flag": false,
49+
"eligibility": true
50+
}
51+
],
52+
"nhsNumbers": [
53+
"9998380197"
54+
]
55+
}

0 commit comments

Comments
 (0)