Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/eligibility_signposting_api/model/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class Iteration(BaseModel):
iteration_number: int | None = Field(None, alias="IterationNumber")
approval_minimum: int | None = Field(None, alias="ApprovalMinimum")
approval_maximum: int | None = Field(None, alias="ApprovalMaximum")
type: Literal["A", "M", "S"] = Field(..., alias="Type")
type: Literal["A", "M", "S", "O"] = Field(..., alias="Type")
default_comms_routing: str = Field(..., alias="DefaultCommsRouting")
iteration_cohorts: list[IterationCohort] = Field(..., alias="IterationCohorts")
iteration_rules: list[IterationRule] = Field(..., alias="IterationRules")
Expand Down
68 changes: 56 additions & 12 deletions tests/unit/services/calculators/test_eligibility_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def test_only_live_campaigns_considered(faker: Faker):
"iteration_type",
["A", "M", "S", "O"],
)
def test_campaigns_with_applicable_iteration_types_considered(iteration_type: str, faker: Faker):
def test_campaigns_with_applicable_iteration_types_in_campaign_level_considered(iteration_type: str, faker: Faker):
# Given
nhs_number = NHSNumber(faker.nhs_number())

Expand All @@ -230,15 +230,59 @@ def test_campaigns_with_applicable_iteration_types_considered(iteration_type: st
)


@pytest.mark.parametrize(
"iteration_type",
["A", "M", "S", "O"],
)
def test_campaigns_with_applicable_iteration_types_in_iteration_level_considered(iteration_type: str, faker: Faker):
# Given
nhs_number = NHSNumber(faker.nhs_number())

person_rows = person_rows_builder(nhs_number)
campaign_configs = [
rule_builder.CampaignConfigFactory.build(
target="RSV", iterations=[rule_builder.IterationFactory.build(type=iteration_type)]
)
]

calculator = EligibilityCalculator(person_rows, campaign_configs)

# When
actual = calculator.evaluate_eligibility()

# Then
assert_that(
actual,
is_eligibility_status().with_conditions(
has_item(
is_condition()
.with_condition_name(ConditionName("RSV"))
.and_status(is_in([Status.actionable, Status.not_actionable, Status.not_eligible]))
),
),
)


@pytest.mark.parametrize(
"iteration_type",
["NA", "N", "FAKE", "F"],
)
def test_invalid_iteration_type_raises_validation_error(iteration_type: str):
def test_invalid_iteration_types_in_campaign_level_raises_validation_error(iteration_type: str):
with pytest.raises(ValidationError):
rule_builder.CampaignConfigFactory.build(target="RSV", iteration_type=iteration_type)


@pytest.mark.parametrize(
"iteration_type",
["NA", "N", "FAKE", "F"],
)
def test_invalid_iteration_types_in_iteration_level_raises_validation_error(iteration_type: str):
with pytest.raises(ValidationError):
rule_builder.CampaignConfigFactory.build(
target="RSV", iterations=[rule_builder.IterationFactory.build(type=iteration_type)]
)


def test_base_eligible_and_simple_rule_includes(faker: Faker):
# Given
nhs_number = NHSNumber(faker.nhs_number())
Expand Down Expand Up @@ -1730,47 +1774,47 @@ def test_cohort_group_descriptions_pick_first_non_empty_if_available(
[
(
"""Rule match: default_comms_routing present, action_mapper present,
return actions from matching comms from rule""",
return actions from matching comms from rule""",
"defaultcomms",
"InternalBookNBS",
{"InternalBookNBS": book_nbs_comms, "defaultcomms": default_comms_detail},
SuggestedActions([suggested_action_for_book_nbs]),
),
(
"""Rule match: default_comms_routing has multiple values,
comms missing in rule, all default comms should be returned in actions""",
comms missing in rule, all default comms should be returned in actions""",
"defaultcomms1|defaultcomms2",
None,
{"defaultcomms1": default_comms_detail, "defaultcomms2": default_comms_detail},
SuggestedActions([suggested_action_for_default_comms, suggested_action_for_default_comms]),
),
(
"""Rule match: default_comms_routing has multiple values,
comms is empty string, all default comms should be returned in actions""",
comms is empty string, all default comms should be returned in actions""",
"defaultcomms1",
"",
{"defaultcomms1": default_comms_detail},
SuggestedActions([suggested_action_for_default_comms]),
),
(
"""Rule match: default_comms_routing present,
action_mapper missing for matching comms, return default_comms in actions""",
action_mapper missing for matching comms, return default_comms in actions""",
"defaultcomms",
"InternalBookNBS",
{"defaultcomms": default_comms_detail},
SuggestedActions([suggested_action_for_default_comms]),
),
(
"""Rule match: default_comms_routing present,
rule has an incorrect comms key, return default_comms in actions""",
rule has an incorrect comms key, return default_comms in actions""",
"defaultcomms",
"InvalidCode",
{"defaultcomms": default_comms_detail},
SuggestedActions([suggested_action_for_default_comms]),
),
(
"""Rule match: action_mapper present without url,
return actions from matching comms from rule""",
return actions from matching comms from rule""",
"defaultcomms",
"InternalBookNBS",
{
Expand All @@ -1794,31 +1838,31 @@ def test_cohort_group_descriptions_pick_first_non_empty_if_available(
),
(
"""Rule match: default_comms_routing missing,
comms present in rule, action_mapper missing, return no actions""",
comms present in rule, action_mapper missing, return no actions""",
"",
"InternalBookNBS",
{},
SuggestedActions([]),
),
(
"""Rule match: default_comms_routing missing, but action_mapper present,
return actions from matching comms from rule""",
return actions from matching comms from rule""",
"",
"InternalBookNBS",
{"InternalBookNBS": book_nbs_comms},
SuggestedActions([suggested_action_for_book_nbs]),
),
(
"""Rule match: default_comms_routing present,
comms present in rule, but action_mapper missing, return no actions""",
comms present in rule, but action_mapper missing, return no actions""",
"defaultcommskeywithoutactionmapper",
"InternalBookNBS",
{},
SuggestedActions([]),
),
(
"""Rule match: default_comms_routing has multiple values,
one of the value is invalid, valid values should be returned in actions""",
one of the value is invalid, valid values should be returned in actions""",
"defaultcomms1|invaliddefault",
None,
{"defaultcomms1": default_comms_detail},
Expand Down