aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/tests/test_groups_self_service.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/tests/test_groups_self_service.py')
-rw-r--r--packages/meshbay-hub/tests/test_groups_self_service.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/packages/meshbay-hub/tests/test_groups_self_service.py b/packages/meshbay-hub/tests/test_groups_self_service.py
index 3202658..def663d 100644
--- a/packages/meshbay-hub/tests/test_groups_self_service.py
+++ b/packages/meshbay-hub/tests/test_groups_self_service.py
@@ -175,3 +175,48 @@ async def test_join_triggers_notification(client):
r = await client.get(f"/v1/groups/{gid}/members",
headers={"Authorization": f"Bearer {alice_token}"})
assert len(r.json()["members"]) == 2
+
+
+# ── Listed and open are one question ────────────────────────────────────────
+
+@pytest.mark.asyncio
+async def test_a_private_group_cannot_be_open_to_everyone(client):
+ """
+ A group anyone may join that nobody can find is a listing with the listing
+ removed: it is absent from the directory, and joining goes through the node
+ rather than a link, so nothing can reach it. It was accepted until now, and
+ the create form offered it.
+ """
+ await _register(client, "pat", email="pat@x.com")
+ token = await _login(client, "pat")
+ resp = await client.post("/v1/groups", json={
+ "name": "nowhere", "visibility": "private", "join_policy": "open",
+ }, headers={"Authorization": f"Bearer {token}"})
+
+ assert resp.status_code == 422
+ assert "invite-only" in resp.json()["detail"]
+
+
+@pytest.mark.asyncio
+async def test_a_public_group_cannot_be_invite_only(client):
+ """The other half, which was already refused — kept so that removing one
+ check does not quietly remove both."""
+ await _register(client, "sam", email="sam@x.com")
+ token = await _login(client, "sam")
+ resp = await client.post("/v1/groups", json={
+ "name": "deadend", "visibility": "public", "join_policy": "invite",
+ }, headers={"Authorization": f"Bearer {token}"})
+
+ assert resp.status_code == 422
+
+
+@pytest.mark.asyncio
+async def test_the_two_combinations_that_mean_something_are_accepted(client):
+ await _register(client, "robin", email="robin@x.com")
+ token = await _login(client, "robin")
+ for name, visibility, policy in (("closed", "private", "invite"),
+ ("open-house", "public", "open")):
+ resp = await client.post("/v1/groups", json={
+ "name": name, "visibility": visibility, "join_policy": policy,
+ }, headers={"Authorization": f"Bearer {token}"})
+ assert resp.status_code == 201, f"{visibility}+{policy}: {resp.text}"