mirror of
https://github.com/Sea-Haven-Industries/afterhours-shift-manager.git
synced 2026-09-30 12:33:13 +00:00
* feat(api): collapse Slack, portal, and jobs onto Fargate (PLAT-216) Move HTTP and scheduled work onto one always-on Flask task so after-hours loses Lambda cold start without changing the Cognito or roster contracts. * fix(portal-api): keep CORS headers on unexpected 500s Portal SPA error handling needs Access-Control-Allow-Origin even when DynamoDB or other internals fail, otherwise the browser hides the 500. * fix(api): retarget holidays per account and ship App Home changelog (PLAT-216) * fix(iam): list ECS tasks and fail closed on non-prod Paychex (PLAT-216) * fix(portal-api): serve portal JSON with an explicit JSON content type
81 lines
3 KiB
Python
81 lines
3 KiB
Python
"""Holiday schedule targets: SQS when JOBS_QUEUE_ARN is set, else Lambda."""
|
|
|
|
import json
|
|
from unittest.mock import MagicMock
|
|
|
|
from shared.side_effects import (
|
|
_holiday_schedule_target,
|
|
activate_holiday_inline,
|
|
create_holiday_schedules,
|
|
)
|
|
|
|
|
|
def test_sqs_target_when_jobs_queue_arn_set(monkeypatch):
|
|
monkeypatch.setenv(
|
|
"JOBS_QUEUE_ARN", "arn:aws:sqs:us-east-1:1:afterhours-shift-manager-jobs"
|
|
)
|
|
monkeypatch.setenv(
|
|
"HOLIDAY_SCHEDULER_ROLE_ARN", "arn:aws:iam::1:role/tf-managed/holiday"
|
|
)
|
|
monkeypatch.delenv("HOLIDAY_ROUTER_ARN", raising=False)
|
|
target = _holiday_schedule_target("activate", "2026-07-04")
|
|
assert target["Arn"].endswith(":afterhours-shift-manager-jobs")
|
|
payload = json.loads(target["Input"])
|
|
assert payload == {
|
|
"event": "holiday",
|
|
"action": "activate",
|
|
"date": "2026-07-04",
|
|
}
|
|
|
|
|
|
def test_lambda_target_when_jobs_queue_unset(monkeypatch):
|
|
monkeypatch.delenv("JOBS_QUEUE_ARN", raising=False)
|
|
monkeypatch.setenv(
|
|
"HOLIDAY_ROUTER_ARN",
|
|
"arn:aws:lambda:us-east-1:1:function:afterhours-holiday-router",
|
|
)
|
|
monkeypatch.setenv(
|
|
"HOLIDAY_SCHEDULER_ROLE_ARN", "arn:aws:iam::1:role/tf-managed/holiday"
|
|
)
|
|
target = _holiday_schedule_target("deactivate", "2026-07-04")
|
|
assert "function:afterhours-holiday-router" in target["Arn"]
|
|
payload = json.loads(target["Input"])
|
|
assert payload == {"action": "deactivate", "date": "2026-07-04"}
|
|
|
|
|
|
def test_inline_activate_in_process_when_jobs_queue_url_set(monkeypatch):
|
|
monkeypatch.setenv("JOBS_QUEUE_URL", "https://sqs.us-east-1.amazonaws.com/1/jobs")
|
|
activate = MagicMock()
|
|
monkeypatch.setattr("shared.holiday_flow.activate", activate)
|
|
activate_holiday_inline(MagicMock(), "2026-07-04")
|
|
activate.assert_called_once()
|
|
|
|
|
|
def test_inline_activate_invokes_lambda_without_jobs_queue(monkeypatch):
|
|
monkeypatch.delenv("JOBS_QUEUE_URL", raising=False)
|
|
monkeypatch.setenv(
|
|
"HOLIDAY_ROUTER_ARN", "arn:aws:lambda:us-east-1:1:function:router"
|
|
)
|
|
client = MagicMock()
|
|
monkeypatch.setattr("shared.side_effects.boto3.client", lambda _svc: client)
|
|
activate_holiday_inline(MagicMock(), "2026-07-04")
|
|
client.invoke.assert_called_once()
|
|
assert client.invoke.call_args.kwargs["FunctionName"].endswith(":function:router")
|
|
|
|
|
|
def test_create_holiday_schedules_uses_sqs_target(monkeypatch):
|
|
monkeypatch.setenv(
|
|
"JOBS_QUEUE_ARN", "arn:aws:sqs:us-east-1:1:afterhours-shift-manager-jobs"
|
|
)
|
|
monkeypatch.setenv(
|
|
"HOLIDAY_SCHEDULER_ROLE_ARN", "arn:aws:iam::1:role/tf-managed/holiday"
|
|
)
|
|
client = MagicMock()
|
|
monkeypatch.setattr("shared.side_effects.boto3.client", lambda _svc: client)
|
|
names = create_holiday_schedules("2026-07-04")
|
|
assert names == ["holiday-activate-20260704", "holiday-deactivate-20260704"]
|
|
assert client.create_schedule.call_count == 2
|
|
first_input = json.loads(
|
|
client.create_schedule.call_args_list[0].kwargs["Target"]["Input"]
|
|
)
|
|
assert first_input["event"] == "holiday"
|