Skip to content

Commit

Permalink
feature/PI-582-modify_readdevice_endpoint_for_mhs Add unit test for c…
Browse files Browse the repository at this point in the history
…reate mhs device
  • Loading branch information
megan-bower4 committed Nov 20, 2024
1 parent a4bb28e commit a3877ef
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/api/createDeviceMessageHandlingSystem/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def mock_epr_product_with_message_set_drd() -> (
)
product_repo.write(entity=product)

# set up questionnaire response
# set up questionnaire responses
mhs_message_set_questionnaire = QuestionnaireRepository().read(
QuestionnaireInstance.SPINE_MHS_MESSAGE_SETS
)
Expand All @@ -92,7 +92,6 @@ def mock_epr_product_with_message_set_drd() -> (
"MHS IN": "baz",
}
)

questionnaire_response_2 = mhs_message_set_questionnaire.validate(
data={
"Interaction ID": "urn:foo2",
Expand Down Expand Up @@ -375,4 +374,40 @@ def test_no_existing_message_set_drd():
assert expected_message_code in response["body"]


# add test for already existing mhs device?
def test_mhs_already_exists() -> None:
with mock_epr_product_with_message_set_drd() as (index, product):
# Execute the lambda
index.handler(
event={
"headers": {"version": VERSION},
"body": json.dumps(
{"questionnaire_responses": {"spine_mhs": [QUESTIONNAIRE_DATA]}}
),
"pathParameters": {
"product_team_id": str(product.product_team_id),
"product_id": str(product.id),
},
}
)

# Execute the lambda again
response = index.handler(
event={
"headers": {"version": VERSION},
"body": json.dumps(
{"questionnaire_responses": {"spine_mhs": [QUESTIONNAIRE_DATA]}}
),
"pathParameters": {
"product_team_id": str(product.product_team_id),
"product_id": str(product.id),
},
}
)

assert response["statusCode"] == 400
expected_error_code = "VALIDATION_ERROR"
expected_message_code = (
"There is already an existing MHS Device for this Product"
)
assert expected_error_code in response["body"]
assert expected_message_code in response["body"]

0 comments on commit a3877ef

Please sign in to comment.