diff --git a/tests/e2e_automation/features/APITests/search.feature b/tests/e2e_automation/features/APITests/search.feature index d038e60ae..6baa8e688 100644 --- a/tests/e2e_automation/features/APITests/search.feature +++ b/tests/e2e_automation/features/APITests/search.feature @@ -328,16 +328,16 @@ Feature: Search the immunization of a patient @supplier_name_SONAR Scenario: Verify that Search API returns 403 when target-disease resolves only to vaccine types supplier is not authorised for - When Send a search request with GET method using target-disease for Immunization event created with valid NHS Number + When Send a search request with GET method using target-disease for Immunization event created with valid NHS Number and patient identifier system 'https://fhir.nhs.uk/Id/nhs-number' and target-disease system 'http://snomed.info/sct' Then The request will be unsuccessful with the status code '403' And The Response JSONs should contain correct error message for 'unauthorized_access' access @supplier_name_Postman_Auth Scenario: Verify that Search API returns 400 when all target-disease values are invalid SNOMED codes - When Send a search request with 'GET' method with valid NHS Number and all invalid target-disease codes + When Send a search request with 'GET' method with valid NHS Number and all invalid target-disease codes using patient identifier system 'https://fhir.nhs.uk/Id/nhs-number' Then The request will be unsuccessful with the status code '400' And The Response JSONs should contain correct error message for invalid target-disease codes - When Send a search request with 'POST' method with valid NHS Number and all invalid target-disease codes + When Send a search request with 'POST' method with valid NHS Number and all invalid target-disease codes using patient identifier system 'https://fhir.nhs.uk/Id/nhs-number' Then The request will be unsuccessful with the status code '400' And The Response JSONs should contain correct error message for invalid target-disease codes @@ -345,9 +345,9 @@ Feature: Search the immunization of a patient @Delete_cleanUp @supplier_name_Postman_Auth Scenario: Verify that Search API returns 200 with results and OperationOutcome when some target-disease values are invalid Given Valid vaccination record is created with Patient 'Random' and vaccine_type '6IN1' - When Send a search request with 'GET' method using mixed valid and invalid target-disease codes for Immunization event created + When Send a search request with 'GET' method using mixed valid and invalid target-disease codes for Immunization event created with target-disease system 'http://snomed.info/sct' and invalid target-disease code '99999' Then The request will be successful with the status code '200' And The Search Response should contain search results and OperationOutcome for invalid target-disease codes - When Send a search request with 'POST' method using mixed valid and invalid target-disease codes for Immunization event created + When Send a search request with 'POST' method using mixed valid and invalid target-disease codes for Immunization event created with target-disease system 'http://snomed.info/sct' and invalid target-disease code '99999' Then The request will be successful with the status code '200' And The Search Response should contain search results and OperationOutcome for invalid target-disease codes diff --git a/tests/e2e_automation/features/APITests/steps/test_search_steps.py b/tests/e2e_automation/features/APITests/steps/test_search_steps.py index bba09f981..74a07c85c 100644 --- a/tests/e2e_automation/features/APITests/steps/test_search_steps.py +++ b/tests/e2e_automation/features/APITests/steps/test_search_steps.py @@ -24,10 +24,6 @@ scenarios("APITests/search.feature") -TARGET_DISEASE_SYSTEM = "http://snomed.info/sct" -INVALID_TARGET_DISEASE_CODE = "99999" -PATIENT_IDENTIFIER_SYSTEM = "https://fhir.nhs.uk/Id/nhs-number" - @when("I send a search request with Post method using identifier parameter for Immunization event created") def send_search_post_request_with_identifier_header(context): @@ -144,24 +140,28 @@ def send_search_post_with_target_disease_and_dates(context): trigger_search_request_by_httpMethod(context, httpMethod="POST") -@when("Send a search request with GET method using target-disease for Immunization event created with valid NHS Number") -def send_search_get_with_target_disease_unauthorised_supplier(context): +@when( + parsers.parse( + "Send a search request with GET method using target-disease for Immunization event created with valid NHS Number and patient identifier system '{patient_identifier_system}' and target-disease system '{target_disease_system}'" + ) +) +def send_search_get_with_target_disease_unauthorised_supplier(context, patient_identifier_system, target_disease_system): nhs_number = "9000000009" context.params = { - "patient.identifier": f"{PATIENT_IDENTIFIER_SYSTEM}|{nhs_number}", - "target-disease": f"{TARGET_DISEASE_SYSTEM}|14189004", + "patient.identifier": f"{patient_identifier_system}|{nhs_number}", + "target-disease": f"{target_disease_system}|14189004", } trigger_search_request_by_httpMethod(context, httpMethod="GET") @when( parsers.parse( - "Send a search request with '{httpMethod}' method with valid NHS Number and all invalid target-disease codes" + "Send a search request with '{httpMethod}' method with valid NHS Number and all invalid target-disease codes using patient identifier system '{patient_identifier_system}'" ) ) -def send_search_request_with_all_invalid_target_disease_codes(context, httpMethod): +def send_search_request_with_all_invalid_target_disease_codes(context, httpMethod, patient_identifier_system): context.params = context.request = { - "patient.identifier": f"{PATIENT_IDENTIFIER_SYSTEM}|9000000009", + "patient.identifier": f"{patient_identifier_system}|9000000009", "target-disease": "invalid-no-pipe,wrong_system|123", } trigger_search_request_by_httpMethod(context, httpMethod=httpMethod) @@ -169,15 +169,18 @@ def send_search_request_with_all_invalid_target_disease_codes(context, httpMetho @when( parsers.parse( - "Send a search request with '{httpMethod}' method using mixed valid and invalid target-disease codes for Immunization event created" + "Send a search request with '{httpMethod}' method using mixed valid and invalid target-disease codes for Immunization event created with target-disease system '{target_disease_system}' and invalid target-disease code '{invalid_target_disease_code}'" ) ) -def send_search_post_with_mixed_valid_and_invalid_target_disease_codes(context, httpMethod): +def send_search_post_with_mixed_valid_and_invalid_target_disease_codes( + context, httpMethod, target_disease_system, invalid_target_disease_code +): patient_ident = context.create_object.contained[1].identifier[0] target = context.create_object.protocolApplied[0].targetDisease[0].coding[0] + context.invalid_target_disease_code = invalid_target_disease_code context.params = context.request = { "patient.identifier": f"{patient_ident.system}|{patient_ident.value}", - "target-disease": f"{target.system}|{target.code},{TARGET_DISEASE_SYSTEM}|{INVALID_TARGET_DISEASE_CODE}", + "target-disease": f"{target.system}|{target.code},{target_disease_system}|{invalid_target_disease_code}", } trigger_search_request_by_httpMethod(context, httpMethod=httpMethod) @@ -499,6 +502,7 @@ def validate_invalid_target_disease_codes_error(context): def validate_search_response_with_invalid_target_disease_operation_outcome(context): issue = read_issue_from_response(context) diagnostics = issue.get("diagnostics", "") + invalid_target_disease_code = getattr(context, "invalid_target_disease_code", None) assert issue.get("code") == "invalid", f"issue code should be 'invalid', got '{issue.get('code')}'" assert "Target disease code" in diagnostics, ( f"issue diagnostics should mention 'Target disease code', got '{diagnostics}'" @@ -506,8 +510,11 @@ def validate_search_response_with_invalid_target_disease_operation_outcome(conte assert "not a supported target disease in this service" in diagnostics, ( f"issue diagnostics should mention unsupported target disease, got '{diagnostics}'" ) - assert INVALID_TARGET_DISEASE_CODE in diagnostics, ( - f"issue diagnostics should contain invalid target disease code '{INVALID_TARGET_DISEASE_CODE}', got '{diagnostics}'" + assert invalid_target_disease_code is not None, ( + "invalid target disease code was not set by the scenario step before assertion" + ) + assert invalid_target_disease_code in diagnostics, ( + f"issue diagnostics should contain invalid target disease code '{invalid_target_disease_code}', got '{diagnostics}'" )