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-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 ) => {
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+ await test . step ( `mark the paricipant as unblocked and they should be marked as ineligible` , async ( ) => {
94+ let url = `${ config . endpointBsSelectUpdateBlockFlag } ${ config . routeBsSelectUnblockParticipant } ?nhsNumber=${ nhsNumbers [ 0 ] } ` ;
95+ let body = ""
96+ let response = await sendHttpPOSTCall ( url , body ) ;
97+
98+
99+ let eligibility = false ;
100+ let blocked = true ;
101+ for ( let i = 0 ; i < 10 ; i ++ ) {
102+ const resp = await getRecordsFromParticipantManagementService ( request ) ;
103+ let responseData = resp ?. data ?. [ 0 ] ;
104+ if ( responseData ?. BlockedFlag === 0 && responseData ?. EligibilityFlag === 0 ) {
105+ blocked = false ;
106+ eligibility = false ;
107+
108+ break ;
109+ }
110+ console . log ( `Waiting for participant to be blocked...(${ i } /10)` ) ;
111+ await new Promise ( res => setTimeout ( res , 2000 ) ) ;
112+ }
113+
114+ var checkNemsSubscriptionStatusURL = `${ config . SubToNems } ${ config . CheckNemsSubPath } ?nhsNumber=${ nhsNumbers [ 0 ] } ` ;
115+ let nemsResponse = await sendHttpGet ( checkNemsSubscriptionStatusURL ) ;
116+
117+ expect ( nemsResponse . status ) . toBe ( 200 ) ;
118+ expect ( eligibility ) . toBe ( true ) ;
119+ expect ( blocked ) . toBe ( false ) ;
120+ expect ( response . status ) . toBe ( 200 ) ;
121+ } ) ;
122+ } ) ;
123+ } ) ;
0 commit comments