Skip to content

Commit 9699e48

Browse files
committed
Implement smoke tests for Search API with mixed valid and invalid Disease Types
- Added a new scenario to verify that the Search API returns a 200 status code with results and an OperationOutcome when both valid and invalid Disease Types are provided. - Implemented corresponding step definitions for GET and POST requests to handle mixed Disease Types. - Better validation to ensure the response includes search results and appropriate OperationOutcome for invalid immunization targets.
1 parent 9492e65 commit 9699e48

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

tests/e2e_automation/features/APITests/search.feature

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ Feature: Search the immunization of a patient
132132
| 1234567890 | ABC |
133133
| "" | "" |
134134

135+
@smoke
136+
@Delete_cleanUp @supplier_name_Postman_Auth
137+
Scenario: Verify that Search API returns 200 with results and OperationOutcome when both valid and invalid Disease Type are provided
138+
Given Valid vaccination record is created with Patient 'Random' and vaccine_type 'COVID'
139+
When Send a search request with GET method with valid NHS Number and mixed valid and invalid Disease Type
140+
Then The request will be successful with the status code '200'
141+
And The Search Response should contain search results and OperationOutcome for invalid immunization targets
142+
When Send a search request with POST method with valid NHS Number and mixed valid and invalid Disease Type
143+
Then The request will be successful with the status code '200'
144+
And The Search Response should contain search results and OperationOutcome for invalid immunization targets
145+
135146
@supplier_name_MAVIS @vaccine_type_RSV
136147
Scenario Outline: Verify that Search API will throw error if date from is invalid
137148
When Send a search request with GET method with invalid Date From '<DateFrom>' and valid Date To '<DateTo>'

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest_check as check
66
from pytest_bdd import parsers, scenarios, then, when
7+
78
from src.objectModels.api_search_object import convert_to_form_data, set_request_data
89
from utilities.api_fhir_immunization_helper import (
910
find_entry_by_Imms_id,
@@ -77,6 +78,36 @@ def TriggerSearchPostRequest(context):
7778
print(f"\n Search Post Response - \n {context.response.json()}")
7879

7980

81+
@when("Send a search request with GET method with valid NHS Number and mixed valid and invalid Disease Type")
82+
def send_search_get_with_mixed_targets(context):
83+
get_search_get_url_header(context)
84+
mixed_target = f"{context.vaccine_type},INVALID_TYPE"
85+
context.params = convert_to_form_data(
86+
set_request_data(
87+
context.patient.identifier[0].value,
88+
mixed_target,
89+
datetime.today().strftime("%Y-%m-%d"),
90+
)
91+
)
92+
print(f"\n Search Get Parameters (mixed targets) - \n {context.params}")
93+
context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers)
94+
95+
96+
@when("Send a search request with POST method with valid NHS Number and mixed valid and invalid Disease Type")
97+
def send_search_post_with_mixed_targets(context):
98+
get_search_post_url_header(context)
99+
mixed_target = f"{context.vaccine_type},INVALID_TYPE"
100+
context.request = convert_to_form_data(
101+
set_request_data(
102+
context.patient.identifier[0].value,
103+
mixed_target,
104+
datetime.today().strftime("%Y-%m-%d"),
105+
)
106+
)
107+
print(f"\n Search Post Request (mixed targets) - \n {context.request}")
108+
context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request)
109+
110+
80111
@when(
81112
parsers.parse(
82113
"Send a search request with GET method with invalid NHS Number '{NHSNumber}' and valid Disease Type '{DiseaseType}'"
@@ -389,3 +420,33 @@ def validate_empty_immunization_event(context):
389420
f"link[0].url should be '{context.baseUrl}/Immunization?identifier=None', got '{link_url}'"
390421
)
391422
assert response.get("total") == 0, "total should be 0"
423+
424+
425+
@then("The Search Response should contain search results and OperationOutcome for invalid immunization targets")
426+
def validate_search_response_with_invalid_targets_operation_outcome(context):
427+
response = context.response.json()
428+
assert response.get("resourceType") == "Bundle", "resourceType should be 'Bundle'"
429+
assert response.get("type") == "searchset", "type should be 'searchset'"
430+
entries = response.get("entry", [])
431+
assert len(entries) >= 1, "Bundle should contain at least one entry"
432+
433+
imms_entry = next(
434+
(
435+
e
436+
for e in entries
437+
if e.get("resource", {}).get("resourceType") == "Immunization"
438+
and e.get("resource", {}).get("id") == context.ImmsID
439+
),
440+
None,
441+
)
442+
assert imms_entry is not None, f"Expected to find Immunization entry with id {context.ImmsID} in search response"
443+
444+
oo_entries = [e for e in entries if e.get("resource", {}).get("resourceType") == "OperationOutcome"]
445+
assert len(oo_entries) >= 1, "Bundle should contain at least one OperationOutcome entry for invalid targets"
446+
diagnostics = oo_entries[0].get("resource", {}).get("issue", [{}])[0].get("diagnostics", "")
447+
assert "invalid -immunization.target value(s) that were ignored" in diagnostics, (
448+
f"Expected OperationOutcome diagnostics to mention invalid targets, got: {diagnostics}"
449+
)
450+
assert "INVALID_TYPE" in diagnostics, (
451+
f"Expected OperationOutcome diagnostics to mention INVALID_TYPE, got: {diagnostics}"
452+
)

0 commit comments

Comments
 (0)