Skip to content

Commit 80e4d38

Browse files
authored
Update: [AEA-4443] - Better validator tests (#223)
## Summary - Routine Change ### Details - use full examples for validator tests - add back in poetry.lock so we get consistent dependencies
1 parent da69223 commit 80e4d38

File tree

17 files changed

+6425
-4
lines changed

17 files changed

+6425
-4
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,3 @@ node_modules
251251
# VSCODE specific
252252
.vscode
253253
vscode
254-
255-
# poetry.lock
256-
poetry.lock

features/eps_fhir/validator.feature

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@eps_fhir @smoke @regression @blocker @validator
22
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4895
3+
@allure.tms:https://jsondiff.tooliverse.io/
34
Feature: I can call the validator endpoint
45

56
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to false
@@ -15,7 +16,7 @@ Feature: I can call the validator endpoint
1516
And the validator response has many information issue
1617
And the validator response has 0 error issue
1718

18-
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to false
19+
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to unset
1920
Given I am an authorised prescriber
2021
When I make a valid request to the eps_fhir validator endpoint with show validation set to unset
2122
Then the response indicates a success
@@ -27,3 +28,33 @@ Feature: I can call the validator endpoint
2728
Then the response indicates a bad request
2829
And the validator response has many error issue
2930
And the validator response has error with diagnostic containing Failed to parse JSON encoded FHIR content
31+
32+
Scenario: I can call the validator endpoint with missing dosage instructions message
33+
Given I am an authorised prescriber
34+
When I make a request with file missing_dosage_instructions/request.json to the eps_fhir validator endpoint
35+
Then the response indicates a bad request
36+
And the validator response matches missing_dosage_instructions/response.json
37+
38+
Scenario: I can call the validator endpoint with missing dispense request quantity message
39+
Given I am an authorised prescriber
40+
When I make a request with file missing_dispense_request_quantity/request.json to the eps_fhir validator endpoint
41+
Then the response indicates a bad request
42+
And the validator response matches missing_dispense_request_quantity/response.json
43+
44+
Scenario: I can call the validator endpoint with missing medication message
45+
Given I am an authorised prescriber
46+
When I make a request with file missing_medication/request.json to the eps_fhir validator endpoint
47+
Then the response indicates a bad request
48+
And the validator response matches missing_medication/response.json
49+
50+
Scenario: I can call the validator endpoint with too many medication requests message
51+
Given I am an authorised prescriber
52+
When I make a request with file too_many_medication_requests/request.json to the eps_fhir validator endpoint
53+
Then the response indicates a bad request
54+
And the validator response matches too_many_medication_requests/response.json
55+
56+
Scenario: I can call the validator endpoint with unknown endorsement message
57+
Given I am an authorised prescriber
58+
When I make a request with file unknown_endorsement/request.json to the eps_fhir validator endpoint
59+
Then the response indicates a bad request
60+
And the validator response matches unknown_endorsement/response.json

features/eps_fhir_dispensing/validator.feature

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@eps_fhir_dispensing @smoke @regression @validator
22
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4895
3+
@allure.tms:https://jsondiff.tooliverse.io/
34
Feature: I can call the validator endpoint
45

56
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to false
@@ -27,3 +28,33 @@ Feature: I can call the validator endpoint
2728
Then the response indicates a bad request
2829
And the validator response has many error issue
2930
And the validator response has error with diagnostic containing Failed to parse JSON encoded FHIR content
31+
32+
Scenario: I can call the validator endpoint with missing dosage instructions message
33+
Given I am an authorised prescriber
34+
When I make a request with file missing_dosage_instructions/request.json to the eps_fhir_dispensing validator endpoint
35+
Then the response indicates a bad request
36+
And the validator response matches missing_dosage_instructions/response.json
37+
38+
Scenario: I can call the validator endpoint with missing dispense request quantity message
39+
Given I am an authorised prescriber
40+
When I make a request with file missing_dispense_request_quantity/request.json to the eps_fhir_dispensing validator endpoint
41+
Then the response indicates a bad request
42+
And the validator response matches missing_dispense_request_quantity/response.json
43+
44+
Scenario: I can call the validator endpoint with missing medication message
45+
Given I am an authorised prescriber
46+
When I make a request with file missing_medication/request.json to the eps_fhir_dispensing validator endpoint
47+
Then the response indicates a bad request
48+
And the validator response matches missing_medication/response.json
49+
50+
Scenario: I can call the validator endpoint with too many medication requests message
51+
Given I am an authorised prescriber
52+
When I make a request with file too_many_medication_requests/request.json to the eps_fhir_dispensing validator endpoint
53+
Then the response indicates a bad request
54+
And the validator response matches too_many_medication_requests/response.json
55+
56+
Scenario: I can call the validator endpoint with unknown endorsement message
57+
Given I am an authorised prescriber
58+
When I make a request with file unknown_endorsement/request.json to the eps_fhir_dispensing validator endpoint
59+
Then the response indicates a bad request
60+
And the validator response matches unknown_endorsement/response.json

features/eps_fhir_prescribing/validator.feature

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@eps_fhir_prescribing @smoke @regression @validator
22
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4895
3+
@allure.tms:https://jsondiff.tooliverse.io/
34
Feature: I can call the validator endpoint
45

56
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to false
@@ -27,3 +28,33 @@ Feature: I can call the validator endpoint
2728
Then the response indicates a bad request
2829
And the validator response has many error issue
2930
And the validator response has error with diagnostic containing Failed to parse JSON encoded FHIR content
31+
32+
Scenario: I can call the validator endpoint with missing dosage instructions message
33+
Given I am an authorised prescriber
34+
When I make a request with file missing_dosage_instructions/request.json to the eps_fhir_prescribing validator endpoint
35+
Then the response indicates a bad request
36+
And the validator response matches missing_dosage_instructions/response.json
37+
38+
Scenario: I can call the validator endpoint with missing dispense request quantity message
39+
Given I am an authorised prescriber
40+
When I make a request with file missing_dispense_request_quantity/request.json to the eps_fhir_prescribing validator endpoint
41+
Then the response indicates a bad request
42+
And the validator response matches missing_dispense_request_quantity/response.json
43+
44+
Scenario: I can call the validator endpoint with missing medication message
45+
Given I am an authorised prescriber
46+
When I make a request with file missing_medication/request.json to the eps_fhir_prescribing validator endpoint
47+
Then the response indicates a bad request
48+
And the validator response matches missing_medication/response.json
49+
50+
Scenario: I can call the validator endpoint with too many medication requests message
51+
Given I am an authorised prescriber
52+
When I make a request with file too_many_medication_requests/request.json to the eps_fhir_prescribing validator endpoint
53+
Then the response indicates a bad request
54+
And the validator response matches too_many_medication_requests/response.json
55+
56+
Scenario: I can call the validator endpoint with unknown endorsement message
57+
Given I am an authorised prescriber
58+
When I make a request with file unknown_endorsement/request.json to the eps_fhir_prescribing validator endpoint
59+
Then the response indicates a bad request
60+
And the validator response matches unknown_endorsement/response.json

features/steps/eps_api_steps.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from methods.shared.common import assert_that, get_auth
1818
from utils.random_nhs_number_generator import generate_single
1919
from messages.eps_fhir.prescription import Prescription
20+
from jycm.jycm import YouchamaJsonDiffer
2021

2122

2223
@given("I successfully prepare and sign a prescription")
@@ -185,6 +186,13 @@ def i_make_a_request_to_the_validator_endpoint(
185186
call_validator(context, product, show_validation, validate_body)
186187

187188

189+
@when("I make a request with file {filename} to the {product} validator endpoint")
190+
def i_make_a_request_to_the_validator_endpoint_with_file(context, filename, product):
191+
with open(f"messages/examples/{filename}") as f:
192+
validate_body = json.load(f)
193+
call_validator(context, product, "unset", json.dumps(validate_body))
194+
195+
188196
@then("the validator response has {expected_issue_count} {issue_type} issue")
189197
def validator_response_has_n_issues_of_type(context, expected_issue_count, issue_type):
190198
json_response = json.loads(context.response.content)
@@ -208,3 +216,16 @@ def validator_response_has_error_issue_with_diagnostic(context, diagnostic):
208216
for p in json_response["issue"]
209217
)
210218
assert_that(actual_issue_count).is_equal_to(1)
219+
220+
221+
@then("the validator response matches {filename}")
222+
def validator_response_matches_file(context, filename):
223+
with open(f"messages/examples/{filename}") as f:
224+
expected_response = json.load(f)
225+
json_response = json.loads(context.response.content)
226+
# create the YouChaMa (ycm) json diff class with expected and actual response
227+
ycm = YouchamaJsonDiffer(expected_response, json_response)
228+
# get the differences
229+
diff_result = ycm.get_diff()
230+
# and there should be none
231+
assert_that(diff_result).is_equal_to({"just4vis:pairs": []})

0 commit comments

Comments
 (0)