| """Admin master switch: turning a client's chatbot off hides the widget and |
| refuses chats — without deleting the account — and only for THAT tenant.""" |
|
|
| from __future__ import annotations |
|
|
| AUTH = {"Authorization": "Bearer test-admin-token"} |
|
|
|
|
| async def test_disable_chatbot_hides_widget_and_refuses_chat(app_client): |
| _app, client = app_client |
| await client.post("/admin/tenants", headers=AUTH, json={"slug": "morosa"}) |
| await client.post("/admin/tenants", headers=AUTH, json={"slug": "alcorriente"}) |
|
|
| |
| wc = (await client.get("/widget-config?t=morosa")).json() |
| assert wc["enabled"] is True |
|
|
| |
| r = await client.put("/admin/tenants/morosa", headers=AUTH, json={"chatbot_enabled": False}) |
| assert r.status_code == 200 and r.json()["chatbot_enabled"] is False |
|
|
| |
| wc2 = (await client.get("/widget-config?t=morosa")).json() |
| assert wc2["enabled"] is False |
| chat = await client.post("/chat?t=morosa", json={"message": "hola"}) |
| assert chat.status_code == 403 |
|
|
| |
| wc3 = (await client.get("/widget-config?t=alcorriente")).json() |
| assert wc3["enabled"] is True |
|
|
| |
| rows = (await client.get("/admin/tenants", headers=AUTH)).json() |
| assert any(t["slug"] == "morosa" for t in rows) |
| await client.put("/admin/tenants/morosa", headers=AUTH, json={"chatbot_enabled": True}) |
| wc4 = (await client.get("/widget-config?t=morosa")).json() |
| assert wc4["enabled"] is True |
|
|