Spaces:
Runtime error
Runtime error
| import pytest | |
| def test_wallet_ledger_audit(client): | |
| # Register customer | |
| client.post( | |
| "/api/auth/signup", | |
| json={ | |
| "name": "Audit Customer", | |
| "phone": "9876543209", | |
| "role": "customer", | |
| "city": "Jaipur" | |
| } | |
| ) | |
| # Login customer | |
| login_res = client.post( | |
| "/api/auth/login", | |
| json={ | |
| "phone": "9876543209", | |
| "role": "customer", | |
| "otp": "123456" | |
| } | |
| ) | |
| token = login_res.json()["access_token"] | |
| # Retrieve initial transactions | |
| res_initial = client.get( | |
| "/api/wallet/transactions", | |
| headers={"Authorization": f"Bearer {token}"} | |
| ) | |
| assert res_initial.status_code == 200 | |
| assert len(res_initial.json()) == 0 | |
| # Execute a wallet topup | |
| topup_res = client.post( | |
| "/api/wallet/topup", | |
| json={"amount": 1500}, | |
| headers={"Authorization": f"Bearer {token}"} | |
| ) | |
| assert topup_res.status_code == 200 | |
| assert topup_res.json()["wallet_balance"] == 9700 | |
| # Verify transactions ledger log | |
| res_after = client.get( | |
| "/api/wallet/transactions", | |
| headers={"Authorization": f"Bearer {token}"} | |
| ) | |
| assert res_after.status_code == 200 | |
| txs = res_after.json() | |
| assert len(txs) == 1 | |
| assert txs[0]["amount"] == 1500 | |
| assert txs[0]["type"] == "credit" | |
| assert "top-up" in txs[0]["label"].lower() | |