test: improve e2e tests and add COMPLETE_EXCHANGE permission tests
- Fix E2E test assertion for buy/sell direction change - Add data-testid to date buttons for reliable e2e selection - Update e2e tests to use data-testid instead of fragile weekday matching - Add tests for regular user cannot complete/no-show trades (COMPLETE_EXCHANGE permission)
This commit is contained in:
parent
ef01a970d5
commit
ca3a08a236
3 changed files with 81 additions and 34 deletions
|
|
@ -769,6 +769,68 @@ class TestAdminCompleteTrade:
|
|||
assert response.status_code == 400
|
||||
assert "not yet started" in response.json()["detail"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_regular_user_cannot_complete_trade(
|
||||
self, client_factory, regular_user, admin_user
|
||||
):
|
||||
"""Regular user cannot complete trades (requires COMPLETE_EXCHANGE permission)."""
|
||||
# Create a past trade in DB
|
||||
async with client_factory.get_db_session() as db:
|
||||
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
|
||||
|
||||
# Regular user tries to complete
|
||||
async with client_factory.create(cookies=regular_user["cookies"]) as client:
|
||||
response = await client.post(f"/api/admin/trades/{trade_id}/complete")
|
||||
|
||||
assert response.status_code == 403
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_regular_user_cannot_mark_no_show(
|
||||
self, client_factory, regular_user, admin_user
|
||||
):
|
||||
"""Regular user cannot mark trades as no-show (requires COMPLETE_EXCHANGE permission)."""
|
||||
# Create a past trade in DB
|
||||
async with client_factory.get_db_session() as db:
|
||||
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
|
||||
|
||||
# Regular user tries to mark as no-show
|
||||
async with client_factory.create(cookies=regular_user["cookies"]) as client:
|
||||
response = await client.post(f"/api/admin/trades/{trade_id}/no-show")
|
||||
|
||||
assert response.status_code == 403
|
||||
|
||||
|
||||
class TestAdminNoShowTrade:
|
||||
"""Test admin marking trades as no-show."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue