Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KindaMAD-hav committed Jan 27, 2025
1 parent bb08e87 commit 7025ca4
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions web_app/tests/test_create_referal_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,18 @@ def client():
with TestClient(app) as client:
yield client


@pytest.mark.asyncio
async def test_create_referal_link_success(client):
"""Test successful referral link creation with a valid wallet ID."""
with patch("web_app.db.database.get_database") as mock_get_db: # Changed here
mock_db = MagicMock()
mock_get_db.return_value = mock_db
mock_user = MagicMock(spec=User)
mock_user.wallet_id = "wallet123"
mock_db.query().filter().first.return_value = mock_user
response = client.get("/api/create_referal_link?wallet_id=wallet123")
assert response.status_code == 200
data = response.json()
assert data["wallet_id"] == "wallet123"
assert len(data["referral_code"]) == 16


@pytest.mark.asyncio
async def test_create_referal_link_missing_wallet_id(client):
"""Test error when wallet ID is missing in the request."""
response = client.get("/api/create_referal_link")
assert response.status_code == 422
data = response.json()
assert data["detail"][0]["msg"] == "Field required" # Updated here

assert data["detail"][0]["msg"] == "Field required"

@pytest.mark.asyncio
async def test_create_referal_link_user_not_found(client):
"""Test error when the user is not found in the database."""
with patch("web_app.db.database.get_database") as mock_get_db: # Changed here
with patch("web_app.db.database.get_database") as mock_get_db:
mock_db = MagicMock()
mock_get_db.return_value = mock_db
mock_db.query().filter().first.return_value = None
Expand Down

0 comments on commit 7025ca4

Please sign in to comment.