diff --git a/tests/playwright-tests/src/api/core/sendHTTPRequest.ts b/tests/playwright-tests/src/api/core/sendHTTPRequest.ts index 4bd2f807d3..48469ccafc 100644 --- a/tests/playwright-tests/src/api/core/sendHTTPRequest.ts +++ b/tests/playwright-tests/src/api/core/sendHTTPRequest.ts @@ -20,7 +20,12 @@ export const sendHttpGet = url: string ): Promise => { - const response = await fetch(url); + const response = await fetch(url, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }); return response; } diff --git a/tests/playwright-tests/src/config/env.ts b/tests/playwright-tests/src/config/env.ts index ad27977c41..a4e23da94d 100644 --- a/tests/playwright-tests/src/config/env.ts +++ b/tests/playwright-tests/src/config/env.ts @@ -44,6 +44,7 @@ export const config = { SubToNems: subToNemsEndPoint, wireMockUrl: wireMockUrl, SubToNemsPath: 'api/Subscribe', + CheckNemsSubPath:'api/CheckSubscriptionStatus', routeBsSelectRetrieveCohortDistributionData: 'api/RetrieveCohortDistributionData', routeBsSelectRetrieveCohortRequestAudit: 'api/RetrieveCohortRequestAudit', routeBsSelectDeleteParticipant: 'api/DeleteParticipant', diff --git a/tests/playwright-tests/src/tests/api/testFiles/@DTOSS-7680-01/ADD_BLOCKED_7680.json b/tests/playwright-tests/src/tests/api/testFiles/@DTOSS-7680-01/ADD_BLOCKED_7680.json new file mode 100644 index 0000000000..4252a54dce --- /dev/null +++ b/tests/playwright-tests/src/tests/api/testFiles/@DTOSS-7680-01/ADD_BLOCKED_7680.json @@ -0,0 +1,55 @@ +{ + "validations": [ + { + "validations": { + "apiEndpoint": "api/CohortDistributionDataService", + "NHSNumber": 9998380197 + } + } + ], + "inputParticipantRecord": [ + { + "record_type": "ADD", + "change_time_stamp": null, + "serial_change_number": 1, + "nhs_number": 9998380197, + "superseded_by_nhs_number": null, + "primary_care_provider": "A81623", + "primary_care_effective_from_date": "20240101", + "current_posting": "LA", + "current_posting_effective_from_date": "20240101", + "name_prefix": "BRO", + "given_name": "smith", + "other_given_name": "OtherGivenName 1", + "family_name": "smith", + "previous_family_name": "PreviousFamilyName 1", + "date_of_birth": "20101022", + "gender": 2, + "address_line_1": "1 Test Street", + "address_line_2": "Test Area", + "address_line_3": "TestAddress", + "address_line_4": "Chelmsford", + "address_line_5": "United Kingdom", + "postcode": "LS1 1AA", + "paf_key": "Z3S4Q5X9", + "address_effective_from_date": "20240101", + "reason_for_removal": "ORR", + "reason_for_removal_effective_from_date": null, + "date_of_death": null, + "death_status": null, + "home_telephone_number": "01619999999", + "home_telephone_effective_from_date": "20240101", + "mobile_telephone_number": "07888888888", + "mobile_telephone_effective_from_date": "20240101", + "email_address": "blockedadd@example.com", + "email_address_effective_from_date": "20240101", + "preferred_language": "en", + "is_interpreter_required": false, + "invalid_flag": false, + "eligibility": true + } + ], + "nhsNumbers": [ + "9998380197" + ] +} diff --git a/tests/playwright-tests/src/tests/api/testFiles/@DTOSS-7680-01/DEL_BLOCKED_7680.json b/tests/playwright-tests/src/tests/api/testFiles/@DTOSS-7680-01/DEL_BLOCKED_7680.json new file mode 100644 index 0000000000..31003c0b8e --- /dev/null +++ b/tests/playwright-tests/src/tests/api/testFiles/@DTOSS-7680-01/DEL_BLOCKED_7680.json @@ -0,0 +1,55 @@ +{ + "validations": [ + { + "validations": { + "apiEndpoint": "api/CohortDistributionDataService", + "NHSNumber": 9998380197 + } + } + ], + "inputParticipantRecord": [ + { + "record_type": "DEL", + "change_time_stamp": null, + "serial_change_number": 1, + "nhs_number": 9998380197, + "superseded_by_nhs_number": null, + "primary_care_provider": "A81623", + "primary_care_effective_from_date": "20240101", + "current_posting": "LA", + "current_posting_effective_from_date": "20240101", + "name_prefix": "BRO", + "given_name": "smith", + "other_given_name": "OtherGivenName 1", + "family_name": "smith", + "previous_family_name": "PreviousFamilyName 1", + "date_of_birth": "20101022", + "gender": 2, + "address_line_1": "1 Test Street", + "address_line_2": "Test Area", + "address_line_3": "TestAddress", + "address_line_4": "Chelmsford", + "address_line_5": "United Kingdom", + "postcode": "LS1 1AA", + "paf_key": "Z3S4Q5X9", + "address_effective_from_date": "20240101", + "reason_for_removal": "ORR", + "reason_for_removal_effective_from_date": null, + "date_of_death": null, + "death_status": null, + "home_telephone_number": "01619999999", + "home_telephone_effective_from_date": "20240101", + "mobile_telephone_number": "07888888888", + "mobile_telephone_effective_from_date": "20240101", + "email_address": "blockedadd@example.com", + "email_address_effective_from_date": "20240101", + "preferred_language": "en", + "is_interpreter_required": false, + "invalid_flag": false, + "eligibility": true + } + ], + "nhsNumbers": [ + "9998380197" + ] +} diff --git a/tests/playwright-tests/src/tests/e2e/epic4b-block-participant-tests/epic-4b-7680-block-paricipant-testsuite.spec.ts b/tests/playwright-tests/src/tests/e2e/epic4b-block-participant-tests/epic-4b-7680-block-paricipant-testsuite.spec.ts new file mode 100644 index 0000000000..36199e30ea --- /dev/null +++ b/tests/playwright-tests/src/tests/e2e/epic4b-block-participant-tests/epic-4b-7680-block-paricipant-testsuite.spec.ts @@ -0,0 +1,123 @@ +import { expect, test } from '../../fixtures/test-fixtures'; +import { createParquetFromJson } from '../../../parquet/parquet-multiplier'; +import { getApiTestData, processFileViaStorage, validateSqlDatabaseFromAPI, cleanupDatabaseFromAPI } from '../../steps/steps'; +import { getRecordsFromParticipantManagementService} from '../../../api/distributionService/bsSelectService'; +import { TestHooks } from '../../hooks/test-hooks'; +import { APIRequestContext, TestInfo } from '@playwright/test'; +import { config } from '../../../config/env'; +import { getRecordsFromExceptionService } from '../../../api/dataService/exceptionService'; +import { sendHttpGet, sendHttpPOSTCall } from '../../../api/core/sendHTTPRequest'; + +annotation: [{ + type: 'Requirement', + description: 'Tests - https://nhsd-jira.digital.nhs.uk/browse/DTOSS-7667' +}] + +test.describe('@regression @e2e @epic4b-block-tests @smoke Tests', async () => { + TestHooks.setupAllTestHooks(); + + test('@DTOSS-7680-01 - AC12- verify that a participant when marked as ineligible and ublocked they are not added to the cohort and unsubscribed from PDS updates', async ({ request }: { request: APIRequestContext }, testInfo: TestInfo) => { + // Arrange: Get test data + const [addValidations, inputParticipantRecord, nhsNumbers, testFilesPath] = await getApiTestData(testInfo.title, 'ADD_BLOCKED'); + const nhsNumber = nhsNumbers[0]; + await cleanupDatabaseFromAPI(request, [nhsNumber]); + + + const parquetFile = await createParquetFromJson(nhsNumbers, inputParticipantRecord, testFilesPath); + + await test.step(`When I ADD participant is processed via storage ready to be blocked by the block function`, async () => { + await processFileViaStorage(parquetFile); + }); + + let nhsNumberFromPds = 0; + let familyName = ""; + let dateOfBirth = ""; + + await test.step(`Then participant should be in the participant management table`, async () => { + + await validateSqlDatabaseFromAPI(request, addValidations); + }); + + + // Call the block participant function + await test.step(`Go to PDS and get the participant data for the blocking of a participant that already exists in the database`, async () => { + // Call the block participant function + let url = `${config.createPDSDemographic}${config.createPDSDemographicPath}?nhsNumber=${nhsNumbers[0]}`; + + let response = await sendHttpGet(url) + expect(response.status).toBe(200) + + let json = await response.json(); + nhsNumberFromPds = json["NhsNumber"]; + familyName = json["FamilyName"] + dateOfBirth = json["DateOfBirth"]; + + expect(nhsNumberFromPds).toBeDefined() + }); + + const blockPayload = { + NhsNumber: Number(nhsNumberFromPds), + FamilyName: familyName, + DateOfBirth: dateOfBirth + }; + + await test.step(`running step to make sure that item can be subscribed to in nems`, async () => { + let subscribeToNemsResponse = await sendHttpPOSTCall(`${config.SubToNems}${config.SubToNemsPath}?nhsNumber=${nhsNumbers[0]}`, ""); + + expect(subscribeToNemsResponse.status).toBe(200); + }); + + await test.step(`Send block to existing participant and make sure they are blocked`, async () => { + + let url = `${config.endpointBsSelectUpdateBlockFlag}${config.routeBsSelectBlockParticipant}`; + let body = JSON.stringify(blockPayload); + let response = await sendHttpPOSTCall(url, body); + expect(response.status).toBe(200); + }); + + + await test.step(`the participant has been blocked`, async () => { + let blocked = false; + for(let i =0; i<10; i++) { + const resp = await getRecordsFromParticipantManagementService(request); + if (resp?.data?.[0]?.BlockedFlag === 1) { + blocked = true; + break; + } + console.log(`Waiting for participant to be blocked...(${i}/10)`); + await new Promise(res => setTimeout(res, 2000)); + } + expect(blocked).toBe(true); + }); + + await test.step(`mark the paricipant as unblocked and they should be marked as ineligible`, async () => { + let url = `${config.endpointBsSelectUpdateBlockFlag}${config.routeBsSelectUnblockParticipant}?nhsNumber=${nhsNumbers[0]}`; + let body = "" + let response = await sendHttpPOSTCall(url, body); + + + let eligibility = false; + let blocked = true; + for(let i =0; i<10; i++) { + const resp = await getRecordsFromParticipantManagementService(request); + let responseData = resp?.data?.[0]; + if (responseData?.BlockedFlag === 0 && responseData?.EligibilityFlag === 0) { + blocked = false; + eligibility = false; + + break; + } + console.log(`Waiting for participant to be blocked...(${i}/10)`); + await new Promise(res => setTimeout(res, 2000)); + } + + var checkNemsSubscriptionStatusURL = `${config.SubToNems}${config.CheckNemsSubPath}?nhsNumber=${nhsNumbers[0]}` ; + let nemsResponse = await sendHttpGet(checkNemsSubscriptionStatusURL); + + expect(nemsResponse.status).toBe(200); + expect(eligibility).toBe(true); + expect(blocked).toBe(false); + expect(response.status).toBe(200); + }); + }); +}); \ No newline at end of file diff --git a/tests/playwright-tests/src/tests/e2e/testFiles/@DTOSS-7680-01/ADD_BLOCKED_7680.json b/tests/playwright-tests/src/tests/e2e/testFiles/@DTOSS-7680-01/ADD_BLOCKED_7680.json new file mode 100644 index 0000000000..4252a54dce --- /dev/null +++ b/tests/playwright-tests/src/tests/e2e/testFiles/@DTOSS-7680-01/ADD_BLOCKED_7680.json @@ -0,0 +1,55 @@ +{ + "validations": [ + { + "validations": { + "apiEndpoint": "api/CohortDistributionDataService", + "NHSNumber": 9998380197 + } + } + ], + "inputParticipantRecord": [ + { + "record_type": "ADD", + "change_time_stamp": null, + "serial_change_number": 1, + "nhs_number": 9998380197, + "superseded_by_nhs_number": null, + "primary_care_provider": "A81623", + "primary_care_effective_from_date": "20240101", + "current_posting": "LA", + "current_posting_effective_from_date": "20240101", + "name_prefix": "BRO", + "given_name": "smith", + "other_given_name": "OtherGivenName 1", + "family_name": "smith", + "previous_family_name": "PreviousFamilyName 1", + "date_of_birth": "20101022", + "gender": 2, + "address_line_1": "1 Test Street", + "address_line_2": "Test Area", + "address_line_3": "TestAddress", + "address_line_4": "Chelmsford", + "address_line_5": "United Kingdom", + "postcode": "LS1 1AA", + "paf_key": "Z3S4Q5X9", + "address_effective_from_date": "20240101", + "reason_for_removal": "ORR", + "reason_for_removal_effective_from_date": null, + "date_of_death": null, + "death_status": null, + "home_telephone_number": "01619999999", + "home_telephone_effective_from_date": "20240101", + "mobile_telephone_number": "07888888888", + "mobile_telephone_effective_from_date": "20240101", + "email_address": "blockedadd@example.com", + "email_address_effective_from_date": "20240101", + "preferred_language": "en", + "is_interpreter_required": false, + "invalid_flag": false, + "eligibility": true + } + ], + "nhsNumbers": [ + "9998380197" + ] +} diff --git a/tests/playwright-tests/src/tests/e2e/testFiles/@DTOSS-7680-01/DEL_BLOCKED_7680.json b/tests/playwright-tests/src/tests/e2e/testFiles/@DTOSS-7680-01/DEL_BLOCKED_7680.json new file mode 100644 index 0000000000..4252a54dce --- /dev/null +++ b/tests/playwright-tests/src/tests/e2e/testFiles/@DTOSS-7680-01/DEL_BLOCKED_7680.json @@ -0,0 +1,55 @@ +{ + "validations": [ + { + "validations": { + "apiEndpoint": "api/CohortDistributionDataService", + "NHSNumber": 9998380197 + } + } + ], + "inputParticipantRecord": [ + { + "record_type": "ADD", + "change_time_stamp": null, + "serial_change_number": 1, + "nhs_number": 9998380197, + "superseded_by_nhs_number": null, + "primary_care_provider": "A81623", + "primary_care_effective_from_date": "20240101", + "current_posting": "LA", + "current_posting_effective_from_date": "20240101", + "name_prefix": "BRO", + "given_name": "smith", + "other_given_name": "OtherGivenName 1", + "family_name": "smith", + "previous_family_name": "PreviousFamilyName 1", + "date_of_birth": "20101022", + "gender": 2, + "address_line_1": "1 Test Street", + "address_line_2": "Test Area", + "address_line_3": "TestAddress", + "address_line_4": "Chelmsford", + "address_line_5": "United Kingdom", + "postcode": "LS1 1AA", + "paf_key": "Z3S4Q5X9", + "address_effective_from_date": "20240101", + "reason_for_removal": "ORR", + "reason_for_removal_effective_from_date": null, + "date_of_death": null, + "death_status": null, + "home_telephone_number": "01619999999", + "home_telephone_effective_from_date": "20240101", + "mobile_telephone_number": "07888888888", + "mobile_telephone_effective_from_date": "20240101", + "email_address": "blockedadd@example.com", + "email_address_effective_from_date": "20240101", + "preferred_language": "en", + "is_interpreter_required": false, + "invalid_flag": false, + "eligibility": true + } + ], + "nhsNumbers": [ + "9998380197" + ] +}