|
32 | 32 | from brunns.matchers.werkzeug import is_werkzeug_response as is_response |
33 | 33 | from flask.testing import FlaskClient |
34 | 34 | from hamcrest import ( |
| 35 | + all_of, |
35 | 36 | assert_that, |
36 | 37 | greater_than_or_equal_to, |
37 | 38 | has_entries, |
@@ -170,3 +171,74 @@ def test_add_days_with_formatted_date_output( |
170 | 171 | actions, |
171 | 172 | has_item(has_entries(actionCode="DateOfNextEarliestVaccination", description="29 April 2026")), |
172 | 173 | ) |
| 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