aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/tests/test_invitation_ui.py
blob: 99538e9d82eb4e6e10c7ff7c676bd5e950745a30 (plain) (blame)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
The two answers a person now gives, in the real application, in both engines.

An invitee answers an invitation on the home page (harness/invitation_probe.py);
a group owner answers a node that asked to host the group, and sees who was
invited and has not answered (harness/group_hosts_probe.py). The hub side is
`test_invitations_and_hosts.py`; this is where it meets the interface.
"""

import json
import shutil
import subprocess
import sys
from pathlib import Path

import pytest

HARNESS = Path(__file__).parent / "harness"
BINARY = {"chrome": "google-chrome", "firefox": "firefox"}


def _run(probe: str, engine: str):
    if shutil.which(BINARY[engine]) is None:
        pytest.skip(f"{engine} is not available")
    proc = subprocess.run([sys.executable, str(HARNESS / probe), "--engine", engine],
                          capture_output=True, text=True, timeout=240)
    assert proc.returncode == 0, f"probe failed: {proc.stdout}{proc.stderr}"
    return json.loads(proc.stdout)


@pytest.fixture(scope="module", params=["chrome", "firefox"])
def invitation(request):
    return {c["case"]: c for c in _run("invitation_probe.py", request.param)}


@pytest.fixture(scope="module", params=["chrome", "firefox"])
def hosts(request):
    return _run("group_hosts_probe.py", request.param)


def test_an_invitation_is_listed_with_its_two_answers(invitation):
    for c in invitation.values():
        assert "error" not in c, c["error"]
        assert c["listed"] and c["buttons"] == 2


def test_accepting_joins_and_shows_the_group(invitation):
    c = invitation["accept"]
    assert c["answer_call"] == [
        "POST /v1/groups/0f8fad5b-d9cb-469f-a165-70867728950e/invitation/accept"]
    assert c["group_card"] and not c["invitation_still_shown"]


def test_declining_leaves_no_group(invitation):
    c = invitation["decline"]
    assert c["answer_call"][0].endswith("/invitation/decline")
    assert not c["group_card"] and not c["invitation_still_shown"]


def test_the_owner_sees_the_invited_and_approves_a_host(hosts):
    assert "error" not in hosts, hosts.get("error")
    assert hosts["invited_row"]
    assert hosts["host_rows"] == 2
    assert hosts["buttons_on_request"] == 2      # approve and refuse
    assert hosts["buttons_on_approved"] == 1     # refuse only
    assert hosts["decision"] == ["POST /v1/groups/g1/hosts/n-asking"]