mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-12-17 08:00:13 +01:00
feat(web): launch commander browser with deck builder CTA
This commit is contained in:
parent
6e9ba244c9
commit
8e57588f40
27 changed files with 1960 additions and 45 deletions
56
code/tests/test_commander_telemetry.py
Normal file
56
code/tests/test_commander_telemetry.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from code.web.app import app # type: ignore
|
||||
from code.web.services import telemetry
|
||||
from code.web.services.commander_catalog_loader import clear_commander_catalog_cache
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(monkeypatch: pytest.MonkeyPatch):
|
||||
csv_dir = Path("csv_files/testdata").resolve()
|
||||
monkeypatch.setenv("CSV_FILES_DIR", str(csv_dir))
|
||||
clear_commander_catalog_cache()
|
||||
with TestClient(app) as test_client:
|
||||
yield test_client
|
||||
clear_commander_catalog_cache()
|
||||
|
||||
|
||||
def test_commander_page_logs_event(client: TestClient, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
events: list[dict] = []
|
||||
|
||||
def capture(_logger, payload):
|
||||
events.append(payload)
|
||||
|
||||
monkeypatch.setattr(telemetry, "_emit", capture)
|
||||
|
||||
response = client.get("/commanders", params={"q": "atraxa"})
|
||||
assert response.status_code == 200
|
||||
assert events, "expected telemetry events to be emitted"
|
||||
event = events[-1]
|
||||
assert event["event"] == "commander_browser.page_view"
|
||||
assert event["page"] == 1
|
||||
assert event["query"]["q"] == "atraxa"
|
||||
assert event["is_htmx"] is False
|
||||
|
||||
|
||||
def test_commander_create_deck_logs_event(client: TestClient, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
events: list[dict] = []
|
||||
|
||||
def capture(_logger, payload):
|
||||
events.append(payload)
|
||||
|
||||
monkeypatch.setattr(telemetry, "_emit", capture)
|
||||
|
||||
response = client.get("/build", params={"commander": "Atraxa", "return": "/commanders"})
|
||||
assert response.status_code == 200
|
||||
assert events, "expected telemetry events to be emitted"
|
||||
event = events[-1]
|
||||
assert event["event"] == "commander_browser.create_deck"
|
||||
assert event["commander"] == "Atraxa"
|
||||
assert event["has_return"] is True
|
||||
assert event["return_url"] == "/commanders"
|
||||
Loading…
Add table
Add a link
Reference in a new issue