File size: 1,633 Bytes
d9abd7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""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"})

    # default: enabled
    wc = (await client.get("/widget-config?t=morosa")).json()
    assert wc["enabled"] is True

    # admin switches it off
    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

    # widget self-hides and the chat refuses without burning an LLM call
    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

    # the OTHER tenant is untouched (isolation)
    wc3 = (await client.get("/widget-config?t=alcorriente")).json()
    assert wc3["enabled"] is True

    # account/data still there; re-enable restores service
    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