121 lines
3.7 KiB
Bash
Executable File
121 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Test Tenant Provisioning Script
|
|
# This script tests the complete multi-tenant setup
|
|
|
|
set -e
|
|
|
|
echo "🚀 Testing Multi-Tenant Setup"
|
|
echo "=============================="
|
|
echo ""
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
BLUE='\033[0;34m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Check if backend is running
|
|
echo -e "${BLUE}Checking if backend is running...${NC}"
|
|
if ! curl -s http://jupiter.routebox.co:3000 > /dev/null; then
|
|
echo -e "${RED}Backend is not running. Please start it with: cd backend && npm run dev${NC}"
|
|
exit 1
|
|
fi
|
|
echo -e "${GREEN}✓ Backend is running${NC}"
|
|
echo ""
|
|
|
|
# Create test tenant
|
|
echo -e "${BLUE}Creating test tenant: 'acme'${NC}"
|
|
RESPONSE=$(curl -s -X POST http://localhost:3000/setup/tenants \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"name": "Acme Corporation",
|
|
"slug": "acme",
|
|
"primaryDomain": "acme"
|
|
}')
|
|
|
|
if echo "$RESPONSE" | grep -q "tenantId"; then
|
|
echo -e "${GREEN}✓ Tenant created successfully${NC}"
|
|
echo "$RESPONSE" | node -e "
|
|
const fs = require('fs');
|
|
const data = JSON.parse(fs.readFileSync(0, 'utf-8'));
|
|
console.log(' Tenant ID:', data.tenantId);
|
|
console.log(' Database:', data.dbName);
|
|
console.log(' Username:', data.dbUsername);
|
|
"
|
|
else
|
|
echo -e "${RED}✗ Failed to create tenant${NC}"
|
|
echo "$RESPONSE"
|
|
exit 1
|
|
fi
|
|
echo ""
|
|
|
|
# Verify tenant database was created
|
|
echo -e "${BLUE}Verifying tenant database...${NC}"
|
|
DB_EXISTS=$(docker exec platform-db mysql -uroot -proot -e "SHOW DATABASES LIKE 'tenant_acme';" | grep tenant_acme || echo "")
|
|
if [ -n "$DB_EXISTS" ]; then
|
|
echo -e "${GREEN}✓ Database 'tenant_acme' exists${NC}"
|
|
else
|
|
echo -e "${RED}✗ Database 'tenant_acme' not found${NC}"
|
|
exit 1
|
|
fi
|
|
echo ""
|
|
|
|
# Check if tables were created
|
|
echo -e "${BLUE}Checking tenant schema...${NC}"
|
|
TABLES=$(docker exec platform-db mysql -uroot -proot tenant_acme -e "SHOW TABLES;" 2>/dev/null || echo "")
|
|
if [ -n "$TABLES" ]; then
|
|
echo -e "${GREEN}✓ Tenant tables created:${NC}"
|
|
echo "$TABLES" | tail -n +2 | sed 's/^/ - /'
|
|
else
|
|
echo -e "${RED}✗ No tables found in tenant database${NC}"
|
|
exit 1
|
|
fi
|
|
echo ""
|
|
|
|
# Check if default roles were seeded
|
|
echo -e "${BLUE}Checking default data...${NC}"
|
|
ROLES=$(docker exec platform-db mysql -uroot -proot tenant_acme -e "SELECT name FROM roles;" 2>/dev/null | tail -n +2 || echo "")
|
|
if [ -n "$ROLES" ]; then
|
|
echo -e "${GREEN}✓ Default roles created:${NC}"
|
|
echo "$ROLES" | sed 's/^/ - /'
|
|
else
|
|
echo -e "${RED}✗ No default roles found${NC}"
|
|
exit 1
|
|
fi
|
|
echo ""
|
|
|
|
# Verify central database entries
|
|
echo -e "${BLUE}Verifying central database...${NC}"
|
|
TENANT_RECORD=$(docker exec platform-db mysql -uroot -proot central_platform -e "SELECT name, slug, status FROM tenants WHERE slug='acme';" 2>/dev/null | tail -n +2 || echo "")
|
|
if [ -n "$TENANT_RECORD" ]; then
|
|
echo -e "${GREEN}✓ Tenant record in central database:${NC}"
|
|
echo " $TENANT_RECORD"
|
|
else
|
|
echo -e "${RED}✗ Tenant record not found in central database${NC}"
|
|
exit 1
|
|
fi
|
|
echo ""
|
|
|
|
DOMAIN_RECORD=$(docker exec platform-db mysql -uroot -proot central_platform -e "SELECT domain, isPrimary FROM domains WHERE domain='acme';" 2>/dev/null | tail -n +2 || echo "")
|
|
if [ -n "$DOMAIN_RECORD" ]; then
|
|
echo -e "${GREEN}✓ Domain mapping exists:${NC}"
|
|
echo " $DOMAIN_RECORD"
|
|
else
|
|
echo -e "${RED}✗ Domain mapping not found${NC}"
|
|
exit 1
|
|
fi
|
|
echo ""
|
|
|
|
echo -e "${GREEN}=============================="
|
|
echo "✓ All tests passed!"
|
|
echo "==============================${NC}"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Update /etc/hosts: 127.0.0.1 acme.localhost"
|
|
echo " 2. Access tenant at: http://acme.localhost:3000"
|
|
echo " 3. Check logs: docker logs platform-api"
|
|
echo ""
|
|
echo "To clean up:"
|
|
echo " curl -X DELETE http://localhost:3000/setup/tenants/<tenant-id>"
|