from app.dashboard.backend.mission_service import MissionService def test_stale_ringing_timeout_uses_last_update(monkeypatch): calls = [] monkeypatch.setattr(MissionService, "_table_exists", staticmethod(lambda _table: True)) monkeypatch.setattr(MissionService, "get_ring_timeout_seconds", staticmethod(lambda: 120)) monkeypatch.setattr( "app.dashboard.backend.mission_service.execute_query", lambda query, params=(): calls.append((query, params)), ) MissionService.expire_stale_ringing_calls() assert len(calls) == 1 query, params = calls[0] assert "updated_at < (NOW() - make_interval(secs => %s))" in query assert "started_at < (NOW() - make_interval(secs => %s))" not in query assert params == (120,) def test_repeated_ringing_event_refreshes_call_start_time(): from pathlib import Path source = Path("app/dashboard/backend/mission_router.py").read_text(encoding="utf-8") assert "started_at = EXCLUDED.started_at" in source assert "started_at = LEAST(mission_call_state.started_at, EXCLUDED.started_at)" not in source def test_yealink_incoming_url_uses_local_value_for_recipient_and_queue(): from pathlib import Path source = Path("app/settings/frontend/settings.html").read_text(encoding="utf-8") assert "queue_name=$local&recipient_extension=$local" in source def test_case_location_list_is_customer_scoped_and_prioritizes_customer_address(): from pathlib import Path template = Path("app/modules/sag/templates/detail_v4.html").read_text(encoding="utf-8") assert "/api/v1/locations/by-customer/${encodeURIComponent(caseAddCustomerId)}" in template assert "visible = customerLocations.filter" in template assert "customer.address" in template assert "normalizeAddress" in template def test_active_calls_are_not_expired_during_state_read(): import inspect source = inspect.getsource(MissionService.get_active_calls) assert "expire_stale_ringing_calls" not in source def test_active_call_read_failure_preserves_client_state(): from pathlib import Path source = Path("app/dashboard/frontend/mission_control_v2.html").read_text(encoding="utf-8") assert '"active_calls", MissionService' not in source