DFiP_Budget_planing/api/tests/unit/test_auth_service.py
2026-05-05 18:07:16 +03:00

33 lines
819 B
Python

from unittest.mock import AsyncMock, MagicMock
import pytest
from src.services.auth_service import AuthService
@pytest.mark.asyncio
async def test_authenticate_user_returns_token(monkeypatch):
db = AsyncMock()
service = AuthService(db)
service.user_repo = MagicMock()
service.user_repo.authenticate = AsyncMock(
return_value=MagicMock(username="admin", email="admin@example.com")
)
token = await service.authenticate_user("admin", "admin")
assert token is not None
assert token.access_token
assert token.refresh_token
assert token.token_type == "bearer"
@pytest.mark.asyncio
async def test_refresh_token_returns_none_for_invalid():
db = AsyncMock()
service = AuthService(db)
token = await service.refresh_token("bad-token")
assert token is None