Skip to content

Commit 5de7623

Browse files
authored
Enhance test coverage to meet the defined acceptance criteria (#1324)
* updated test coverage * added NO_GP_NHS test patient detail * fix broken tests and reduce wait time for no msn event
1 parent a6401ed commit 5de7623

8 files changed

Lines changed: 101 additions & 49 deletions

File tree

tests/e2e_automation/features/APITests/create.feature

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Feature: Create the immunization event for a patient
7474
And The terms are mapped to the respective text fields in imms delta table
7575
And MNS event will be triggered with correct data for created event
7676

77-
@Delete_cleanUp @vaccine_type_BCG @patient_id_Random @supplier_name_EMIS
77+
@Delete_cleanUp @vaccine_type_BCG @patient_id_InvalidInPDS @supplier_name_EMIS
7878
Scenario: Verify that VACCINATION_PROCEDURE_TERM, VACCINE_PRODUCT_TERM fields are mapped to first instance of coding.display fields in imms delta table
7979
Given Valid json payload is created where vaccination terms has multiple instances of coding
8080
When Trigger the post create request
@@ -83,14 +83,14 @@ Feature: Create the immunization event for a patient
8383
And The terms are mapped to first instance of coding.display fields in imms delta table
8484
And MNS event will be triggered with correct data for created event
8585

86-
@Delete_cleanUp @vaccine_type_HEPB @patient_id_Random @supplier_name_MEDICUS
86+
@Delete_cleanUp @vaccine_type_HEPB @patient_id_NullNHS @supplier_name_MEDICUS
8787
Scenario: Verify that VACCINATION_PROCEDURE_TERM, VACCINE_PRODUCT_TERM, SITE_OF_VACCINATION_TERM, ROUTE_OF_VACCINATION_TERM fields are mapped to correct instance of coding.display fields in imms delta table
8888
Given Valid json payload is created where vaccination terms has multiple instance of coding with different coding system
8989
When Trigger the post create request
9090
Then The request will be successful with the status code '201'
9191
And The location key and Etag in header will contain the Immunization Id and version
9292
And The terms are mapped to correct instance of coding.display fields in imms delta table
93-
And MNS event will be triggered with correct data for created event
93+
And MNS event will not be triggered for the event
9494

9595
@smoke
9696
@Delete_cleanUp @vaccine_type_PERTUSSIS @patient_id_Random @supplier_name_EMIS
@@ -103,7 +103,7 @@ Feature: Create the immunization event for a patient
103103
And MNS event will be triggered with correct data for created event
104104

105105
@smoke
106-
@Delete_cleanUp @vaccine_type_HIB @patient_id_Random @supplier_name_TPP
106+
@Delete_cleanUp @vaccine_type_HIB @patient_id_NO_GP_NHS @supplier_name_TPP
107107
Scenario: Verify that VACCINATION_PROCEDURE_TERM, VACCINE_PRODUCT_TERM, SITE_OF_VACCINATION_TERM, ROUTE_OF_VACCINATION_TERM fields are blank in imms delta table if no text or value string or display field is present
108108
Given Valid json payload is created where vaccination terms has no text or value string or display field
109109
When Trigger the post create request
@@ -305,3 +305,16 @@ Feature: Create the immunization event for a patient
305305
And The imms event table will be populated with the correct data for 'created' event
306306
And The delta table will be populated with the correct data for created event
307307
And MNS event will be triggered with correct data for created event
308+
309+
310+
@smoke
311+
@Delete_cleanUp @supplier_name_TPP @vaccine_type_BCG @patient_id_Random
312+
Scenario: Verify that the POST Create API will create MNS event when patient DOB is in future
313+
Given Valid json payload is created where patient date is greater then vaccination occurrence date
314+
When Trigger the post create request
315+
Then The request will be successful with the status code '201'
316+
And The location key and Etag in header will contain the Immunization Id and version
317+
And The X-Request-ID and X-Correlation-ID keys in header will populate correctly
318+
And The imms event table will be populated with the correct data for 'created' event
319+
And The delta table will be populated with the correct data for created event
320+
And MNS event will be triggered with correct data for created event

tests/e2e_automation/features/APITests/search.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ Feature: Search the immunization of a patient
235235
When I send a search request with Post method using identifier parameter for Immunization event created
236236
Then The request will be successful with the status code '200'
237237
And correct immunization event is returned in the response
238+
And MNS event will not be triggered for the update event
238239

239240
@Delete_cleanUp @vaccine_type_FLU @patient_id_Random @supplier_name_Postman_Auth
240241
Scenario: Flu event is created and search post request fetch the only one record matched with identifier and _elements

tests/e2e_automation/features/APITests/steps/common_steps.py

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ def valid_json_payload_is_created_patient_age_is_less_then_a_year(context):
6363
context.immunization_object.contained[1].birthDate = dob.strftime("%Y-%m-%d")
6464

6565

66+
@given("Valid json payload is created where patient date is greater then vaccination occurrence date")
67+
def valid_json_payload_is_created_patient_age_is_in_future(context):
68+
valid_json_payload_is_created(context)
69+
today = datetime.now(UTC)
70+
dob = today - timedelta(days=7)
71+
context.immunization_object.contained[1].birthDate = dob.strftime("%Y-%m-%d")
72+
occurrence_date = today - timedelta(days=14)
73+
context.immunization_object.occurrenceDateTime = occurrence_date.isoformat()
74+
75+
6676
@given(parsers.parse("Valid json payload is created with Patient '{Patient}' and vaccine_type '{vaccine_type}'"))
6777
def The_Immunization_object_is_created_with_patient_for_vaccine_type(context, Patient, vaccine_type):
6878
context.vaccine_type = vaccine_type
@@ -123,7 +133,10 @@ def validVaccinationRecordIsCreated(context):
123133
Trigger_the_post_create_request(context)
124134
The_request_will_have_status_code(context, 201)
125135
validateCreateLocation(context)
126-
mns_event_will_be_triggered_with_correct_data(context=context, action="CREATE")
136+
if context.patient.identifier[0].value is not None:
137+
mns_event_will_be_triggered_with_correct_data(context=context, action="CREATE")
138+
else:
139+
mns_event_will_not_be_triggered_for_the_event(context)
127140

128141

129142
@given(parsers.parse("valid vaccination record is created by '{Supplier}' supplier"))
@@ -271,7 +284,7 @@ def validate_imms_event_table_by_operation(context, operation: Operation):
271284
),
272285
(
273286
"PatientPK",
274-
f"Patient#{context.patient.identifier[0].value}",
287+
f"Patient#{context.patient.identifier[0].value if context.patient.identifier[0].value is not None else 'TBC'}",
275288
item.get("PatientPK"),
276289
),
277290
(
@@ -332,7 +345,6 @@ def send_update_for_immunization_event(context):
332345
context.update_object.contained[1].address[0].city = "Updated City"
333346
context.update_object.contained[1].address[0].state = "Updated State"
334347
trigger_the_updated_request(context)
335-
mns_event_will_be_triggered_with_correct_data(context=context, action="UPDATE")
336348

337349

338350
@given("created event is being updated twice")
@@ -364,8 +376,27 @@ def mns_event_will_be_triggered_with_correct_data_for_created_event(context):
364376

365377
@then("MNS event will not be triggered for the event")
366378
def mns_event_will_not_be_triggered_for_the_event(context):
367-
message_body = read_message(context, queue_type="notification", wait_for_message=False)
368-
print(f"Read message from SQS: {message_body}")
379+
message_body = read_message(
380+
context,
381+
queue_type="notification",
382+
action="CREATE",
383+
wait_time_seconds=5,
384+
max_empty_polls=1,
385+
)
386+
print("No MNS create event is created")
387+
assert message_body is None, "Not expected a message but queue returned a message"
388+
389+
390+
@then("MNS event will not be triggered for the update event")
391+
def validate_mns_event_not_triggered_for_updated_event(context):
392+
message_body = read_message(
393+
context,
394+
queue_type="notification",
395+
action="UPDATE",
396+
wait_time_seconds=5,
397+
max_empty_polls=3,
398+
)
399+
print("no MNS update event is created")
369400
assert message_body is None, "Not expected a message but queue returned a message"
370401

371402

@@ -391,10 +422,6 @@ def calculate_age(birth_date_str: str, occurrence_datetime_str: str) -> int:
391422
age = occurrence.year - birth.year
392423
if (occurrence.month, occurrence.day) < (birth.month, birth.day):
393424
age -= 1
394-
395-
if age < 0:
396-
age = 0
397-
398425
return age
399426

400427

@@ -467,10 +494,18 @@ def validate_sqs_message(context, message_body, action):
467494

468495

469496
def mns_event_will_be_triggered_with_correct_data_for_deleted_event(context):
470-
if context.patient.identifier[0].value is None or context.gp_code is not None:
497+
if context.patient.identifier[0].value is None:
498+
message_body = read_message(
499+
context,
500+
queue_type="notification",
501+
action="DELETE",
502+
wait_time_seconds=5,
503+
max_empty_polls=3,
504+
)
471505
print(
472-
f"Patient {context.patient_id} has no NHS number or gp code is not setup, MNS message will go to Dead letter queue"
506+
"No MNS delete event is created as expected since NHS number is not present in the original immunization event"
473507
)
508+
assert message_body is None, "Not expected a message but queue returned a message"
474509
else:
475510
message_body = read_message(context, queue_type="notification", action="DELETE")
476511
print(f"Read deleted message from SQS: {message_body}")
@@ -479,14 +514,9 @@ def mns_event_will_be_triggered_with_correct_data_for_deleted_event(context):
479514

480515

481516
def mns_event_will_be_triggered_with_correct_data(context, action):
482-
if context.patient.identifier[0].value is None or context.gp_code is not None:
483-
print(
484-
f"Patient {context.patient_id} has no NHS number or gp code is not setup, MNS message will go to Dead letter queue"
485-
)
486-
else:
487-
message_body = read_message(context, queue_type="notification", action=action)
488-
print(f"Read {action}d message from SQS: {message_body}")
489-
assert message_body is not None, f"Expected a {action} message but queue returned empty"
490-
context.gp_code = get_gp_code_by_nhs_number(context.patient.identifier[0].value)
491-
context.patient_age = calculate_age(context.patient.birthDate, context.immunization_object.occurrenceDateTime)
492-
validate_sqs_message(context, message_body, action)
517+
message_body = read_message(context, queue_type="notification", action=action)
518+
print(f"Read {action}d message from SQS: {message_body}")
519+
assert message_body is not None, f"Expected a {action} message but queue returned empty"
520+
context.gp_code = get_gp_code_by_nhs_number(context.patient.identifier[0].value)
521+
context.patient_age = calculate_age(context.patient.birthDate, context.immunization_object.occurrenceDateTime)
522+
validate_sqs_message(context, message_body, action)

tests/e2e_automation/features/APITests/update.feature

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Feature: Update the immunization of a patient
1111
And The X-Request-ID and X-Correlation-ID keys in header will populate correctly
1212
And The imms event table will be populated with the correct data for 'updated' event
1313
And The delta table will be populated with the correct data for updated event
14+
And MNS event will be triggered with correct data for Updated event
1415

1516

1617
@vaccine_type_RSV @patient_id_Random
@@ -21,7 +22,7 @@ Feature: Update the immunization of a patient
2122
And The Response JSONs should contain correct error message for 'forbidden' access
2223

2324

24-
@delete_cleanup @vaccine_type_RSV @patient_id_Random @supplier_name_RAVS
25+
@delete_cleanup @vaccine_type_RSV @patient_id_NullNHS @supplier_name_RAVS
2526
Scenario: verify that vaccination record can be updated with valid vaccination detail
2627
Given I have created a valid vaccination record
2728
When I update the address of the original immunization event
@@ -30,7 +31,7 @@ Feature: Update the immunization of a patient
3031
And The X-Request-ID and X-Correlation-ID keys in header will populate correctly
3132
And The imms event table will be populated with the correct data for 'updated' event
3233
And The delta table will be populated with the correct data for updated event
33-
And MNS event will be triggered with correct data for Updated event
34+
And MNS event will not be triggered for the update event
3435

3536

3637
@smoke
@@ -51,7 +52,7 @@ Feature: Update the immunization of a patient
5152
And MNS event will be triggered with correct data for Updated event
5253

5354
@smoke
54-
@delete_cleanup @vaccine_type_ROTAVIRUS @patient_id_Random
55+
@delete_cleanup @vaccine_type_ROTAVIRUS @patient_id_NO_GP_NHS
5556
Scenario: Verify that update will be successful when request is triggered by other supplier with authorize permission
5657
Given valid vaccination record is created by 'TPP' supplier
5758
When Send a update for Immunization event created with patient address being updated by 'EMIS'
@@ -62,7 +63,7 @@ Feature: Update the immunization of a patient
6263
And MNS event will be triggered with correct data for Updated event
6364

6465

65-
@Delete_cleanUp @vaccine_type_RSV @patient_id_Mod11_NHS @supplier_name_Postman_Auth
66+
@Delete_cleanUp @vaccine_type_RSV @patient_id_InvalidInPDS @supplier_name_Postman_Auth
6667
Scenario: Verify that the Update API will be successful with invalid but Mod11 compliant NHS Number
6768
Given I have created a valid vaccination record
6869
When I update the address of the original immunization event
@@ -71,6 +72,7 @@ Feature: Update the immunization of a patient
7172
And The X-Request-ID and X-Correlation-ID keys in header will populate correctly
7273
And The imms event table will be populated with the correct data for 'updated' event
7374
And The delta table will be populated with the correct data for updated event
75+
And MNS event will be triggered with correct data for Updated event
7476

7577
@Delete_cleanUp @vaccine_type_RSV @patient_id_Mod11_NHS @supplier_name_Postman_Auth
7678
Scenario Outline: Scenario Outline name: Verify that the Update API will be fails if occurrenceDateTime has future or invalid formatted date

tests/e2e_automation/input/testData.csv

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
id,nhs_number,family_name,given_name,gender,birth_date,address_text,address_line,city,district,state,postal_code,country,start_date,end_date,gp_code,dss_record_start_date,dss_record_end_date
2-
ValidNHS,9449309981,test1,test2,unknown,1980-11-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01
3-
NullNHS,none,test1,test2,unknown,1980-09-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01
4-
NullNHS,none,test1,test2,unknown,1981-12-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01
5-
SFlag,9449310475,test1,test2,unknown,1980-11-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01
6-
InvalidInPDS,9449310599,test1,test2,unknown,1980-11-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01
7-
InvalidMOD11Check,1234567890,test1,test2,unknown,1980-11-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01
8-
OldNHSNo,9452372230,test1,test2,unknown,1980-11-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01
9-
SupersedeNhsNo,9467351307,test1,test2,unknown,1980-11-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01
10-
Invalid_NHS,9461267665,STERLING,SOKHI,unknown,2007-11-25,217A,ROUNDHAY ROAD,City,district,State,LS8 4HS,UK,2013-12-22,2033-01-01,B83013,
11-
Mod11_NHS,2788584652,STERLING,Sal,unknown,2007-11-25,217A,ROUNDHAY ROAD,City,district,State,LS8 4HS,UK,2013-12-22,2033-01-01
12-
Mod11_NHS,3510670485,STERLING,Sall,unknown,2007-11-25,217A,ROUNDHAY ROAD,City,district,State,LS8 4HS,UK,2013-12-22,2033-01-01
13-
Mod11_NHS,5309741852,STERLING,Sally,unknown,2007-11-25,217A,ROUNDHAY ROAD,City,district,State,LS8 4HS,UK,2013-12-22,2033-01-01
14-
Valid_NHS,9727799280,MOAH,HANNAH,female,1934-05-30,50 GORDON STREET,BOOTHTOWN,HALIFAX,District,State,HX3 6NU,UK,2010-01-01,2029-12-30,B84612,2026-01-30,null
2+
ValidNHS,9449309981,test1,test2,unknown,1980-11-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01,,,
3+
NullNHS,none,test1,test2,unknown,1980-09-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01,,,
4+
NullNHS,none,test1,test2,unknown,1981-12-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01,,,
5+
SFlag,9449310475,test1,test2,unknown,1980-11-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01,,,
6+
InvalidInPDS,7085531614,test1,test2,unknown,1980-11-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01,,,
7+
InvalidInPDS,1542293278,test1,test2,unknown,1980-11-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01,,,
8+
InvalidMOD11Check,1234567890,test1,test2,unknown,1980-11-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01,,,
9+
OldNHSNo,9452372230,test1,test2,unknown,1980-11-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01,,,
10+
SupersedeNhsNo,9467351307,test1,test2,unknown,1980-11-01,Validate Obf,"1, obf_2",obf_3,obf_4,obf_5,LS01 1AB,obf_7,2000-01-01,2025-01-01,,,
11+
Invalid_NHS,9461267665,STERLING,SOKHI,unknown,2007-11-25,217A,ROUNDHAY ROAD,City,district,State,LS8 4HS,UK,2013-12-22,2033-01-01,B83013,,
12+
Mod11_NHS,2788584652,STERLING,Sal,unknown,2007-11-25,217A,ROUNDHAY ROAD,City,district,State,LS8 4HS,UK,2013-12-22,2033-01-01,,,
13+
Mod11_NHS,3510670485,STERLING,Sall,unknown,2007-11-25,217A,ROUNDHAY ROAD,City,district,State,LS8 4HS,UK,2013-12-22,2033-01-01,,,
14+
Mod11_NHS,5309741852,STERLING,Sally,unknown,2007-11-25,217A,ROUNDHAY ROAD,City,district,State,LS8 4HS,UK,2013-12-22,2033-01-01,,,
15+
NO_GP_NHS,9737366689,ERNEST,MILMIN,female,2021-07-21,50 GORDON STREET,BOOTHTOWN,HALIFAX,District,State,LS12 2QS,UK,2010-01-01,2029-12-30,,,
16+
NO_GP_NHS,9446144078,KEIRAN,POSTLETHWAITE,female,2010-03-21,50 GORDON STREET,BOOTHTOWN,HALIFAX,District,State,LS10 4QE,UK,2010-01-01,2029-12-30,,,
1517
Valid_NHS,9727805493,BULLEN,OTIS,male,1961-08-23,3 MANOR ROAD EXTENSION,OADBY,LEICESTER,District,State,LE2 4FG,UK,2010-01-01,2029-12-30,C82066,2026-01-30,null
1618
Valid_NHS,9727835147,MOXON,ANITA,female,1993-03-22,10 BRANDER DRIVE,LEEDS,null,District,State,LS9 6NU,UK,2010-01-01,2029-12-30,B86092,2026-01-30,null
1719
Valid_NHS,9727847587,DUFFY,BEN,male,1959-01-24,35 HOPWOOD LANE,HALIFAX,null,District,State,HX1 5ER,UK,2010-01-01,2029-12-30,B84612,2026-01-30,null

tests/e2e_automation/src/dynamoDB/dynamo_db_helper.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,11 @@ def validate_imms_delta_record_with_created_event(
294294
),
295295
(
296296
"NHS_NUMBER",
297-
create_obj.contained[1].identifier[0].value,
297+
(
298+
create_obj.contained[1].identifier[0].value
299+
if create_obj.contained[1].identifier[0].value is not None
300+
else ""
301+
),
298302
imms_event.get("NHS_NUMBER"),
299303
),
300304
(

tests/e2e_automation/utilities/api_fhir_immunization_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ def validate_to_compare_request_and_response(context, create_obj, created_event,
241241
fields_to_compare.append(
242242
(
243243
"patient.identifier.value",
244-
request_patient.identifier[0].value,
245-
response_patient.identifier.value,
244+
(request_patient.identifier[0].value if context.patient.identifier[0].value is not None else ""),
245+
(response_patient.identifier.value if response_patient.identifier.value is not None else ""),
246246
)
247247
)
248248
fields_to_compare.append(

tests/e2e_automation/utilities/sqs_message_halder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ def read_message(
2626
action="CREATE",
2727
wait_for_message=True,
2828
max_empty_polls=3,
29+
wait_time_seconds=20,
2930
):
3031
sqs = boto3.client("sqs", region_name="eu-west-2")
3132
queue_url = build_queue_url(context.S3_env, context.aws_account_id, queue_type)
3233

3334
expected_dataref = f"{context.url}/{context.ImmsID}"
3435

35-
WAIT_TIME_SECONDS = 10
3636
empty_polls = 0
3737

3838
while True:
39-
print(f"Polling {queue_type} queue for {action} messages (wait {WAIT_TIME_SECONDS}s)...")
39+
print(f"Polling {queue_type} queue for {action} messages (wait {wait_time_seconds}s)...")
4040

4141
response = sqs.receive_message(
4242
QueueUrl=queue_url,
4343
MaxNumberOfMessages=10,
44-
WaitTimeSeconds=WAIT_TIME_SECONDS,
44+
WaitTimeSeconds=wait_time_seconds,
4545
VisibilityTimeout=30,
4646
)
4747

0 commit comments

Comments
 (0)