fix: Prevent user from cancelling trades after slot time has passed
Users can no longer cancel trades once the slot time has passed. Added test to verify this behavior.
This commit is contained in:
parent
3a22534c04
commit
29b0438416
2 changed files with 40 additions and 1 deletions
|
|
@ -543,6 +543,39 @@ class TestCancelTrade:
|
|||
assert response.status_code == 400
|
||||
assert "cancelled_by_user" in response.json()["detail"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_cannot_cancel_past_trade(
|
||||
self, client_factory, regular_user, admin_user
|
||||
):
|
||||
"""Cannot cancel a trade after the slot time has passed."""
|
||||
# Create a past trade directly in DB
|
||||
async with client_factory.get_db_session() as db:
|
||||
await create_price_in_db(db, price=20000.0)
|
||||
past_time = datetime.now(UTC) - timedelta(hours=1)
|
||||
exchange = Exchange(
|
||||
user_id=regular_user["user"]["id"],
|
||||
slot_start=past_time,
|
||||
slot_end=past_time + timedelta(minutes=15),
|
||||
direction=TradeDirection.BUY,
|
||||
eur_amount=10000,
|
||||
sats_amount=500000,
|
||||
market_price_eur=20000.0,
|
||||
agreed_price_eur=21000.0,
|
||||
premium_percentage=5,
|
||||
status=ExchangeStatus.BOOKED,
|
||||
)
|
||||
db.add(exchange)
|
||||
await db.commit()
|
||||
await db.refresh(exchange)
|
||||
trade_id = exchange.id
|
||||
|
||||
# User tries to cancel
|
||||
async with client_factory.create(cookies=regular_user["cookies"]) as client:
|
||||
response = await client.post(f"/api/trades/{trade_id}/cancel")
|
||||
|
||||
assert response.status_code == 400
|
||||
assert "already passed" in response.json()["detail"]
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Admin Trades Tests
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue