feat: sensical user invitation
Some checks failed
ci / lint_and_test (push) Failing after 8s

Users can now be invited to an org by email.

"Email" for now is "print to stdout"

Resolves #12
This commit is contained in:
Chris Milne 2026-06-09 12:22:36 +01:00
parent 1012947b67
commit 62c43ce883
5 changed files with 173 additions and 5 deletions

View file

@ -52,3 +52,53 @@ async def test_delete_user_success(default_client: AsyncClient):
resp = await default_client.delete("/user/?user_id=1")
assert resp.status_code == 204
@pytest.mark.anyio
async def test_post_user_invitation_success(default_client: AsyncClient):
body = {"user_email": "admin@test.com", "organisation_id": 1}
resp = await default_client.post("/user/invitation", json=body)
assert resp.status_code == 200
assert resp.json() == "Invitation sent"
@pytest.mark.parametrize(
"body, expected_status",
[
({"organisation_id": 42, "user_email": "admin@test.com"}, 404),
({"organisation_id": "Test Org", "user_email": "admin@test.com"}, 422),
({"organisation_id": "", "user_email": "admin@test.com"}, 422),
({}, 422),
({"user_email": 42}, 422),
({"organisation_id": 1, "user_email": "Test User"}, 422),
],
)
@pytest.mark.anyio
async def test_post_user_invitation_status_checks(
default_client: AsyncClient, body, expected_status
):
resp = await default_client.post("/user/invitation", json=body)
assert resp.status_code == expected_status
@pytest.mark.parametrize(
"body, expected_status",
[
({"jwt": "invalid"}, 401),
({"jwt": ""}, 401),
({"jwt": None}, 422),
({"jwt": 42}, 422),
],
)
@pytest.mark.anyio
async def test_post_user_invitation_accept_status_checks(
default_client: AsyncClient, body, expected_status
):
resp = await default_client.post("/user/invitation/accept", json=body)
assert resp.status_code == expected_status
if resp.status_code == 401:
assert resp.json()["detail"] == "Invalid JWS"