from tests.helpers import latest_token


def test_verify_email_rejects_invalid_token(client):
    client.post("/api/v1/auth/register", json={"email": "bad@example.com", "password": "Valid123"})
    response = client.post("/api/v1/auth/verify-email", json={"token": "invalid-token"})
    assert response.status_code == 400
    assert response.json()["detail"] == "INVALID_TOKEN"


def test_resend_verification_sends_new_token(client):
    client.post("/api/v1/auth/register", json={"email": "resend@example.com", "password": "Valid123"})
    first_token = latest_token("resend@example.com", "verify_email")

    client.post("/api/v1/auth/resend-verification", json={"email": "resend@example.com"})
    second_token = latest_token("resend@example.com", "verify_email")
    assert first_token != second_token

    verify = client.post("/api/v1/auth/verify-email", json={"token": second_token})
    assert verify.status_code == 200
