"""
Tests for user functionality
"""
import pytest
from fastapi.testclient import TestClient
from merchants_of_hope.models import User, UserRole


def test_create_user(client, db_session):
    """Test creating a user"""
    user_data = {
        "email": "test@example.com",
        "username": "testuser",
        "password": "testpassword",
        "role": "job_seeker"
    }
    response = client.post("/api/v1/users/", json=user_data)
    assert response.status_code == 200
    data = response.json()
    assert data["email"] == user_data["email"]
    assert data["username"] == user_data["username"]
    assert data["role"] == user_data["role"]


def test_get_user(client, db_session):
    """Test getting a user"""
    # First create a user
    user_data = {
        "email": "test2@example.com",
        "username": "testuser2",
        "password": "testpassword",
        "role": "job_provider"
    }
    create_response = client.post("/api/v1/users/", json=user_data)
    assert create_response.status_code == 200
    created_user = create_response.json()
    
    # Then get the user
    response = client.get(f"/api/v1/users/{created_user['id']}")
    assert response.status_code == 200
    data = response.json()
    assert data["email"] == user_data["email"]