`CreateTicket` no longer rejects `user_id` together with `name`/`email`
(the exclusion was a fork-only dispatch convenience from dfabcb8; nothing
needed it). `crud.create_ticket` stops blanking name/email when a user_id
is present, so logged-in webapp buyers can have their ticket emailed —
until now `_send_ticket_notification` short-circuited on the empty
address for every app purchase.
New optional `frontend_url` (absolute http(s) root, no query/fragment/..,
trailing slash stripped) lets a buyer-side client name the app the buyer
should be returned to and linked into from the ticket email; the origin
allow-list lives in views_api.
Also folds in the pending black reflow of migrations_fork.py.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYwoAkZZmXMMmaBp4WGUBo
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
from unittest.mock import AsyncMock
|
|
|
|
import pytest
|
|
|
|
from .. import crud
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_ticket_keeps_email_alongside_user_id(monkeypatch):
|
|
inserted = {}
|
|
|
|
async def fake_insert(table, model):
|
|
inserted["table"] = table
|
|
inserted["model"] = model
|
|
|
|
monkeypatch.setattr(crud.db, "insert", AsyncMock(side_effect=fake_insert))
|
|
|
|
ticket = await crud.create_ticket(
|
|
payment_hash="hash",
|
|
wallet="w",
|
|
event="e",
|
|
name="Ada",
|
|
email="ada@example.com",
|
|
user_id="u1",
|
|
ticket_id="t1",
|
|
)
|
|
|
|
assert inserted["table"] == "events.ticket"
|
|
assert inserted["model"].user_id == "u1"
|
|
assert inserted["model"].email == "ada@example.com"
|
|
assert inserted["model"].name == "Ada"
|
|
assert ticket.email == "ada@example.com"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_ticket_stores_empty_string_sentinels(monkeypatch):
|
|
inserted = {}
|
|
|
|
async def fake_insert(table, model):
|
|
inserted["model"] = model
|
|
|
|
monkeypatch.setattr(crud.db, "insert", AsyncMock(side_effect=fake_insert))
|
|
|
|
await crud.create_ticket(
|
|
payment_hash="hash", wallet="w", event="e", user_id="u1", ticket_id="t2"
|
|
)
|
|
assert inserted["model"].email == ""
|
|
assert inserted["model"].name == ""
|