meal-order-manager/tests/test_app.py
Adam Moussa af2743f23c
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.
2026-09-21 15:00:33 -04:00

47 lines
1.5 KiB
Python

"""Flask app health and CORS preflight."""
import os
os.environ.setdefault("AWS_DEFAULT_REGION", "us-east-1")
os.environ.setdefault("TABLE_NAME", "test-orders-table")
from server.app import create_app
def test_health_returns_stage_and_sha(monkeypatch):
monkeypatch.setenv("STAGE", "local")
monkeypatch.setenv("GIT_SHA", "abc123")
client = create_app().test_client()
response = client.get("/api/health")
assert response.status_code == 200
assert response.get_json() == {"stage": "local", "sha": "abc123"}
def test_options_preflight_from_portal_origin():
client = create_app().test_client()
response = client.options(
"/api/submit-order",
headers={"Origin": "https://internal.seahaven.com"},
)
assert response.status_code == 204
assert (
response.headers["Access-Control-Allow-Origin"]
== "https://internal.seahaven.com"
)
assert "Authorization" in response.headers["Access-Control-Allow-Headers"]
def test_api_dispatch_jsonifies_handler_body():
from unittest.mock import patch
with patch("server.http_api.lambda_handler") as mock_handler:
mock_handler.return_value = {
"statusCode": 400,
"headers": {"Content-Type": "application/json"},
"body": '{"error": "Bad request"}',
}
client = create_app().test_client()
response = client.get("/api/menu")
assert response.status_code == 400
assert response.get_json() == {"error": "Bad request"}
assert response.content_type.startswith("application/json")