Arag / tests /unit /test_suite_b_formatter.py
AuthorBot
Unify token tracking, smart links, and personality settings across admin and chat.
a825fee
Raw
History Blame Contribute Delete
1.9 kB
"""Suite B — Buy Book button & response formatter (P0)."""
import pytest
from app.services.formatter import ResponseFormatter
@pytest.fixture
def formatter():
return ResponseFormatter()
@pytest.mark.p0
def test_purchase_link_rendered_with_buy_book_label(formatter):
result = formatter.format(
response_text="Great question about the plot.",
purchase_url="https://store.example.com/book",
show_link=True,
)
assert result["has_links"] is True
assert len(result["links"]) == 1
assert result["links"][0]["label"] == "Buy Book"
assert result["links"][0]["type"] == "purchase"
assert result["links"][0]["url"] == "https://store.example.com/book"
@pytest.mark.p0
def test_no_links_when_show_link_false(formatter):
result = formatter.format(
response_text="Just an answer.",
purchase_url="https://store.example.com/book",
show_link=False,
)
assert result["has_links"] is False
assert result["links"] == []
@pytest.mark.p0
def test_max_two_links_purchase_and_preview(formatter):
result = formatter.format(
response_text="Check it out.",
purchase_url="https://store.example.com/buy",
preview_url="https://store.example.com/preview",
show_link=True,
)
assert len(result["links"]) == 2
types = {link["type"] for link in result["links"]}
assert types == {"purchase", "preview"}
@pytest.mark.p0
def test_no_link_when_purchase_url_missing(formatter):
result = formatter.format(
response_text="Answer without URL.",
purchase_url=None,
show_link=True,
)
assert result["has_links"] is False
@pytest.mark.p0
def test_markdown_stripped_from_response(formatter):
result = formatter.format(response_text="This is **bold** text.", show_link=False)
assert "**" not in result["text"]
assert "bold" in result["text"]