import pytest
from httpx import AsyncClient
from app.main import app

@pytest.mark.asyncio
async def test_create_search_request():
    async with AsyncClient(app=app, base_url="http://test") as ac:
        response = await ac.post(
            "/api/v1/search/requests",
            json={
                "keywords": ["python", "fastapi"],
                "platforms": ["google", "youtube"],
                "search_type": "manual"
            }
        )
    assert response.status_code == 201
    data = response.json()
    assert "id" in data
    assert data["keywords"] == ["python", "fastapi"]
    assert data["platforms"] == ["google", "youtube"]

@pytest.mark.asyncio
async def test_get_search_request():
    # First create a search request
    async with AsyncClient(app=app, base_url="http://test") as ac:
        create_response = await ac.post(
            "/api/v1/search/requests",
            json={
                "keywords": ["test"],
                "platforms": ["google"],
                "search_type": "manual"
            }
        )
        request_id = create_response.json()["id"]
        
        # Then get it
        response = await ac.get(f"/api/v1/search/requests/{request_id}")
    
    assert response.status_code == 200
    data = response.json()
    assert data["id"] == request_id
