import pytest
from unittest.mock import MagicMock

def test_register_duplicate_email(client, db_mock):
    # Setup mock return value
    db_mock.execute_query.return_value = [{"id": 1}]
    
    response = client.post(
        "/auth/register",
        json={
            "email": "test@example.com",
            "password": "password123",
            "first_name": "Test",
            "last_name": "User"
        }
    )
    
    assert response.status_code == 400
    assert "email_already_registered" in response.json()["detail"] or "already registered" in response.json()["detail"].lower()

import auth_utils

def test_login_success(client, db_mock):
    # Mock user entry
    db_mock.execute_query.return_value = [{
        "id": 1,
        "email": "test@example.com",
        "password_hash": auth_utils.get_password_hash("password123"),
        "role": "user"
    }]
    
    response = client.post(
        "/auth/login",
        json={
            "email": "test@example.com",
            "password": "password123"
        }
    )
    
    assert response.status_code == 200
    assert "access_token" in response.json()
    assert response.json()["token_type"] == "bearer"

def test_get_me_unauthorized(client):
    response = client.get("/auth/me")
    assert response.status_code == 401
