from pathlib import Path from app.economy.backend.router import _normalise_billing_method, _settlement_label ROOT = Path(__file__).resolve().parents[1] def test_time_queue_normalises_legacy_settlement_names(): assert _normalise_billing_method("prepaid_card") == "prepaid" assert _normalise_billing_method("fixed_price") == "subscription" assert _normalise_billing_method(None) == "invoice" assert _settlement_label("subscription") == "Abonnement / fast pris" def test_time_queue_has_preview_and_safe_draft_tracking(): router_source = (ROOT / "app/economy/backend/router.py").read_text() template_source = (ROOT / "app/economy/frontend/time_queue.html").read_text() migration_source = (ROOT / "migrations/1018_economy_time_queue_settlement.sql").read_text() assert '"/time-queue/preview-settlement"' in router_source assert '"/time-queue/settle"' in router_source assert "economy_order_draft_id" in router_source assert "preview-settlement" in template_source assert "Forhåndsvisning af afregning" in template_source assert "economy_order_draft_id" in migration_source def test_case_customer_is_authoritative_for_queue_and_settlement(): router_source = (ROOT / "app/economy/backend/router.py").read_text() # A moved/corrected case must not be invoiced to the historic customer # stored on a time entry. assert "COALESCE(s.customer_id, effective_customer.hub_customer_id) AS customer_id" in router_source assert "The case company is authoritative" in router_source