mirror of
https://github.com/Sea-Haven-Industries/meal-order-manager.git
synced 2026-09-30 22:53:12 +00:00
* feat(api): serve meals on ECS Fargate instead of Lambda Keep the Flask app always-on with in-process jobs so CloudFront no longer fronts a cold-start API Gateway. * fix(jobs): run delayed close and reminder deliveries Wall-clock skip windows dropped the only weekly SQS attempt when Scheduler already fired in Eastern time. Dev schedules stay disabled. * fix(api): return JSON objects and stop logging job payloads Flask now jsonify-s handler dicts so API responses are not HTML, and the worker logs only event and status. * fix(ci): restore the reusable workflow so the required check is named ci / ci Inlining the job reported `ci` instead of the org ruleset's `ci / ci`. * fix(secrets): drop unused os import so ruff check passes * style: apply ruff format so ci-python-app lint passes * fix(infra): give meals its own VPC because prod has none * chore(security): re-key ALB SG checkov suppression after vpc.tf
55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
"""Unit tests for src/server/jobs/close_form.py."""
|
|
|
|
import os
|
|
import sys
|
|
from unittest.mock import patch
|
|
|
|
os.environ.setdefault(
|
|
"AGGREGATE_FUNCTION_ARN",
|
|
"arn:aws:lambda:us-east-1:000000000000:function:test-aggregate",
|
|
)
|
|
|
|
import importlib.util
|
|
|
|
_handler_path = os.path.join(
|
|
os.path.dirname(__file__), os.pardir, "src", "server", "jobs", "close_form.py"
|
|
)
|
|
_spec = importlib.util.spec_from_file_location(
|
|
"close_form_handler", os.path.abspath(_handler_path)
|
|
)
|
|
close_form_handler = importlib.util.module_from_spec(_spec)
|
|
sys.modules["close_form_handler"] = close_form_handler
|
|
_spec.loader.exec_module(close_form_handler)
|
|
|
|
|
|
class TestCloseForm:
|
|
@patch("close_form_handler.set_form_status")
|
|
@patch("close_form_handler.get_form_status", return_value="open")
|
|
@patch("close_form_handler.current_week", return_value="2026-W19")
|
|
@patch("close_form_handler._dispatch_job")
|
|
def test_closes_open_form(self, mock_lam, mock_week, mock_status, mock_set):
|
|
result = close_form_handler.lambda_handler({}, None)
|
|
|
|
assert result["status"] == "closed"
|
|
mock_set.assert_called_once_with("2026-W19", "closed")
|
|
mock_lam.assert_called_once_with({"event": "aggregate", "week": "2026-W19"})
|
|
|
|
@patch("close_form_handler.set_form_status")
|
|
@patch("close_form_handler.get_form_status", return_value="open")
|
|
@patch("close_form_handler._dispatch_job")
|
|
def test_uses_week_from_event(self, mock_lam, mock_status, mock_set):
|
|
result = close_form_handler.lambda_handler({"week": "2026-W20"}, None)
|
|
|
|
assert result["status"] == "closed"
|
|
mock_set.assert_called_once_with("2026-W20", "closed")
|
|
|
|
@patch("close_form_handler.set_form_status")
|
|
@patch("close_form_handler.get_form_status", return_value="closed")
|
|
@patch("close_form_handler.current_week", return_value="2026-W19")
|
|
@patch("close_form_handler._dispatch_job")
|
|
def test_already_closed(self, mock_lam, mock_week, mock_status, mock_set):
|
|
result = close_form_handler.lambda_handler({}, None)
|
|
|
|
assert result["status"] == "already_closed"
|
|
mock_set.assert_not_called()
|
|
mock_lam.assert_not_called()
|