From 0480cc306319edd352d504406cb84b74e8b9e278 Mon Sep 17 00:00:00 2001 From: SamRobinson75684 Date: Mon, 1 Sep 2025 19:58:58 +0100 Subject: [PATCH] fix: adding test data and tests for DTOSS-7678 --- .../@DTOSS-7678-01/ADD_BLOCKED_7678.json | 55 ++++++ ...c4b-7678-block-paricipant-tessuite.spec.ts | 160 ++++++++++++++++++ .../@DTOSS-7678-01/ADD_BLOCKED_7678.json | 55 ++++++ 3 files changed, 270 insertions(+) create mode 100644 tests/playwright-tests/src/tests/api/testFiles/@DTOSS-7678-01/ADD_BLOCKED_7678.json create mode 100644 tests/playwright-tests/src/tests/e2e/epic4b-block-participant-tests/epic4b-7678-block-paricipant-tessuite.spec.ts create mode 100644 tests/playwright-tests/src/tests/e2e/testFiles/@DTOSS-7678-01/ADD_BLOCKED_7678.json diff --git a/tests/playwright-tests/src/tests/api/testFiles/@DTOSS-7678-01/ADD_BLOCKED_7678.json b/tests/playwright-tests/src/tests/api/testFiles/@DTOSS-7678-01/ADD_BLOCKED_7678.json new file mode 100644 index 0000000000..4252a54dce --- /dev/null +++ b/tests/playwright-tests/src/tests/api/testFiles/@DTOSS-7678-01/ADD_BLOCKED_7678.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/epic4b-block-participant-tests/epic4b-7678-block-paricipant-tessuite.spec.ts b/tests/playwright-tests/src/tests/e2e/epic4b-block-participant-tests/epic4b-7678-block-paricipant-tessuite.spec.ts new file mode 100644 index 0000000000..196d5ce2bb --- /dev/null +++ b/tests/playwright-tests/src/tests/e2e/epic4b-block-participant-tests/epic4b-7678-block-paricipant-tessuite.spec.ts @@ -0,0 +1,160 @@ +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-7678-01 - AC1 - Verify participant is deleted from CohortDistributionDataService', 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(`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 () => { + + const parquetFile = await createParquetFromJson(nhsNumbers, inputParticipantRecord, testFilesPath); + + await processFileViaStorage(parquetFile); + + let validationExceptions; + for(let i =0; i<10; i++) + { + const responseFromExceptions = await getRecordsFromExceptionService(request); + if(responseFromExceptions.data.length >= 3) + { + validationExceptions = responseFromExceptions.data + break; + } + console.log(`waiting for exception for participant blocked to be added to exception table...({${i}/10)`); + await new Promise(res => setTimeout(res, 2000)); + } + + let getUrl = `${config.endpointParticipantManagementDataService}api/${config.participantManagementService}`; + var response = await sendHttpGet(getUrl); + + + + let cohortDistributionServiceUrl = `${config.endpointCohortDistributionDataService}api/${config.cohortDistributionService}` + + var response = await sendHttpGet(cohortDistributionServiceUrl); + var jsonResponse = await response.json(); + + expect(response.status).toBe(200) + expect(jsonResponse.length).toBe(1); + let objectToVerify = validationExceptions.find((o: { RuleDescription: string; }) => o.RuleDescription === 'Participant is blocked'); + expect(objectToVerify !== null || objectToVerify !== undefined).toBeTruthy() + }); + + + + await test.step(`verify that the participant is unblocked and then marked as eligible `, async () => { + let url = `${config.endpointBsSelectUpdateBlockFlag}${config.routeBsSelectUnblockParticipant}?nhsNumber=${nhsNumbers[0]}`; + let body = JSON.stringify(blockPayload); + 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 === 1) { + blocked = false; + eligibility = true; + + break; + } + console.log(`Waiting for participant to be blocked...(${i}/10)`); + await new Promise(res => setTimeout(res, 2000)); + } + + expect(eligibility).toBe(true); + expect(blocked).toBe(false); + expect(response.status).toBe(200); + + }); + }); +}); diff --git a/tests/playwright-tests/src/tests/e2e/testFiles/@DTOSS-7678-01/ADD_BLOCKED_7678.json b/tests/playwright-tests/src/tests/e2e/testFiles/@DTOSS-7678-01/ADD_BLOCKED_7678.json new file mode 100644 index 0000000000..4252a54dce --- /dev/null +++ b/tests/playwright-tests/src/tests/e2e/testFiles/@DTOSS-7678-01/ADD_BLOCKED_7678.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" + ] +}