Files
card-game/backend/tests/test_chests.py

35 lines
1.2 KiB
Python

import pytest
from app import models
def test_catalog_chests(client, db):
# Seed a chest for testing
chest = models.Chest(id="test-chest-1", name="Test Chest", cost_gold=100, cards_per_open=3)
db.add(chest)
db.commit()
response = client.get("/catalog/chests")
assert response.status_code == 200
chests = response.json()
assert len(chests) >= 1
def test_open_chest_insufficient_gold(client, db, auth_headers):
# Create a chest but user has no gold (wallet starts at 0 in test)
chest = models.Chest(id="test-chest-2", name="Expensive Chest", cost_gold=10000, cards_per_open=3)
db.add(chest)
db.commit()
response = client.post(f"/chests/{chest.id}/open", headers=auth_headers)
assert response.status_code in [400, 403] # Insufficient funds
def test_open_chest_not_found(client, auth_headers):
response = client.post("/chests/nonexistent-chest-id/open", headers=auth_headers)
assert response.status_code == 404
def test_open_chest_unauthenticated(client, db):
chest = models.Chest(id="test-chest-3", name="Test Chest", cost_gold=100, cards_per_open=3)
db.add(chest)
db.commit()
response = client.post(f"/chests/{chest.id}/open")
assert response.status_code == 401