import pytest
import auth_utils

def test_admin_audit_logs_unauthorized(client):
    response = client.get("/admin/audit-logs")
    assert response.status_code == 401

def test_admin_get_audit_logs_success(client, db_mock):
    token = auth_utils.create_access_token({"id": 1, "role": "admin", "email": "admin@radionica3d.me"})
    
    # Mock data for logs and total count
    db_mock.execute_query.side_effect = [
        [{"id": 1, "action": "login", "user_email": "admin@radionica3d.me"}],
        [{"total": 1}]
    ]
    
    response = client.get("/admin/audit-logs", headers={"Authorization": f"Bearer {token}"})
    
    assert response.status_code == 200
    assert "logs" in response.json()
    assert response.json()["total"] == 1

def test_admin_reviews_list_success(client, db_mock):
    token = auth_utils.create_access_token({"id": 1, "role": "admin", "email": "admin@radionica3d.me"})
    
    # Mock data for reviews and total count
    db_mock.execute_query.side_effect = [
        [{"id": 123, "review_text": "Good", "rating": 5, "review_approved": False}],
        [{"total": 1}]
    ]
    
    response = client.get("/admin/reviews", headers={"Authorization": f"Bearer {token}"})
    
    assert response.status_code == 200
    assert "reviews" in response.json()
    assert len(response.json()["reviews"]) == 1
