Fix new services implementation 2
This commit is contained in:
162
test_onboarding_debug.py
Normal file
162
test_onboarding_debug.py
Normal file
@@ -0,0 +1,162 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to debug onboarding inventory creation step by step
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import httpx
|
||||
import sys
|
||||
from uuid import uuid4
|
||||
|
||||
# Test configuration
|
||||
GATEWAY_URL = "http://localhost:8000"
|
||||
TENANT_ID = "946206b3-7446-436b-b29d-f265b28d9ff5"
|
||||
|
||||
# Test token (you'll need to replace this with a real token)
|
||||
TEST_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIzOTUyYTEwOC1lNWFmLTRlMjktOTJkOC0xMjc0MTBiOWJiYmEiLCJ1c2VyX2lkIjoiMzk1MmExMDgtZTVhZi00ZTI5LTkyZDgtMTI3NDEwYjliYmJhIiwiZW1haWwiOiJkZnNmc2RAdGVzdC5jb20iLCJ0eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzU1MTY3NTk4LCJpYXQiOjE3NTUxNjU3OTgsImlzcyI6ImJha2VyeS1hdXRoIiwiZnVsbF9uYW1lIjoiZGZzZGZzZGYiLCJpc192ZXJpZmllZCI6ZmFsc2UsImlzX2FjdGl2ZSI6dHJ1ZSwicm9sZSI6InVzZXIifQ.hYyRqqqZ-Ud-uzn42l_ic-QjP-NWYvT8RmwmU12uaQU"
|
||||
|
||||
async def test_onboarding_flow():
|
||||
"""Test the complete onboarding inventory creation flow"""
|
||||
|
||||
print("🧪 Testing Onboarding Inventory Creation Flow")
|
||||
print("=" * 60)
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {TEST_TOKEN}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
async with httpx.AsyncClient(timeout=30.0) as client:
|
||||
|
||||
# Step 1: Test direct ingredient creation via inventory service
|
||||
print("\n1️⃣ Testing Direct Ingredient Creation via Inventory Service")
|
||||
print("-" * 50)
|
||||
|
||||
ingredient_data = {
|
||||
"name": "Test Flour",
|
||||
"description": "Test ingredient for debugging",
|
||||
"category": "flour", # Use valid enum value
|
||||
"unit_of_measure": "kg", # Use correct field name
|
||||
"brand": "Test Supplier",
|
||||
"is_active": True
|
||||
}
|
||||
|
||||
ingredient_url = f"{GATEWAY_URL}/api/v1/tenants/{TENANT_ID}/ingredients"
|
||||
print(f"URL: {ingredient_url}")
|
||||
print(f"Data: {json.dumps(ingredient_data, indent=2)}")
|
||||
|
||||
try:
|
||||
response = await client.post(ingredient_url, json=ingredient_data, headers=headers)
|
||||
print(f"Status: {response.status_code}")
|
||||
print(f"Response: {response.text}")
|
||||
|
||||
if response.status_code == 201:
|
||||
print("✅ Direct ingredient creation SUCCESS!")
|
||||
created_ingredient = response.json()
|
||||
ingredient_id = created_ingredient.get('id')
|
||||
print(f"Created ingredient ID: {ingredient_id}")
|
||||
else:
|
||||
print("❌ Direct ingredient creation FAILED!")
|
||||
if response.status_code == 401:
|
||||
print("❌ Authentication failed - token might be expired")
|
||||
return
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Direct ingredient creation ERROR: {e}")
|
||||
|
||||
# Step 2: Test onboarding inventory creation endpoint
|
||||
print("\n2️⃣ Testing Onboarding Inventory Creation Endpoint")
|
||||
print("-" * 50)
|
||||
|
||||
# Create test suggestions like the frontend sends
|
||||
suggestions = [
|
||||
{
|
||||
"suggestion_id": str(uuid4()),
|
||||
"approved": True,
|
||||
"modifications": {},
|
||||
"original_name": "Pan",
|
||||
"suggested_name": "Pan",
|
||||
"product_type": "finished_product",
|
||||
"category": "other_products",
|
||||
"unit_of_measure": "units",
|
||||
"confidence_score": 0.9,
|
||||
"estimated_shelf_life_days": None,
|
||||
"requires_refrigeration": False,
|
||||
"requires_freezing": False,
|
||||
"is_seasonal": False,
|
||||
"suggested_supplier": None,
|
||||
"notes": "Test bread product"
|
||||
},
|
||||
{
|
||||
"suggestion_id": str(uuid4()),
|
||||
"approved": True,
|
||||
"modifications": {},
|
||||
"original_name": "Test Croissant",
|
||||
"suggested_name": "Test Croissant",
|
||||
"product_type": "finished_product",
|
||||
"category": "pastries",
|
||||
"unit_of_measure": "units",
|
||||
"confidence_score": 0.8,
|
||||
"estimated_shelf_life_days": 2,
|
||||
"requires_refrigeration": False,
|
||||
"requires_freezing": False,
|
||||
"is_seasonal": False,
|
||||
"suggested_supplier": "Test Bakery",
|
||||
"notes": "Test pastry product"
|
||||
}
|
||||
]
|
||||
|
||||
onboarding_data = {"suggestions": suggestions}
|
||||
onboarding_url = f"{GATEWAY_URL}/api/v1/tenants/{TENANT_ID}/onboarding/create-inventory"
|
||||
|
||||
print(f"URL: {onboarding_url}")
|
||||
print(f"Suggestions count: {len(suggestions)}")
|
||||
|
||||
try:
|
||||
response = await client.post(onboarding_url, json=onboarding_data, headers=headers)
|
||||
print(f"Status: {response.status_code}")
|
||||
print(f"Response: {response.text}")
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
print(f"✅ Onboarding inventory creation completed!")
|
||||
print(f"Created items: {len(result.get('created_items', []))}")
|
||||
print(f"Failed items: {len(result.get('failed_items', []))}")
|
||||
print(f"Success rate: {result.get('success_rate', 0)}")
|
||||
|
||||
if result.get('failed_items'):
|
||||
print("\n❌ Failed items details:")
|
||||
for item in result['failed_items']:
|
||||
print(f" - {item.get('suggestion_id')}: {item.get('error')}")
|
||||
|
||||
else:
|
||||
print("❌ Onboarding inventory creation FAILED!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Onboarding inventory creation ERROR: {e}")
|
||||
|
||||
# Step 3: Test service health
|
||||
print("\n3️⃣ Testing Service Health")
|
||||
print("-" * 50)
|
||||
|
||||
services = [
|
||||
("Gateway", f"{GATEWAY_URL}/health"),
|
||||
("Inventory Service", "http://localhost:8008/health"),
|
||||
("Sales Service", "http://localhost:8004/health")
|
||||
]
|
||||
|
||||
for service_name, health_url in services:
|
||||
try:
|
||||
response = await client.get(health_url)
|
||||
status = "✅ Healthy" if response.status_code == 200 else f"❌ Unhealthy ({response.status_code})"
|
||||
print(f"{service_name}: {status}")
|
||||
except Exception as e:
|
||||
print(f"{service_name}: ❌ Error - {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Starting onboarding flow debug test...")
|
||||
print("Make sure your services are running with docker-compose!")
|
||||
print()
|
||||
|
||||
asyncio.run(test_onboarding_flow())
|
||||
Reference in New Issue
Block a user