mirror of
https://github.com/Sea-Haven-Industries/afterhours-shift-manager.git
synced 2026-09-30 06:43:12 +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
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
"""Worker dispatch: holiday SQS payload and known job events."""
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
|
|
from server import jobs
|
|
|
|
|
|
def test_holiday_activate_payload_calls_holiday_flow(monkeypatch):
|
|
activate = MagicMock(return_value={"action": "activate", "date": "2026-07-04"})
|
|
monkeypatch.setattr("server.jobs.activate", activate)
|
|
monkeypatch.setattr("server.jobs.ShiftSchedule", MagicMock)
|
|
result = jobs.run_job(
|
|
{"event": "holiday", "action": "activate", "date": "2026-07-04"}
|
|
)
|
|
assert result["action"] == "activate"
|
|
activate.assert_called_once()
|
|
assert activate.call_args.args[1] == "2026-07-04"
|
|
|
|
|
|
def test_holiday_deactivate_payload_calls_holiday_flow(monkeypatch):
|
|
deactivate = MagicMock(return_value={"action": "deactivate", "date": "2026-07-04"})
|
|
monkeypatch.setattr("server.jobs.deactivate", deactivate)
|
|
monkeypatch.setattr("server.jobs.ShiftSchedule", MagicMock)
|
|
result = jobs.run_job(
|
|
{"event": "holiday", "action": "deactivate", "date": "2026-07-04"}
|
|
)
|
|
assert result["action"] == "deactivate"
|
|
deactivate.assert_called_once()
|
|
|
|
|
|
def test_unknown_job_raises():
|
|
with pytest.raises(ValueError, match="unknown job event"):
|
|
jobs.run_job({"event": "nope"})
|
|
|
|
|
|
def test_weekly_post_dispatches_with_force(monkeypatch):
|
|
handler = MagicMock(return_value={"posted": True})
|
|
monkeypatch.setattr(
|
|
jobs,
|
|
"_load_lambda_app",
|
|
lambda name: MagicMock(handler=handler) if name == "weekly-post" else None,
|
|
)
|
|
result = jobs.run_job({"event": "weekly_post"})
|
|
assert result == {"posted": True}
|
|
assert handler.call_args.args[0]["force"] is True
|
|
|
|
|
|
def test_ring_scheduler_events_share_handler(monkeypatch):
|
|
handler = MagicMock(return_value={"ok": True})
|
|
monkeypatch.setattr(
|
|
jobs,
|
|
"_load_lambda_app",
|
|
lambda name: MagicMock(handler=handler),
|
|
)
|
|
jobs.run_job({"event": "ring_scheduler_daily"})
|
|
jobs.run_job({"event": "ring_scheduler_weekend"})
|
|
assert handler.call_count == 2
|
|
assert handler.call_args.args[0]["force"] is True
|