#!/bin/bash
# Simple test script for inventory processing API
# Usage: ./test_api.sh

echo "=== Testing Inventory Processing API ==="
echo ""

# Configuration
API_URL="http://localhost/api/inventory/processTransactions"
LOG_FILE="/var/www/html/TAF/logs/error.log"

echo "1. Testing API endpoint..."
echo "URL: $API_URL"
echo ""

# Make the request
response=$(curl -X POST "$API_URL" \
  -H "Content-Type: application/json" \
  -d '{}' \
  -w "\nHTTP_CODE:%{http_code}" \
  -s)

# Extract HTTP code
http_code=$(echo "$response" | grep "HTTP_CODE:" | cut -d':' -f2)
json_response=$(echo "$response" | sed '/HTTP_CODE:/d')

echo "HTTP Status: $http_code"
echo ""
echo "Response:"
echo "$json_response" | jq . 2>/dev/null || echo "$json_response"
echo ""

echo "2. Checking recent logs..."
if [ -f "$LOG_FILE" ]; then
    echo "Recent INVENTORY logs:"
    tail -n 100 "$LOG_FILE" | grep -i inventory | tail -n 20
else
    echo "Log file not found: $LOG_FILE"
fi

echo ""
echo "=== Test Complete ==="
