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 does not have a subscription in our database when they are blocked' , 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 ( `When the participant is not blocked list they are subscribed to nems for PDS updates` , async ( ) => {
71+ let checkNemsSubscriptionStatusURL = `${ config . SubToNems } ${ config . CheckNemsSubPath } ?nhsNumber=${ nhsNumbers [ 0 ] } ` ;
72+ let nemsResponse = await sendHttpGet ( checkNemsSubscriptionStatusURL ) ;
73+
74+ expect ( nemsResponse . status ) . toBe ( 200 ) ;
75+ } ) ;
76+
77+ await test . step ( `Send block to existing participant and make sure they are blocked` , async ( ) => {
78+
79+ let url = `${ config . endpointBsSelectUpdateBlockFlag } ${ config . routeBsSelectBlockParticipant } ` ;
80+ let body = JSON . stringify ( blockPayload ) ;
81+ let response = await sendHttpPOSTCall ( url , body ) ;
82+ expect ( response . status ) . toBe ( 200 ) ;
83+ } ) ;
84+
85+
86+ await test . step ( `make sure the participant has been blocked` , async ( ) => {
87+ let blocked = false ;
88+ for ( let i = 0 ; i < 10 ; i ++ ) {
89+ const resp = await getRecordsFromParticipantManagementService ( request ) ;
90+ if ( resp ?. data ?. [ 0 ] ?. BlockedFlag === 1 ) {
91+ blocked = true ;
92+ break ;
93+ }
94+ console . log ( `Waiting for participant to be blocked...(${ i } /10)` ) ;
95+ await new Promise ( res => setTimeout ( res , 2000 ) ) ;
96+ }
97+ expect ( blocked ) . toBe ( true ) ;
98+ } ) ;
99+
100+ await test . step ( `When the participant is in the blocked list they are not subscribed to nems for PDS updates` , async ( ) => {
101+ let checkNemsSubscriptionStatusURL = `${ config . SubToNems } ${ config . CheckNemsSubPath } ?nhsNumber=${ nhsNumbers [ 0 ] } ` ;
102+ let nemsResponse = await sendHttpGet ( checkNemsSubscriptionStatusURL ) ;
103+
104+ expect ( nemsResponse . status ) . toBe ( 404 ) ;
105+ } ) ;
106+ } ) ;
107+ } ) ;
0 commit comments