Spaces:
Runtime error
Runtime error
File size: 1,430 Bytes
680fa2b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | 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()
|