refactor(status): introduce OrderStatus enum, replace string literals

Centralized order status values in api/app/constants.py via a
str-valued Enum so comparisons keep working. Replaced literals in:
- services: sync_service, sqlite_service, retry_service
- routers: sync, dashboard
- templates: dashboard.html, logs.html
- static JS: shared (ORDER_STATUS mirror), dashboard, logs
- tests: requirements, order_items_overwrite, business_rules

MALFORMED intentionally NOT added — introduced in follow-up PR2
(per-order failure isolation).

Full test suite: 231 unit + 33 e2e pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude Agent
2026-04-22 08:45:32 +00:00
parent 51790accf9
commit f6d283b743
14 changed files with 171 additions and 133 deletions

View File

@@ -36,6 +36,7 @@ import pytest_asyncio
from app.database import init_sqlite
from app.services import sqlite_service
from app.constants import OrderStatus
# Initialize SQLite once before any tests run
init_sqlite()
@@ -70,10 +71,10 @@ def seed_baseline_data():
# Add the first order (IMPORTED) with items
await sqlite_service.upsert_order(
"RUN001", "ORD001", "2025-01-15", "Test Client", "IMPORTED",
"RUN001", "ORD001", "2025-01-15", "Test Client", OrderStatus.IMPORTED.value,
id_comanda=100, id_partener=200, items_count=2
)
await sqlite_service.add_sync_run_order("RUN001", "ORD001", "IMPORTED")
await sqlite_service.add_sync_run_order("RUN001", "ORD001", OrderStatus.IMPORTED.value)
items = [
{
@@ -103,15 +104,15 @@ def seed_baseline_data():
# Add more orders for filter tests
await sqlite_service.upsert_order(
"RUN001", "ORD002", "2025-01-16", "Client 2", "SKIPPED",
"RUN001", "ORD002", "2025-01-16", "Client 2", OrderStatus.SKIPPED.value,
missing_skus=["SKU99"], items_count=1
)
await sqlite_service.add_sync_run_order("RUN001", "ORD002", "SKIPPED")
await sqlite_service.add_sync_run_order("RUN001", "ORD002", OrderStatus.SKIPPED.value)
await sqlite_service.upsert_order(
"RUN001", "ORD003", "2025-01-17", "Client 3", "ERROR",
"RUN001", "ORD003", "2025-01-17", "Client 3", OrderStatus.ERROR.value,
error_message="Test error", items_count=3
)
await sqlite_service.add_sync_run_order("RUN001", "ORD003", "ERROR")
await sqlite_service.add_sync_run_order("RUN001", "ORD003", OrderStatus.ERROR.value)
asyncio.run(_seed())
yield
@@ -212,7 +213,7 @@ async def test_get_order_detail_not_found():
async def test_get_order_detail_status():
"""Seeded ORD001 should have IMPORTED status."""
detail = await sqlite_service.get_order_detail("ORD001")
assert detail["order"]["status"] == "IMPORTED"
assert detail["order"]["status"] == OrderStatus.IMPORTED.value
# ---------------------------------------------------------------------------
@@ -232,7 +233,7 @@ async def test_get_run_orders_filtered_all():
@pytest.mark.asyncio
async def test_get_run_orders_filtered_imported():
"""Filter IMPORTED should return only ORD001."""
result = await sqlite_service.get_run_orders_filtered("RUN001", "IMPORTED", 1, 50)
result = await sqlite_service.get_run_orders_filtered("RUN001", OrderStatus.IMPORTED.value, 1, 50)
assert result["total"] == 1
assert result["orders"][0]["order_number"] == "ORD001"
@@ -240,7 +241,7 @@ async def test_get_run_orders_filtered_imported():
@pytest.mark.asyncio
async def test_get_run_orders_filtered_skipped():
"""Filter SKIPPED should return only ORD002."""
result = await sqlite_service.get_run_orders_filtered("RUN001", "SKIPPED", 1, 50)
result = await sqlite_service.get_run_orders_filtered("RUN001", OrderStatus.SKIPPED.value, 1, 50)
assert result["total"] == 1
assert result["orders"][0]["order_number"] == "ORD002"
@@ -248,7 +249,7 @@ async def test_get_run_orders_filtered_skipped():
@pytest.mark.asyncio
async def test_get_run_orders_filtered_error():
"""Filter ERROR should return only ORD003."""
result = await sqlite_service.get_run_orders_filtered("RUN001", "ERROR", 1, 50)
result = await sqlite_service.get_run_orders_filtered("RUN001", OrderStatus.ERROR.value, 1, 50)
assert result["total"] == 1
assert result["orders"][0]["order_number"] == "ORD003"
@@ -360,10 +361,10 @@ def test_api_sync_run_orders(client):
def test_api_sync_run_orders_filtered(client):
"""R1: Filtering by status=IMPORTED returns only IMPORTED orders."""
resp = client.get("/api/sync/run/RUN001/orders?status=IMPORTED")
resp = client.get(f"/api/sync/run/RUN001/orders?status={OrderStatus.IMPORTED.value}")
assert resp.status_code == 200
data = resp.json()
assert all(o["status"] == "IMPORTED" for o in data["orders"])
assert all(o["status"] == OrderStatus.IMPORTED.value for o in data["orders"])
def test_api_sync_run_orders_pagination_fields(client):