test_sponsor_prompt_api.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """Integration tests for /sponsor-prompt routes."""
  2. from __future__ import annotations
  3. import pytest
  4. from httpx import AsyncClient
  5. class TestSponsorPromptAPI:
  6. @pytest.mark.asyncio
  7. @pytest.mark.integration
  8. async def test_check_returns_show_false_for_empty_install(self, async_client: AsyncClient):
  9. response = await async_client.get("/api/v1/sponsor-prompt/check")
  10. assert response.status_code == 200
  11. body = response.json()
  12. assert body["show"] is False
  13. assert body.get("milestone") is None
  14. @pytest.mark.asyncio
  15. @pytest.mark.integration
  16. async def test_dismiss_requires_milestone(self, async_client: AsyncClient):
  17. response = await async_client.post("/api/v1/sponsor-prompt/dismiss", json={})
  18. # Pydantic missing-field → 422.
  19. assert response.status_code == 422
  20. @pytest.mark.asyncio
  21. @pytest.mark.integration
  22. async def test_dismiss_returns_204(self, async_client: AsyncClient):
  23. response = await async_client.post(
  24. "/api/v1/sponsor-prompt/dismiss",
  25. json={"milestone": "version-update"},
  26. )
  27. assert response.status_code == 204
  28. @pytest.mark.asyncio
  29. @pytest.mark.integration
  30. async def test_check_then_dismiss_then_recheck_is_silent(self, async_client: AsyncClient):
  31. """End-to-end: even if no trigger is currently eligible, dismissing
  32. anchors the cooldown, so a subsequent check stays {show: false}."""
  33. first = await async_client.get("/api/v1/sponsor-prompt/check")
  34. assert first.json()["show"] is False
  35. dismiss = await async_client.post(
  36. "/api/v1/sponsor-prompt/dismiss",
  37. json={"milestone": "version-update"},
  38. )
  39. assert dismiss.status_code == 204
  40. second = await async_client.get("/api/v1/sponsor-prompt/check")
  41. assert second.json()["show"] is False