Improve the design of the frontend
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "🚀 Deploying Bakery Forecasting Platform..."
|
||||
|
||||
# Build and deploy all services
|
||||
docker-compose build
|
||||
docker-compose up -d
|
||||
|
||||
echo "Waiting for services to be healthy..."
|
||||
sleep 30
|
||||
|
||||
# Check service health
|
||||
echo "Checking service health..."
|
||||
curl -f http://localhost:8000/health || echo "Gateway health check failed"
|
||||
|
||||
echo "✅ Deployment completed"
|
||||
echo "Gateway: http://localhost:8000"
|
||||
echo "API Docs: http://localhost:8000/docs"
|
||||
@@ -1,14 +0,0 @@
|
||||
# scripts/docker-logs.sh
|
||||
#!/bin/bash
|
||||
|
||||
# View logs for specific service or all services
|
||||
|
||||
SERVICE=${1:-"all"}
|
||||
|
||||
if [ "$SERVICE" = "all" ]; then
|
||||
echo "📋 Showing logs for all services..."
|
||||
docker-compose logs -f --tail=100
|
||||
else
|
||||
echo "📋 Showing logs for $SERVICE..."
|
||||
docker-compose logs -f --tail=100 $SERVICE
|
||||
fi
|
||||
@@ -1,201 +0,0 @@
|
||||
#!/bin/bash
|
||||
# scripts/fix-frontend.sh - Frontend troubleshooting script
|
||||
|
||||
set -e
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[0;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
print_step() {
|
||||
echo -e "${BLUE}[FRONTEND-FIX]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if we're in the right directory
|
||||
if [ ! -f "docker-compose.yml" ]; then
|
||||
print_error "docker-compose.yml not found. Please run this script from the project root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_step "Starting frontend troubleshooting..."
|
||||
|
||||
# Step 1: Check frontend directory structure
|
||||
print_step "Checking frontend directory structure..."
|
||||
if [ ! -d "frontend" ]; then
|
||||
print_error "Frontend directory not found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd frontend
|
||||
|
||||
# Step 2: Check package.json exists
|
||||
if [ ! -f "package.json" ]; then
|
||||
print_error "package.json not found in frontend directory!"
|
||||
exit 1
|
||||
fi
|
||||
print_success "package.json found"
|
||||
|
||||
# Step 3: Generate package-lock.json if missing
|
||||
if [ ! -f "package-lock.json" ]; then
|
||||
print_warning "package-lock.json not found. Generating..."
|
||||
npm install
|
||||
print_success "package-lock.json generated"
|
||||
else
|
||||
print_success "package-lock.json found"
|
||||
fi
|
||||
|
||||
# Step 4: Check for missing directories
|
||||
print_step "Creating missing directories..."
|
||||
mkdir -p src/pages
|
||||
mkdir -p src/components
|
||||
mkdir -p src/hooks
|
||||
mkdir -p src/services
|
||||
mkdir -p src/utils
|
||||
mkdir -p public
|
||||
print_success "Directory structure verified"
|
||||
|
||||
# Step 5: Check for App.tsx
|
||||
if [ ! -f "src/App.tsx" ]; then
|
||||
print_warning "src/App.tsx not found. Creating basic App.tsx..."
|
||||
|
||||
cat > src/App.tsx << 'EOF'
|
||||
import React from 'react'
|
||||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<Router>
|
||||
<div className="App min-h-screen bg-gray-50">
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<h1 className="text-3xl font-bold text-gray-900 mb-6">
|
||||
🥖 PanIA Dashboard
|
||||
</h1>
|
||||
<div className="bg-white rounded-lg shadow p-6">
|
||||
<h2 className="text-xl font-semibold mb-4">
|
||||
Bienvenido a PanIA
|
||||
</h2>
|
||||
<p className="text-gray-600">
|
||||
Sistema de predicción de demanda para panaderías en Madrid
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Router>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
EOF
|
||||
print_success "Basic App.tsx created"
|
||||
else
|
||||
print_success "App.tsx found"
|
||||
fi
|
||||
|
||||
# Step 6: Check for index.css
|
||||
if [ ! -f "src/index.css" ]; then
|
||||
print_warning "src/index.css not found. Creating basic CSS..."
|
||||
|
||||
cat > src/index.css << 'EOF'
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
||||
EOF
|
||||
print_success "Basic index.css created"
|
||||
else
|
||||
print_success "index.css found"
|
||||
fi
|
||||
|
||||
# Step 7: Go back to project root
|
||||
cd ..
|
||||
|
||||
# Step 8: Stop and remove the frontend container
|
||||
print_step "Stopping and removing existing frontend container..."
|
||||
docker-compose stop dashboard 2>/dev/null || true
|
||||
docker-compose rm -f dashboard 2>/dev/null || true
|
||||
|
||||
# Step 9: Remove the image to force rebuild
|
||||
print_step "Removing frontend image to force rebuild..."
|
||||
docker rmi bakery/dashboard:latest 2>/dev/null || true
|
||||
|
||||
# Step 10: Check .env file
|
||||
if [ ! -f ".env" ]; then
|
||||
print_warning ".env file not found. Creating from example..."
|
||||
if [ -f ".env.example" ]; then
|
||||
cp .env.example .env
|
||||
print_success ".env created from .env.example"
|
||||
else
|
||||
# Create minimal .env
|
||||
cat > .env << 'EOF'
|
||||
ENVIRONMENT=development
|
||||
DASHBOARD_PORT=3000
|
||||
GATEWAY_PORT=8000
|
||||
IMAGE_TAG=latest
|
||||
EOF
|
||||
print_success "Minimal .env created"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Step 11: Rebuild the frontend service
|
||||
print_step "Rebuilding frontend service..."
|
||||
docker-compose build --no-cache dashboard
|
||||
|
||||
# Step 12: Start the frontend service
|
||||
print_step "Starting frontend service..."
|
||||
docker-compose up -d dashboard
|
||||
|
||||
# Step 13: Wait and check status
|
||||
print_step "Waiting for frontend to start..."
|
||||
sleep 10
|
||||
|
||||
# Check if container is running
|
||||
if docker-compose ps dashboard | grep -q "Up"; then
|
||||
print_success "Frontend container is running!"
|
||||
print_step "Checking logs..."
|
||||
docker-compose logs --tail=20 dashboard
|
||||
|
||||
print_step "Testing frontend health..."
|
||||
sleep 5
|
||||
if curl -f http://localhost:3000 >/dev/null 2>&1; then
|
||||
print_success "Frontend is accessible at http://localhost:3000"
|
||||
else
|
||||
print_warning "Frontend is running but not yet accessible. Check logs above."
|
||||
fi
|
||||
else
|
||||
print_error "Frontend container failed to start. Check logs:"
|
||||
docker-compose logs dashboard
|
||||
fi
|
||||
|
||||
print_step "Frontend troubleshooting completed!"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Check the frontend at: http://localhost:3000"
|
||||
echo "2. View logs with: docker-compose logs dashboard"
|
||||
echo "3. Restart if needed: docker-compose restart dashboard"
|
||||
@@ -1,90 +0,0 @@
|
||||
# scripts/docker-health-check.sh
|
||||
#!/bin/bash
|
||||
|
||||
# Comprehensive health check for all services
|
||||
|
||||
services=(
|
||||
"bakery-redis:6379"
|
||||
"bakery-rabbitmq:15672"
|
||||
"bakery-gateway:8000"
|
||||
"bakery-auth-service:8000"
|
||||
"bakery-tenant-service:8000"
|
||||
"bakery-training-service:8000"
|
||||
"bakery-forecasting-service:8000"
|
||||
"bakery-data-service:8000"
|
||||
"bakery-notification-service:8000"
|
||||
)
|
||||
|
||||
echo "🏥 Checking service health..."
|
||||
|
||||
for service_port in "${services[@]}"; do
|
||||
service=$(echo $service_port | cut -d: -f1)
|
||||
port=$(echo $service_port | cut -d: -f2)
|
||||
|
||||
if docker ps --format "table {{.Names}}" | grep -q "^$service$"; then
|
||||
if [ "$service" = "bakery-redis" ]; then
|
||||
# Redis health check
|
||||
if docker exec $service redis-cli -a redis_pass123 ping > /dev/null 2>&1; then
|
||||
echo "✅ $service is healthy"
|
||||
else
|
||||
echo "❌ $service is unhealthy"
|
||||
fi
|
||||
elif [ "$service" = "bakery-rabbitmq" ]; then
|
||||
# RabbitMQ health check
|
||||
if curl -s -u bakery:forecast123 http://localhost:$port/api/health/checks/alarms > /dev/null; then
|
||||
echo "✅ $service is healthy"
|
||||
else
|
||||
echo "❌ $service is unhealthy"
|
||||
fi
|
||||
else
|
||||
# HTTP service health check
|
||||
container_ip=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $service)
|
||||
if curl -f -s "http://$container_ip:8000/health" > /dev/null; then
|
||||
echo "✅ $service is healthy"
|
||||
else
|
||||
echo "❌ $service is unhealthy"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "⚠️ $service is not running"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "🔍 Checking database connections..."
|
||||
|
||||
databases=("auth-db" "training-db" "forecasting-db" "data-db" "tenant-db" "notification-db")
|
||||
|
||||
for db in "${databases[@]}"; do
|
||||
if docker ps --format "table {{.Names}}" | grep -q "^bakery-$db$"; then
|
||||
db_name=$(echo $db | sed 's/-/_/g')
|
||||
user=$(echo $db | sed 's/-db//' | sed 's/-/_/g')_user
|
||||
|
||||
if docker exec bakery-$db pg_isready -U $user -d $db_name > /dev/null 2>&1; then
|
||||
echo "✅ bakery-$db is ready"
|
||||
else
|
||||
echo "❌ bakery-$db is not ready"
|
||||
fi
|
||||
else
|
||||
echo "⚠️ bakery-$db is not running"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "📊 Service resource usage:"
|
||||
docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" $(docker ps --format "{{.Names}}" | grep "^bakery-")
|
||||
|
||||
# scripts/docker-logs.sh
|
||||
#!/bin/bash
|
||||
|
||||
# View logs for specific service or all services
|
||||
|
||||
SERVICE=${1:-"all"}
|
||||
|
||||
if [ "$SERVICE" = "all" ]; then
|
||||
echo "📋 Showing logs for all services..."
|
||||
docker-compose logs -f --tail=100
|
||||
else
|
||||
echo "📋 Showing logs for $SERVICE..."
|
||||
docker-compose logs -f --tail=100 $SERVICE
|
||||
fi
|
||||
@@ -1,106 +0,0 @@
|
||||
# ================================================================
|
||||
# SERVICE RESTART SCRIPT
|
||||
# scripts/restart-service.sh
|
||||
# ================================================================
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
# Restart individual service script
|
||||
|
||||
set -e
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m'
|
||||
|
||||
print_step() {
|
||||
echo -e "${BLUE}[RESTART]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
restart_service() {
|
||||
local service=$1
|
||||
|
||||
print_step "Restarting $service..."
|
||||
|
||||
# Build the service
|
||||
docker-compose build $service
|
||||
|
||||
# Restart with zero downtime
|
||||
docker-compose up -d --no-deps --force-recreate $service
|
||||
|
||||
# Wait a bit for the service to start
|
||||
sleep 5
|
||||
|
||||
# Check health
|
||||
local port
|
||||
case $service in
|
||||
"gateway") port=8000 ;;
|
||||
"auth-service") port=8001 ;;
|
||||
"training-service") port=8002 ;;
|
||||
"forecasting-service") port=8003 ;;
|
||||
"data-service") port=8004 ;;
|
||||
"tenant-service") port=8005 ;;
|
||||
"notification-service") port=8006 ;;
|
||||
*)
|
||||
print_error "Unknown service: $service"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Health check with timeout
|
||||
local attempts=0
|
||||
local max_attempts=12 # 60 seconds total
|
||||
|
||||
while [ $attempts -lt $max_attempts ]; do
|
||||
if curl -f -s "http://localhost:$port/health" > /dev/null 2>&1; then
|
||||
print_success "$service is healthy and ready"
|
||||
return 0
|
||||
fi
|
||||
|
||||
attempts=$((attempts + 1))
|
||||
echo "Waiting for $service to be healthy... ($attempts/$max_attempts)"
|
||||
sleep 5
|
||||
done
|
||||
|
||||
print_error "$service failed to become healthy within 60 seconds"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Main function
|
||||
main() {
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Usage: $0 <service-name>"
|
||||
echo ""
|
||||
echo "Available services:"
|
||||
echo " gateway"
|
||||
echo " auth-service"
|
||||
echo " training-service"
|
||||
echo " forecasting-service"
|
||||
echo " data-service"
|
||||
echo " tenant-service"
|
||||
echo " notification-service"
|
||||
echo ""
|
||||
echo "Example: $0 auth-service"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local service=$1
|
||||
|
||||
echo "================================================================"
|
||||
echo "RESTARTING SERVICE: $service"
|
||||
echo "================================================================"
|
||||
|
||||
restart_service $service
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
@@ -1,392 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ================================================================
|
||||
# Complete Authentication Test with Registration - FIXED VERSION
|
||||
# Tests the full user lifecycle: registration → login → API access
|
||||
# ================================================================
|
||||
|
||||
echo "🔐 Testing Complete Authentication System with Registration"
|
||||
echo "=========================================================="
|
||||
|
||||
# Configuration
|
||||
API_BASE="http://localhost:8000"
|
||||
AUTH_BASE="$API_BASE/api/v1/auth"
|
||||
TEST_EMAIL="test-$(date +%s)@bakery.com" # Unique email for each test
|
||||
TEST_PASSWORD="SecurePass123!"
|
||||
TEST_NAME="Test Baker"
|
||||
# ✅ FIX: Generate a proper UUID for tenant testing (will be replaced after bakery creation)
|
||||
TENANT_ID=$(uuidgen 2>/dev/null || python3 -c "import uuid; print(uuid.uuid4())" 2>/dev/null || echo "00000000-0000-0000-0000-000000000000")
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Helper function for colored output
|
||||
log_step() {
|
||||
echo -e "${BLUE}📍 $1${NC}"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}✅ $1${NC}"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}❌ $1${NC}"
|
||||
}
|
||||
|
||||
log_warning() {
|
||||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||||
}
|
||||
|
||||
# Helper function to check if service is healthy
|
||||
check_service_health() {
|
||||
local service_url=$1
|
||||
local service_name=$2
|
||||
|
||||
log_step "Checking $service_name health..."
|
||||
|
||||
response=$(curl -s -o /dev/null -w "%{http_code}" "$service_url/health")
|
||||
if [ "$response" = "200" ]; then
|
||||
log_success "$service_name is healthy"
|
||||
return 0
|
||||
else
|
||||
log_error "$service_name is not healthy (HTTP $response)"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Check all services are running
|
||||
log_step "Pre-flight checks..."
|
||||
echo ""
|
||||
|
||||
# Check API Gateway
|
||||
if ! check_service_health "$API_BASE" "API Gateway"; then
|
||||
log_error "API Gateway is not running. Start with: docker-compose up -d"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check Auth Service directly
|
||||
if ! check_service_health "http://localhost:8001" "Auth Service"; then
|
||||
log_error "Auth Service is not running. Check: docker-compose logs auth-service"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check Tenant Service
|
||||
if ! check_service_health "http://localhost:8005" "Tenant Service"; then
|
||||
log_error "Tenant Service is not running. Check: docker-compose logs tenant-service"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check Data Service
|
||||
if ! check_service_health "http://localhost:8004" "Data Service"; then
|
||||
log_warning "Data Service is not running, but continuing with auth tests..."
|
||||
fi
|
||||
|
||||
# Check Training Service
|
||||
if ! check_service_health "http://localhost:8002" "Training Service"; then
|
||||
log_warning "Training Service is not running, but continuing with auth tests..."
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_step "All systems ready! Starting authentication tests..."
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 1: USER REGISTRATION
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 1: Registering new user"
|
||||
echo "Email: $TEST_EMAIL"
|
||||
echo "Password: $TEST_PASSWORD"
|
||||
echo ""
|
||||
|
||||
REGISTRATION_RESPONSE=$(curl -s -X POST "$AUTH_BASE/register" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"email\": \"$TEST_EMAIL\",
|
||||
\"password\": \"$TEST_PASSWORD\",
|
||||
\"full_name\": \"$TEST_NAME\"
|
||||
}")
|
||||
|
||||
echo "Registration Response:"
|
||||
echo "$REGISTRATION_RESPONSE" | jq '.'
|
||||
|
||||
# Check if registration was successful
|
||||
if echo "$REGISTRATION_RESPONSE" | jq -e '.id' > /dev/null; then
|
||||
USER_ID=$(echo "$REGISTRATION_RESPONSE" | jq -r '.id')
|
||||
log_success "User registration successful! User ID: $USER_ID"
|
||||
else
|
||||
log_error "User registration failed!"
|
||||
echo "Response: $REGISTRATION_RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 2: USER LOGIN
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 2: Logging in with new user credentials"
|
||||
|
||||
LOGIN_RESPONSE=$(curl -s -X POST "$AUTH_BASE/login" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"email\": \"$TEST_EMAIL\",
|
||||
\"password\": \"$TEST_PASSWORD\"
|
||||
}")
|
||||
|
||||
echo "Login Response:"
|
||||
echo "$LOGIN_RESPONSE" | jq '.'
|
||||
|
||||
# Extract access token
|
||||
if echo "$LOGIN_RESPONSE" | jq -e '.access_token' > /dev/null; then
|
||||
ACCESS_TOKEN=$(echo "$LOGIN_RESPONSE" | jq -r '.access_token')
|
||||
REFRESH_TOKEN=$(echo "$LOGIN_RESPONSE" | jq -r '.refresh_token')
|
||||
log_success "Login successful! Token obtained: ${ACCESS_TOKEN:0:20}..."
|
||||
else
|
||||
log_error "Login failed!"
|
||||
echo "Response: $LOGIN_RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 3: ACCESSING PROTECTED ENDPOINTS
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 3: Testing protected endpoints with authentication"
|
||||
|
||||
# 3a. Get current user info
|
||||
log_step "3a. Getting current user profile"
|
||||
|
||||
USER_PROFILE_RESPONSE=$(curl -s -X GET "$API_BASE/api/v1/users/me" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN")
|
||||
|
||||
echo "User Profile Response:"
|
||||
echo "$USER_PROFILE_RESPONSE" | jq '.'
|
||||
|
||||
if echo "$USER_PROFILE_RESPONSE" | jq -e '.email' > /dev/null; then
|
||||
log_success "User profile retrieved successfully!"
|
||||
else
|
||||
log_warning "User profile endpoint may not be implemented yet"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 4: TENANT REGISTRATION (BAKERY CREATION)
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 4: Registering a bakery/tenant"
|
||||
|
||||
BAKERY_RESPONSE=$(curl -s -X POST "$API_BASE/api/v1/tenants/register" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"name\": \"Test Bakery $(date +%H%M)\",
|
||||
\"business_type\": \"bakery\",
|
||||
\"address\": \"Calle Test 123\",
|
||||
\"city\": \"Madrid\",
|
||||
\"postal_code\": \"28001\",
|
||||
\"phone\": \"+34600123456\"
|
||||
}")
|
||||
|
||||
echo "Bakery Registration Response:"
|
||||
echo "$BAKERY_RESPONSE" | jq '.'
|
||||
|
||||
if echo "$BAKERY_RESPONSE" | jq -e '.id' > /dev/null; then
|
||||
# ✅ FIX: Use the actual tenant ID returned from bakery creation
|
||||
TENANT_ID=$(echo "$BAKERY_RESPONSE" | jq -r '.id')
|
||||
log_success "Bakery registration successful! Tenant ID: $TENANT_ID"
|
||||
else
|
||||
log_error "Bakery registration failed!"
|
||||
echo "Response: $BAKERY_RESPONSE"
|
||||
# Continue with tests using placeholder UUID for other endpoints
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 5: TEST DATA SERVICE WITH TENANT ID
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 5: Testing data service through gateway"
|
||||
|
||||
# Only test with valid tenant ID
|
||||
if [ "$TENANT_ID" != "00000000-0000-0000-0000-000000000000" ]; then
|
||||
DATA_RESPONSE=$(curl -s -X GET "$API_BASE/api/v1/data/sales" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-H "X-Tenant-ID: $TENANT_ID")
|
||||
|
||||
echo "Data Service Response:"
|
||||
echo "$DATA_RESPONSE" | jq '.'
|
||||
|
||||
if [ "$(echo "$DATA_RESPONSE" | jq -r '.status // "unknown"')" != "error" ]; then
|
||||
log_success "Data service access successful!"
|
||||
else
|
||||
log_warning "Data service returned error (may be expected for new tenant)"
|
||||
fi
|
||||
else
|
||||
log_warning "Skipping data service test - no valid tenant ID"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 6: TEST TRAINING SERVICE WITH TENANT ID
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 6: Testing training service through gateway"
|
||||
|
||||
# Only test with valid tenant ID
|
||||
if [ "$TENANT_ID" != "00000000-0000-0000-0000-000000000000" ]; then
|
||||
TRAINING_RESPONSE=$(curl -s -X POST "$API_BASE/api/v1/training/jobs" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-H "X-Tenant-ID: $TENANT_ID" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"include_weather": true,
|
||||
"include_traffic": false,
|
||||
"min_data_points": 30
|
||||
}')
|
||||
|
||||
echo "Training Service Response:"
|
||||
echo "$TRAINING_RESPONSE" | jq '.'
|
||||
|
||||
if echo "$TRAINING_RESPONSE" | jq -e '.job_id // .message' > /dev/null; then
|
||||
log_success "Training service access successful!"
|
||||
else
|
||||
log_warning "Training service access may have issues"
|
||||
fi
|
||||
else
|
||||
log_warning "Skipping training service test - no valid tenant ID"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 7: TOKEN REFRESH
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 7: Testing token refresh"
|
||||
|
||||
REFRESH_RESPONSE=$(curl -s -X POST "$AUTH_BASE/refresh" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"refresh_token\": \"$REFRESH_TOKEN\"
|
||||
}")
|
||||
|
||||
echo "Token Refresh Response:"
|
||||
echo "$REFRESH_RESPONSE" | jq '.'
|
||||
|
||||
if echo "$REFRESH_RESPONSE" | jq -e '.access_token' > /dev/null; then
|
||||
NEW_ACCESS_TOKEN=$(echo "$REFRESH_RESPONSE" | jq -r '.access_token')
|
||||
log_success "Token refresh successful! New token: ${NEW_ACCESS_TOKEN:0:20}..."
|
||||
else
|
||||
log_warning "Token refresh may not be fully implemented"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 8: DIRECT SERVICE HEALTH CHECKS
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 8: Testing direct service access (without gateway)"
|
||||
|
||||
# Test auth service directly
|
||||
log_step "8a. Auth service direct health check"
|
||||
AUTH_HEALTH=$(curl -s -X GET "http://localhost:8001/health")
|
||||
echo "Auth Service Health:"
|
||||
echo "$AUTH_HEALTH" | jq '.'
|
||||
|
||||
# Test other services if available
|
||||
log_step "8b. Other services health check"
|
||||
|
||||
services=("8002:Training" "8003:Forecasting" "8004:Data" "8005:Tenant" "8006:Notification")
|
||||
|
||||
for service in "${services[@]}"; do
|
||||
port=$(echo $service | cut -d: -f1)
|
||||
name=$(echo $service | cut -d: -f2)
|
||||
|
||||
health_response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:$port/health" 2>/dev/null)
|
||||
if [ "$health_response" = "200" ]; then
|
||||
log_success "$name Service (port $port) is healthy"
|
||||
else
|
||||
log_warning "$name Service (port $port) is not responding"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# STEP 9: LOGOUT
|
||||
# ================================================================
|
||||
|
||||
log_step "Step 9: Logging out user"
|
||||
|
||||
LOGOUT_RESPONSE=$(curl -s -X POST "$AUTH_BASE/logout" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-H "Content-Type: application/json")
|
||||
|
||||
echo "Logout Response:"
|
||||
echo "$LOGOUT_RESPONSE" | jq '.'
|
||||
|
||||
if echo "$LOGOUT_RESPONSE" | jq -e '.message' > /dev/null; then
|
||||
log_success "Logout successful!"
|
||||
else
|
||||
log_warning "Logout endpoint may not be fully implemented"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# ================================================================
|
||||
# SUMMARY
|
||||
# ================================================================
|
||||
|
||||
echo "🎉 Authentication Test Summary"
|
||||
echo "==============================="
|
||||
echo ""
|
||||
echo "Test User Created:"
|
||||
echo " 📧 Email: $TEST_EMAIL"
|
||||
echo " 👤 Name: $TEST_NAME"
|
||||
echo " 🆔 User ID: $USER_ID"
|
||||
echo ""
|
||||
echo "Authentication Flow:"
|
||||
echo " ✅ User Registration"
|
||||
echo " ✅ User Login"
|
||||
echo " ✅ Token Verification"
|
||||
echo " ✅ Protected Endpoint Access"
|
||||
echo " ✅ Token Refresh"
|
||||
echo " ✅ User Logout"
|
||||
echo ""
|
||||
echo "Services Tested:"
|
||||
echo " 🌐 API Gateway"
|
||||
echo " 🔐 Auth Service"
|
||||
echo " 🏢 Tenant Service (bakery registration)"
|
||||
echo " 📊 Data Service (through gateway)"
|
||||
echo " 🤖 Training Service (through gateway)"
|
||||
echo ""
|
||||
|
||||
if [ "$TENANT_ID" != "00000000-0000-0000-0000-000000000000" ]; then
|
||||
echo "Tenant Created:"
|
||||
echo " 🏪 Tenant ID: $TENANT_ID"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
log_success "Complete authentication test finished successfully!"
|
||||
echo ""
|
||||
echo "🔧 Development Tips:"
|
||||
echo " • Use the created test user for further development"
|
||||
echo " • Check service logs with: docker-compose logs [service-name]"
|
||||
echo " • View API docs at: http://localhost:8000/docs"
|
||||
echo " • Monitor services at: http://localhost:3002"
|
||||
echo ""
|
||||
echo "🧹 Cleanup:"
|
||||
echo " • Test user will remain in database for development"
|
||||
echo " • To reset: Delete user from auth database or run cleanup script"
|
||||
Reference in New Issue
Block a user