multiberry-backend/test_multiberry.sh

134 lines
4.9 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Save as test_multiberry.sh
# Extended comprehensive test with DB verification
BASE_URL="http://localhost:3000/api"
echo "=========================================="
echo "1⃣ REGISTER USER"
echo "=========================================="
REGISTER=$(curl -s -X POST $BASE_URL/auth/register \
-H 'Content-Type: application/json' \
-d '{"bank_user_number": 1, "password": "testpass123"}')
echo "$REGISTER" | jq .
TOKEN=$(echo "$REGISTER" | jq -r '.token')
BANK_USER_ID=$(echo "$REGISTER" | jq -r '.bank_user_id')
echo "✅ Token: ${TOKEN:0:50}..."
echo "✅ Bank User ID: $BANK_USER_ID"
echo ""
echo "=========================================="
echo "2⃣ LOGIN (verify token works)"
echo "=========================================="
curl -s -X POST $BASE_URL/auth/login \
-H 'Content-Type: application/json' \
-d "{\"bank_user_id\": \"$BANK_USER_ID\", \"password\": \"testpass123\"}" | jq .
echo ""
echo "=========================================="
echo "3⃣ GET ME (verify auth middleware)"
echo "=========================================="
curl -s http://localhost:3000/api/auth/me \
-H "Authorization: Bearer $TOKEN" | jq .
echo ""
echo "=========================================="
echo "4⃣ REQUEST CONSENT from VBank"
echo "=========================================="
CONSENT=$(curl -s -X POST $BASE_URL/consent/vbank/$BANK_USER_ID \
-H "Authorization: Bearer $TOKEN")
echo "$CONSENT" | jq .
CONSENT_ID=$(echo "$CONSENT" | jq -r '.consent_id')
echo "✅ Consent ID: $CONSENT_ID"
echo ""
echo "=========================================="
echo "5⃣ GET ACCOUNTS (auto-saved to DB)"
echo "=========================================="
ACCOUNTS=$(curl -s $BASE_URL/accounts/vbank/$BANK_USER_ID \
-H "Authorization: Bearer $TOKEN")
echo "$ACCOUNTS" | jq .
ACCOUNT_ID=$(echo "$ACCOUNTS" | jq -r '.data.account[0].accountId')
echo "✅ Account ID: $ACCOUNT_ID"
echo ""
echo "=========================================="
echo "6⃣ GET BALANCES (auto-saved to DB)"
echo "=========================================="
BALANCES=$(curl -s $BASE_URL/balances/vbank/$ACCOUNT_ID \
-H "Authorization: Bearer $TOKEN")
echo "$BALANCES" | jq .
BALANCE_AMOUNT=$(echo "$BALANCES" | jq -r '.data.balance[0].amount.amount')
echo "✅ Current Balance: $BALANCE_AMOUNT RUB"
echo ""
echo "=========================================="
echo "7⃣ GET TRANSACTIONS (page 1, limit 6 - auto-saved)"
echo "=========================================="
TRANS_PAGE1=$(curl -s "$BASE_URL/transactions/vbank/$BANK_USER_ID/$ACCOUNT_ID?page=1&limit=6" \
-H "Authorization: Bearer $TOKEN")
echo "$TRANS_PAGE1" | jq .
TOTAL_RECORDS=$(echo "$TRANS_PAGE1" | jq -r '.meta.totalRecords')
echo "✅ Total Records: $TOTAL_RECORDS"
echo ""
echo "=========================================="
echo "8⃣ GET TRANSACTIONS (page 2, limit 6)"
echo "=========================================="
curl -s "$BASE_URL/transactions/vbank/$BANK_USER_ID/$ACCOUNT_ID?page=2&limit=6" \
-H "Authorization: Bearer $TOKEN" | jq .
echo ""
echo "=========================================="
echo "9⃣ DELETE CONSENT"
echo "=========================================="
curl -s -X DELETE $BASE_URL/consent/vbank/$BANK_USER_ID \
-H "Authorization: Bearer $TOKEN" | jq .
echo ""
echo "=========================================="
echo "🔟 VERIFY DATABASE CACHE"
echo "=========================================="
echo ""
echo "Run in another terminal:"
echo "just psql-exec"
echo ""
echo "Then execute these queries:"
echo ""
echo "-- Check users registered:"
echo "SELECT bank_user_id, created_at FROM users ORDER BY created_at DESC LIMIT 5;"
echo ""
echo "-- Check consents granted:"
echo "SELECT user_id, bank_code, consent_id, status, expires_at FROM user_consents;"
echo ""
echo "-- Check accounts cached:"
echo "SELECT account_id, user_id, bank_code, nickname, currency FROM accounts;"
echo ""
echo "-- Check balances cached:"
echo "SELECT account_id, balance_type, amount, currency, date_time FROM balances;"
echo ""
echo "-- Check transactions cached (show count by account):"
echo "SELECT account_id, COUNT(*) as tx_count, MIN(booking_date_time) as oldest, MAX(booking_date_time) as newest FROM transactions GROUP BY account_id;"
echo ""
echo "-- Show recent transactions:"
echo "SELECT transaction_id, account_id, amount, currency, credit_debit_indicator, transaction_information, booking_date_time FROM transactions ORDER BY booking_date_time DESC LIMIT 10;"
echo ""
echo "=========================================="
echo "✅ FULL TEST COMPLETE!"
echo "=========================================="
echo ""
echo "Summary:"
echo "✅ Authentication (register/login/auth middleware)"
echo "✅ Consent Management (request consent)"
echo "✅ Account Aggregation (fetch & cache accounts)"
echo "✅ Balance Retrieval (fetch & cache balances)"
echo "✅ Transaction History (fetch & cache transactions)"
echo "✅ Data Persistence (all cached in PostgreSQL)"
echo ""