79 lines
3.0 KiB
Bash
79 lines
3.0 KiB
Bash
|
|
#\!/bin/bash
|
||
|
|
|
||
|
|
echo "🧪 Testing Forecasting Service Components - FIXED ROUTES"
|
||
|
|
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: Test forecast endpoint with correct path format (no extra path)
|
||
|
|
echo ""
|
||
|
|
echo "2. Testing forecast endpoint with correct format..."
|
||
|
|
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": "Cafe", "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 2: Test predictions endpoint with correct format
|
||
|
|
echo ""
|
||
|
|
echo "3. Testing predictions endpoint with correct format..."
|
||
|
|
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": ["Cafe", "Pan"], "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 3: Direct forecasting service test (bypass gateway)
|
||
|
|
echo ""
|
||
|
|
echo "4. Testing forecasting service directly (bypass gateway)..."
|
||
|
|
DIRECT_FORECAST=$(curl -s -w "\nHTTP_CODE:%{http_code}" -X POST "http://localhost:8003/api/v1/tenants/$TENANT_ID/forecasts" \
|
||
|
|
-H "Content-Type: application/json" \
|
||
|
|
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||
|
|
-d '{"product_name": "Cafe", "days_ahead": 7}')
|
||
|
|
|
||
|
|
DIRECT_HTTP_CODE=$(echo "$DIRECT_FORECAST" | grep "HTTP_CODE:" | cut -d: -f2)
|
||
|
|
DIRECT_FORECAST=$(echo "$DIRECT_FORECAST" | sed '/HTTP_CODE:/d')
|
||
|
|
|
||
|
|
echo "Direct Forecast HTTP Code: $DIRECT_HTTP_CODE"
|
||
|
|
echo "Direct Forecast Response:"
|
||
|
|
echo "$DIRECT_FORECAST" | python3 -m json.tool 2>/dev/null || echo "$DIRECT_FORECAST"
|
||
|
|
|
||
|
|
echo ""
|
||
|
|
echo "🏁 Fixed forecasting test completed\!"
|