#!/bin/bash # Test script for the mock API server # Usage: ./test-mock-api.sh BASE_URL="http://localhost:3000/api/mock" API_KEY="test-api-key" echo "๐Ÿงช Testing Freezone Mock API Server" echo "๐ŸŒ Base URL: $BASE_URL" echo "๐Ÿ”‘ API Key: $API_KEY" echo "----------------------------------------" # Function to make API calls with proper formatting test_endpoint() { local method=$1 local endpoint=$2 local description=$3 local data=$4 echo "" echo "๐Ÿ“‹ Testing: $description" echo "๐Ÿ”— $method $endpoint" if [ -n "$data" ]; then echo "๐Ÿ“ค Request Body:" echo "$data" | jq '.' 2>/dev/null || echo "$data" echo "" response=$(curl -s -X "$method" \ -H "Content-Type: application/json" \ -H "X-API-Key: $API_KEY" \ -d "$data" \ "$BASE_URL$endpoint") else response=$(curl -s -X "$method" \ -H "X-API-Key: $API_KEY" \ "$BASE_URL$endpoint") fi echo "๐Ÿ“ฅ Response:" echo "$response" | jq '.' 2>/dev/null || echo "$response" echo "----------------------------------------" } # Check if jq is available for JSON formatting if ! command -v jq &> /dev/null; then echo "๐Ÿ’ก Tip: Install 'jq' for better JSON formatting: brew install jq" echo "" fi # Check if mock server is running echo "๐Ÿ” Checking if mock server is running..." if ! curl -s "$BASE_URL" > /dev/null; then echo "โŒ Mock server is not running on $BASE_URL" echo "๐Ÿ’ก Start it with: ./start-mock-server.sh" exit 1 fi echo "โœ… Mock server is running!" # Test Authentication test_endpoint "POST" "/auth/api-key" "Generate API Key" '{ "client_id": "reseller_123", "client_secret": "secret_abc123xyz", "access_password": "freezone_access_2024" }' # Test Digital Residents test_endpoint "GET" "/digital-residents" "List Digital Residents" test_endpoint "POST" "/digital-residents" "Create Digital Resident" '{ "reseller_user_id": "reseller_user_456", "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "kyc_provider_id": "kyc_john_doe_789", "phone": "+1234567890" }' test_endpoint "GET" "/digital-residents/fz_resident_abc123" "Get Digital Resident" # Test Free Zone Companies test_endpoint "GET" "/free-zone-companies" "List Free Zone Companies" test_endpoint "POST" "/free-zone-companies" "Create Free Zone Company" '{ "reseller_company_id": "reseller_comp_123", "name": "Tech Innovations FZC", "type": "company", "description": "Technology consulting company", "registration_number": "FZC-2024-001", "tax_id": "TAX123456789", "address": { "street": "123 Business Bay", "city": "Dubai", "state": "Dubai", "postal_code": "12345", "country": "AE" }, "shareholder_resident_ids": ["fz_resident_abc123", "fz_resident_def456"], "crypto_wallets": [ { "public_key": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", "chain": "bitcoin", "label": "Main Bitcoin Wallet" } ] }' test_endpoint "GET" "/free-zone-companies/fz_company_xyz789" "Get Free Zone Company" # Test Invoices test_endpoint "GET" "/free-zone-companies/fz_company_xyz789/invoices" "List Company Invoices" test_endpoint "POST" "/free-zone-companies/fz_company_xyz789/invoices" "Create Invoice" '{ "reseller_invoice_id": "reseller_inv_456", "invoice_number": "INV-2024-001", "amount": 1500.00, "currency": "USD", "tax_amount": 150.00, "description": "Consulting services for Q1 2024", "line_items": [ { "description": "Strategy consulting", "quantity": 10, "unit_price": 150.00, "amount": 1500.00 } ], "issue_date": "2024-01-15", "due_date": "2024-02-15" }' test_endpoint "GET" "/free-zone-companies/fz_company_xyz789/invoices/fz_invoice_inv123" "Get Invoice" # Test Expenses test_endpoint "GET" "/free-zone-companies/fz_company_xyz789/expenses" "List Company Expenses" test_endpoint "POST" "/free-zone-companies/fz_company_xyz789/expenses" "Create Expense" '{ "reseller_expense_id": "reseller_exp_456", "amount": 500.00, "currency": "USD", "category": "office_supplies", "description": "Office equipment purchase", "vendor": "Office Depot", "receipt_url": "https://receipts.example.com/receipt123.pdf", "date": "2024-01-15" }' test_endpoint "GET" "/free-zone-companies/fz_company_xyz789/expenses/fz_expense_exp123" "Get Expense" echo "" echo "โœ… Mock API testing completed!" echo "๐Ÿ’ก All endpoints should return example responses from the OpenAPI specification" echo "๐Ÿ”ง Mock server provides realistic data for development and testing"