from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]


def test_frontend_loads_current_identity_and_clears_invalid_tokens():
    user_api = (ROOT / "frontend/src/api/user.js").read_text(encoding="utf-8")
    store = (ROOT / "frontend/src/store/modules/user.js").read_text(encoding="utf-8")
    request = (ROOT / "frontend/src/utils/request.js").read_text(encoding="utf-8")

    assert "/system/auth/me" in user_api
    assert "loadCurrentUser" in store
    assert "deleteToken" in request
    assert "redirect" in request


def test_user_management_has_no_registration_route():
    api = (ROOT / "frontend/src/api/users.js").read_text(encoding="utf-8")
    routes = (ROOT / "frontend/src/router/routes.js").read_text(encoding="utf-8")

    assert "/system/users" in api
    assert "register" not in api.lower()
    assert "users:manage" in routes
