Add validation to prevent booking two trades on the same day
This commit is contained in:
parent
8948e3533f
commit
04192799ab
2 changed files with 59 additions and 0 deletions
|
|
@ -260,6 +260,43 @@ class TestCreateExchange:
|
|||
assert response.status_code == 409
|
||||
assert "already been booked" in response.json()["detail"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_cannot_book_two_trades_same_day(
|
||||
self, client_factory, regular_user, admin_user
|
||||
):
|
||||
"""Cannot book two trades on the same day."""
|
||||
target_date = await setup_availability_and_price(client_factory, admin_user)
|
||||
|
||||
with mock_price_fetcher(20000.0):
|
||||
# First trade
|
||||
async with client_factory.create(cookies=regular_user["cookies"]) as client:
|
||||
response = await client.post(
|
||||
"/api/exchange",
|
||||
json={
|
||||
"slot_start": f"{target_date}T09:00:00Z",
|
||||
"direction": "buy",
|
||||
"bitcoin_transfer_method": "onchain",
|
||||
"eur_amount": 10000,
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
# Try to book another trade on the same day
|
||||
async with client_factory.create(cookies=regular_user["cookies"]) as client:
|
||||
response = await client.post(
|
||||
"/api/exchange",
|
||||
json={
|
||||
"slot_start": f"{target_date}T10:00:00Z",
|
||||
"direction": "sell",
|
||||
"bitcoin_transfer_method": "lightning",
|
||||
"eur_amount": 20000,
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
assert "already have a trade booked" in response.json()["detail"]
|
||||
assert "Trade ID:" in response.json()["detail"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_invalid_direction_rejected(
|
||||
self, client_factory, regular_user, admin_user
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue