"""CH-AUTH-001 — login → refresh → new access token."""

from __future__ import annotations

from unittest.mock import MagicMock

import pytest

from server.api.dependencies import get_auth_service

pytestmark = pytest.mark.chain


@pytest.mark.asyncio
async def test_login_refresh_chain(db_session, test_admin, mock_request):
    mock_request.state.db = db_session
    service = await get_auth_service(mock_request)

    login_result = await service.login(
        username=test_admin["admin"].username,
        password="test123",
        ip_address="127.0.0.1",
    )
    assert login_result["success"] is True
    assert login_result.get("access_token")
    refresh_raw = login_result.get("refresh_token")
    assert refresh_raw

    refresh_result = await service.refresh_token(refresh_raw, ip_address="127.0.0.1")
    assert refresh_result["success"] is True
    assert refresh_result.get("access_token")
