#!/bin/bash echo "๐Ÿงช Testing Forecasting Service Components" echo "========================================" # Use the most recent successful tenant from the full onboarding test TENANT_ID="5765e61a-4d06-4e17-b614-a4f8410e2a35" # Get a fresh access token echo "1. Getting access token..." LOGIN_RESPONSE=$(curl -s -X POST "http://localhost:8000/api/v1/auth/login" \ -H "Content-Type: application/json" \ -d '{"email": "onboarding.test.1754565461@bakery.com", "password": "TestPassword123!"}') ACCESS_TOKEN=$(echo "$LOGIN_RESPONSE" | python3 -c " import json, sys try: data = json.load(sys.stdin) print(data.get('access_token', '')) except: pass " 2>/dev/null) if [ -z "$ACCESS_TOKEN" ]; then echo "โŒ Login failed" echo "Response: $LOGIN_RESPONSE" exit 1 fi echo "โœ… Access token obtained" # Test 1: Check forecasting service health echo "" echo "2. Testing forecasting service health..." FORECAST_HEALTH=$(curl -s "http://localhost:8003/health") echo "Forecasting Service Health:" echo "$FORECAST_HEALTH" | python3 -m json.tool 2>/dev/null || echo "$FORECAST_HEALTH" # Test 2: Test forecast endpoint (should handle gracefully if no models exist) echo "" echo "3. Testing forecast endpoint..." FORECAST_RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" -X POST "http://localhost:8000/api/v1/tenants/$TENANT_ID/forecasts" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -d '{"product_name": "bread", "days_ahead": 7}') HTTP_CODE=$(echo "$FORECAST_RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2) FORECAST_RESPONSE=$(echo "$FORECAST_RESPONSE" | sed '/HTTP_CODE:/d') echo "Forecast HTTP Code: $HTTP_CODE" echo "Forecast Response:" echo "$FORECAST_RESPONSE" | python3 -m json.tool 2>/dev/null || echo "$FORECAST_RESPONSE" # Test 3: Test predictions endpoint echo "" echo "4. Testing predictions endpoint..." PREDICTION_RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" -X POST "http://localhost:8000/api/v1/tenants/$TENANT_ID/predictions" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -d '{"product_names": ["bread", "croissant"], "days_ahead": 5, "include_confidence": true}') PRED_HTTP_CODE=$(echo "$PREDICTION_RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2) PREDICTION_RESPONSE=$(echo "$PREDICTION_RESPONSE" | sed '/HTTP_CODE:/d') echo "Prediction HTTP Code: $PRED_HTTP_CODE" echo "Prediction Response:" echo "$PREDICTION_RESPONSE" | python3 -m json.tool 2>/dev/null || echo "$PREDICTION_RESPONSE" # Test 4: Check available products for this tenant echo "" echo "5. Testing available products endpoint..." PRODUCTS_RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" -X GET "http://localhost:8000/api/v1/tenants/$TENANT_ID/sales/products" \ -H "Authorization: Bearer $ACCESS_TOKEN") PROD_HTTP_CODE=$(echo "$PRODUCTS_RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2) PRODUCTS_RESPONSE=$(echo "$PRODUCTS_RESPONSE" | sed '/HTTP_CODE:/d') echo "Products HTTP Code: $PROD_HTTP_CODE" echo "Available Products:" echo "$PRODUCTS_RESPONSE" | python3 -m json.tool 2>/dev/null || echo "$PRODUCTS_RESPONSE" echo "" echo "๐Ÿ Forecasting service component test completed!"