import pytest

def test_expense_item_get_found(client, admin_tokens, auth_headers):
    response = client.get(
        "/api/v1/expense-item/1",
        headers=auth_headers(admin_tokens),
    )
    assert response.status_code == 200
    result = response.json()
    assert result["success"] is True
    assert result["result"]["id"] == 1


def test_expense_item_get_not_found(client, admin_tokens, auth_headers):
    response = client.get(
        "/api/v1/expense-item/999999",
        headers=auth_headers(admin_tokens),
    )
    assert response.status_code == 404


def test_expense_item_get_unauthorized(client):
    response = client.get("/api/v1/expense-item/1")
    assert response.status_code == 403


def test_expense_item_get_executor(client, isp_tokens, auth_headers):
    response = client.get(
        "/api/v1/expense-item/1",
        headers=auth_headers(isp_tokens),
    )
    assert response.status_code == 403


def test_expense_item_list(client, isp_tokens, auth_headers):
    response = client.get(
        "/api/v1/expense-item/",
        headers=auth_headers(isp_tokens),
    )
    assert response.status_code == 200
    result = response.json()
    assert result["success"] is True
    assert isinstance(result["result"], list)
    assert len(result["result"]) != 0


def test_expense_item_list_r_start(client, isp_tokens, auth_headers):
    response = client.get(
        "/api/v1/expense-item/?r_start=true",
        headers=auth_headers(isp_tokens),
    )
    assert response.status_code == 200
    result = response.json()
    assert result["success"] is True
    assert isinstance(result["result"], list)
    assert len(result["result"]) != 0
    assert all([el["item_id"].startswith("R") for el in result["result"]])