mirror of
https://github.com/Sea-Haven-Industries/meal-order-manager.git
synced 2026-09-30 20:33:13 +00:00
Flask now jsonify-s handler dicts so API responses are not HTML, and the worker logs only event and status.
47 lines
1.5 KiB
Python
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")
|