aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/tests/test_api_peers.py
blob: 420ccba944e818dadebb35cb64286aada34e4f9c (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
"""
The Node page's Peers tab: one row per live session, from the loopback API.

`_get_remote_ip` moved out of `webrtc_server.py` and the endpoint's import,
inside the function, went on naming the old place. Nothing imports a function
body until it runs, so the tab answered 500 and nothing else noticed.
"""

from types import SimpleNamespace

from fastapi.testclient import TestClient
from meshbay_node.ui.app import create_ui_app


def test_the_peers_tab_lists_a_live_session():
    session = SimpleNamespace(
        _user_id="u-bob", _group_id="g" * 32, _username="bob",
        # No address learnt at the handshake: the endpoint asks the ICE
        # transport, which is the line that broke.
        _remote_ip="",
        _pc=SimpleNamespace(sctp=None, connectionState="connected"))
    state = {"status": "running",
             "webrtc": SimpleNamespace(_sessions={"p1": session})}

    resp = TestClient(create_ui_app(state)).get("/api/peers")

    assert resp.status_code == 200, resp.text
    assert resp.json() == {"peers": [{
        "peer_id": "p1", "user_id": "u-bob", "username": "bob",
        "group_id": "g" * 32, "group_name": "", "remote_ip": "",
        "state": "connected"}]}