Spaces:
Running
Running
AuthorBot
Unify token tracking, smart links, and personality settings across admin and chat.
a825fee | """Suite B — Buy Book button & response formatter (P0).""" | |
| import pytest | |
| from app.services.formatter import ResponseFormatter | |
| def formatter(): | |
| return ResponseFormatter() | |
| 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" | |
| 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"] == [] | |
| 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"} | |
| 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 | |
| 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"] | |