| from tests.conftest import auth | |
| def test_register_and_me(client): | |
| r = client.post( | |
| "/auth/register", | |
| json={"name": "A", "email": "a@example.com", "password": "password123", "zip": "20001"}, | |
| ) | |
| assert r.status_code == 201 | |
| token = r.json()["access_token"] | |
| me = client.get("/auth/me", headers=auth(token)) | |
| assert me.status_code == 200 | |
| assert me.json()["email"] == "a@example.com" | |
| assert me.json()["role"] == "owner" | |
| def test_duplicate_email_rejected(client): | |
| body = {"name": "A", "email": "dup@example.com", "password": "password123", "zip": "20001"} | |
| assert client.post("/auth/register", json=body).status_code == 201 | |
| assert client.post("/auth/register", json=body).status_code == 409 | |
| def test_login_wrong_password(client): | |
| client.post( | |
| "/auth/register", | |
| json={"name": "A", "email": "b@example.com", "password": "password123", "zip": "20001"}, | |
| ) | |
| r = client.post("/auth/login", json={"email": "b@example.com", "password": "wrong"}) | |
| assert r.status_code == 401 | |
| def test_me_requires_auth(client): | |
| assert client.get("/auth/me").status_code == 401 | |
| def test_error_envelope_shape(client): | |
| r = client.get("/auth/me") | |
| assert "error" in r.json() | |
| assert r.json()["error"]["code"] == 401 | |