|
| 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-7678-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.length >= 3) |
| 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 | + let objectToVerify = validationExceptions.find((o: { RuleDescription: string; }) => o.RuleDescription === 'Participant is blocked'); |
| 128 | + expect(objectToVerify !== null || objectToVerify !== undefined).toBeTruthy() |
| 129 | + }); |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | + await test.step(`verify that the participant is unblocked and then marked as eligible `, async () => { |
| 134 | + let url = `${config.endpointBsSelectUpdateBlockFlag}${config.routeBsSelectUnblockParticipant}?nhsNumber=${nhsNumbers[0]}`; |
| 135 | + let body = JSON.stringify(blockPayload); |
| 136 | + let response = await sendHttpPOSTCall(url, body); |
| 137 | + |
| 138 | + |
| 139 | + let eligibility = false; |
| 140 | + let blocked = true; |
| 141 | + for(let i =0; i<10; i++) { |
| 142 | + const resp = await getRecordsFromParticipantManagementService(request); |
| 143 | + let responseData = resp?.data?.[0]; |
| 144 | + if (responseData?.BlockedFlag === 0 && responseData?.EligibilityFlag === 1) { |
| 145 | + blocked = false; |
| 146 | + eligibility = true; |
| 147 | + |
| 148 | + break; |
| 149 | + } |
| 150 | + console.log(`Waiting for participant to be blocked...(${i}/10)`); |
| 151 | + await new Promise(res => setTimeout(res, 2000)); |
| 152 | + } |
| 153 | + |
| 154 | + expect(eligibility).toBe(true); |
| 155 | + expect(blocked).toBe(false); |
| 156 | + expect(response.status).toBe(200); |
| 157 | + |
| 158 | + }); |
| 159 | + }); |
| 160 | +}); |
0 commit comments