#!/bin/bash # Test Frontend-Backend Connection Script # This script verifies that the frontend can connect to Directus and perform operations DIRECTUS_URL="http://localhost:8055" ADMIN_EMAIL="admin@assetmanagement.com" ADMIN_PASSWORD="AssetAdmin2024!" echo "🔗 Testing Frontend-Backend Connection..." echo # Test 1: Authentication echo "1️⃣ Testing authentication..." AUTH_RESPONSE=$(curl -s -X POST "$DIRECTUS_URL/auth/login" \ -H "Content-Type: application/json" \ -d "{\"email\":\"$ADMIN_EMAIL\",\"password\":\"$ADMIN_PASSWORD\"}") ACCESS_TOKEN=$(echo $AUTH_RESPONSE | grep -o '"access_token":"[^"]*"' | cut -d'"' -f4) if [ -z "$ACCESS_TOKEN" ]; then echo "❌ Authentication failed" exit 1 fi echo "✅ Authentication successful" # Test 2: Check collections are accessible echo echo "2️⃣ Testing collection access..." COLLECTIONS_RESPONSE=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \ "$DIRECTUS_URL/collections") if echo "$COLLECTIONS_RESPONSE" | grep -q "assets"; then echo "✅ Assets collection accessible" else echo "⚠️ Assets collection not found" fi # Test 3: Check if sample data exists echo echo "3️⃣ Checking for sample data..." # Check organizations ORG_COUNT=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \ "$DIRECTUS_URL/items/organizations" | grep -o '"id"' | wc -l) echo "📊 Organizations: $ORG_COUNT" # Check asset categories CAT_COUNT=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \ "$DIRECTUS_URL/items/asset_categories" | grep -o '"id"' | wc -l) echo "📊 Asset Categories: $CAT_COUNT" # Check locations LOC_COUNT=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \ "$DIRECTUS_URL/items/locations" | grep -o '"id"' | wc -l) echo "📊 Locations: $LOC_COUNT" # Check vendors VENDOR_COUNT=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \ "$DIRECTUS_URL/items/vendors" | grep -o '"id"' | wc -l) echo "📊 Vendors: $VENDOR_COUNT" # Check existing assets ASSET_COUNT=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \ "$DIRECTUS_URL/items/assets" | grep -o '"id"' | wc -l) echo "📊 Assets: $ASSET_COUNT" echo if [ "$ORG_COUNT" -gt 0 ] && [ "$CAT_COUNT" -gt 0 ] && [ "$LOC_COUNT" -gt 0 ]; then echo "✅ Sample data exists - ready for frontend testing" echo echo "🎯 Frontend URLs to test:" echo "- Frontend: http://localhost:5173 (or check your frontend port)" echo "- Directus Admin: http://localhost:8055/admin" echo "- Login: $ADMIN_EMAIL / $ADMIN_PASSWORD" else echo "⚠️ Missing sample data - this might cause frontend issues" echo "Consider running the database reset: make db-reset" fi echo echo "📋 Next steps:" echo "1. Open your frontend application" echo "2. Try logging in with the admin credentials" echo "3. Test creating a new asset" echo "4. Verify data appears in Directus admin panel"