import pytest
from app.tests.conftest import headers
@pytest.mark.asyncio
async def test_request_idempotency_and_cancel(client):
    await client.post("/api/v1/tenant-bundles",headers=headers(),json={"bundle_code":"payment.byo_psp.basic","is_active":True})
    assert (await client.post("/api/v1/payment-requests",headers=headers(),json={"amount_minor":10})).status_code==400
    h={**headers(),"Idempotency-Key":"same"}
    a=(await client.post("/api/v1/payment-requests",headers=h,json={"amount_minor":10})).json()
    b=(await client.post("/api/v1/payment-requests",headers=h,json={"amount_minor":10})).json()
    assert a["id"]==b["id"] and a["status"]=="redirect_issued"
    assert (await client.post(f"/api/v1/payment-requests/{a['id']}/cancel",headers=headers())).json()["status"]=="cancelled"
