Skip to content

Commit

Permalink
[PRMDR-699] unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelHowellNHS committed Feb 22, 2024
1 parent 4cbc600 commit 0ba00f4
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions lambdas/tests/unit/handlers/test_process_nems_message.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from handlers.nems_message_handler import lambda_handler
from services.feature_flags_service import FeatureFlagService
from services.process_nems_message_service import ProcessNemsMessageService
from tests.unit.helpers.data.bulk_upload.test_data import (
TEST_EVENT_WITH_NO_SQS_MESSAGES,
Expand All @@ -14,7 +15,23 @@ def mock_service(mocker):
yield mocker.patch.object(ProcessNemsMessageService, "process_messages_from_event")


def test_can_process_event_with_one_message_no_error(mock_service, context, set_env):
@pytest.fixture
def mock_nems_enabled(mocker):
mock_function = mocker.patch.object(FeatureFlagService, "get_feature_flags_by_flag")
mock_nems_feature_flag = mock_function.return_value = {"nemsEnabled": True}
yield mock_nems_feature_flag


@pytest.fixture
def mock_nems_disabled(mocker):
mock_function = mocker.patch.object(FeatureFlagService, "get_feature_flags_by_flag")
mock_nems_feature_flag = mock_function.return_value = {"nemsEnabled": False}
yield mock_nems_feature_flag


def test_can_process_event_with_one_message_no_error(
mock_service, context, set_env, mock_nems_enabled
):
expected = {"batchItemFailures": []}
mock_service.return_value = []

Expand All @@ -25,7 +42,7 @@ def test_can_process_event_with_one_message_no_error(mock_service, context, set_


def test_can_process_event_with_several_messages_no_error(
mock_service, context, set_env
mock_service, context, set_env, mock_nems_enabled
):
expected = {"batchItemFailures": []}
mock_service.return_value = []
Expand All @@ -37,7 +54,7 @@ def test_can_process_event_with_several_messages_no_error(


def test_can_process_event_with_several_messages_with_fail(
mock_service, context, set_env
mock_service, context, set_env, mock_nems_enabled
):
expected = {"batchItemFailures": ["test_response"]}
mock_service.return_value = ["test_response"]
Expand All @@ -49,7 +66,7 @@ def test_can_process_event_with_several_messages_with_fail(


def test_receive_correct_response_when_no_records_in_event(
mock_service, context, set_env
mock_service, context, set_env, mock_nems_enabled
):
expected = ApiGatewayResponse(
400,
Expand All @@ -59,3 +76,11 @@ def test_receive_correct_response_when_no_records_in_event(
actual = lambda_handler(TEST_EVENT_WITH_NO_SQS_MESSAGES, context)

assert expected == actual


def test_no_event_processing_when_nems_flag_not_enabled(
mock_service, context, set_env, mock_nems_disabled
):
lambda_handler(TEST_EVENT_WITH_SQS_MESSAGES, context)

mock_service.assert_not_called()

0 comments on commit 0ba00f4

Please sign in to comment.