Skip to content

Commit 42c3776

Browse files
committed
eli-579 adding integration test to test that functions can use multiple instances a function
1 parent afea6a3 commit 42c3776

2 files changed

Lines changed: 121 additions & 0 deletions

File tree

tests/integration/conftest.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,55 @@ def campaign_config_with_derived_values_formatted(
10941094
s3_client.delete_object(Bucket=rules_bucket, Key=f"{campaign.name}.json")
10951095

10961096

1097+
@pytest.fixture
1098+
def campaign_config_with_multiple_add_days(
1099+
s3_client: BaseClient, rules_bucket: BucketName
1100+
) -> Generator[CampaignConfig]:
1101+
"""Campaign config with multiple actions using ADD_DAYS with different parameters."""
1102+
campaign: CampaignConfig = rule.CampaignConfigFactory.build(
1103+
target="COVID",
1104+
iterations=[
1105+
rule.IterationFactory.build(
1106+
default_comms_routing="DERIVED_LAST_DATE|DERIVED_NEXT_DOSE_91|DERIVED_NEXT_DOSE_61",
1107+
actions_mapper=rule.ActionsMapperFactory.build(
1108+
root={
1109+
"DERIVED_LAST_DATE": AvailableAction(
1110+
ActionType="DataValue",
1111+
ExternalRoutingCode="DateOfLastVaccination",
1112+
ActionDescription="[[TARGET.COVID.LAST_SUCCESSFUL_DATE]]",
1113+
),
1114+
"DERIVED_NEXT_DOSE_91": AvailableAction(
1115+
ActionType="DataValue",
1116+
ExternalRoutingCode="DateOfNextDoseAt91Days",
1117+
ActionDescription="[[TARGET.COVID.NEXT_DOSE_DUE:ADD_DAYS(91)]]",
1118+
),
1119+
"DERIVED_NEXT_DOSE_61": AvailableAction(
1120+
ActionType="DataValue",
1121+
ExternalRoutingCode="DateOfNextDoseAt61Days",
1122+
ActionDescription="[[TARGET.COVID.NEXT_DOSE_DUE:ADD_DAYS(61)]]",
1123+
),
1124+
}
1125+
),
1126+
iteration_rules=[],
1127+
iteration_cohorts=[
1128+
rule.IterationCohortFactory.build(
1129+
cohort_label="cohort_label1",
1130+
cohort_group="cohort_group1",
1131+
positive_description="Positive Description",
1132+
negative_description="Negative Description",
1133+
)
1134+
],
1135+
)
1136+
],
1137+
)
1138+
campaign_data = {"CampaignConfig": campaign.model_dump(by_alias=True)}
1139+
s3_client.put_object(
1140+
Bucket=rules_bucket, Key=f"{campaign.name}.json", Body=json.dumps(campaign_data), ContentType="application/json"
1141+
)
1142+
yield campaign
1143+
s3_client.delete_object(Bucket=rules_bucket, Key=f"{campaign.name}.json")
1144+
1145+
10971146
@pytest.fixture(scope="class")
10981147
def multiple_campaign_configs(s3_client: BaseClient, rules_bucket: BucketName) -> Generator[list[CampaignConfig]]:
10991148
"""Create and upload multiple campaign configs to S3, then clean up after tests."""

tests/integration/in_process/test_derived_values.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from brunns.matchers.werkzeug import is_werkzeug_response as is_response
3333
from flask.testing import FlaskClient
3434
from hamcrest import (
35+
all_of,
3536
assert_that,
3637
greater_than_or_equal_to,
3738
has_entries,
@@ -170,3 +171,74 @@ def test_add_days_with_formatted_date_output(
170171
actions,
171172
has_item(has_entries(actionCode="DateOfNextEarliestVaccination", description="29 April 2026")),
172173
)
174+
175+
176+
class TestMultipleActionsWithAddDays:
177+
"""Test that multiple actions can use ADD_DAYS with different parameters."""
178+
179+
def test_multiple_actions_with_different_add_days_parameters(
180+
self,
181+
client: FlaskClient,
182+
campaign_config_with_multiple_add_days: CampaignConfig, # noqa: ARG002
183+
person_with_covid_vaccination: NHSNumber,
184+
):
185+
"""
186+
Test that multiple actions can use the same function (ADD_DAYS) with different parameters.
187+
188+
This test verifies that when a campaign has multiple actions that use ADD_DAYS with different
189+
parameters (e.g., ADD_DAYS(91) and ADD_DAYS(61)), both calculations are performed correctly.
190+
191+
Given:
192+
- A person with a COVID vaccination date of 2026-01-28 (20260128)
193+
- A campaign config with three actions:
194+
1. DateOfLastVaccination: Returns the raw LAST_SUCCESSFUL_DATE
195+
2. DateOfNextDoseAt91Days: Returns NEXT_DOSE_DUE with ADD_DAYS(91)
196+
3. DateOfNextDoseAt61Days: Returns NEXT_DOSE_DUE with ADD_DAYS(61)
197+
198+
When:
199+
- The /patient-check endpoint is called with includeActions=Y
200+
201+
Then:
202+
- DateOfLastVaccination should be "20260128" (raw date)
203+
- DateOfNextDoseAt91Days should be "20260429" (2026-01-28 + 91 days)
204+
- DateOfNextDoseAt61Days should be "20260330" (2026-01-28 + 61 days)
205+
206+
This addresses the reviewer's suggestion to test multiple actions using the same
207+
function with different parameters.
208+
"""
209+
# Given
210+
headers = {"nhs-login-nhs-number": str(person_with_covid_vaccination)}
211+
212+
# When
213+
response = client.get(
214+
f"/patient-check/{person_with_covid_vaccination}?includeActions=Y",
215+
headers=headers,
216+
)
217+
218+
# Then
219+
assert_that(
220+
response,
221+
is_response().with_status_code(HTTPStatus.OK).and_text(is_json_that(has_key("processedSuggestions"))),
222+
)
223+
224+
body = response.get_json()
225+
assert_that(body, is_not(none()))
226+
processed_suggestions = body.get("processedSuggestions", [])
227+
228+
covid_suggestion = next(
229+
(s for s in processed_suggestions if s.get("condition") == "COVID"),
230+
None,
231+
)
232+
assert_that(covid_suggestion, is_not(none()))
233+
234+
actions = covid_suggestion.get("actions", []) # type: ignore[union-attr]
235+
236+
# Verify all three actions are present with correct values
237+
assert_that(
238+
actions,
239+
all_of(
240+
has_item(has_entries(actionCode="DateOfLastVaccination", description="20260128")),
241+
has_item(has_entries(actionCode="DateOfNextDoseAt91Days", description="20260429")),
242+
has_item(has_entries(actionCode="DateOfNextDoseAt61Days", description="20260330")),
243+
),
244+
)

0 commit comments

Comments
 (0)