#!/bin/bash
# Test script for get_invoice_detail tool
# This tests the invoice detail loading functionality with context
set -e
echo "=== Testing Get Invoice Detail Tool ==="
echo ""
# Configuration
API_URL="${API_URL:-http://localhost:8000}"
BEARER_TOKEN="${BEARER_TOKEN:-your_token_here}"
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Test 1: Load invoice context (empty message)
echo -e "${YELLOW}Test 1: Load invoice context with empty message${NC}"
curl -X POST "${API_URL}/chat" \
-H "Authorization: Bearer ${BEARER_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"message": "",
"page_context": {
"page_type": "invoice_detail",
"entity_type": "invoice",
"entity_id": "12345"
}
}' | jq '.'
echo ""
# Test 2: Load invoice context with specific question
echo -e "${YELLOW}Test 2: Load invoice context with question${NC}"
curl -X POST "${API_URL}/chat" \
-H "Authorization: Bearer ${BEARER_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"message": "What is the total amount for this invoice?",
"page_context": {
"page_type": "invoice_detail",
"entity_type": "invoice",
"entity_id": "12345"
}
}' | jq '.'
echo ""
# Test 3: Invalid invoice ID
echo -e "${YELLOW}Test 3: Invalid invoice ID${NC}"
curl -X POST "${API_URL}/chat" \
-H "Authorization: Bearer ${BEARER_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"message": "",
"page_context": {
"page_type": "invoice_detail",
"entity_type": "invoice",
"entity_id": "999999"
}
}' | jq '.'
echo ""
# Test 4: Wrong page type (should not load invoice)
echo -e "${YELLOW}Test 4: Wrong page type${NC}"
curl -X POST "${API_URL}/chat" \
-H "Authorization: Bearer ${BEARER_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"message": "",
"page_context": {
"page_type": "dashboard",
"entity_type": "invoice",
"entity_id": "12345"
}
}' | jq '.'
echo ""
# Test 5: Missing entity type
echo -e "${YELLOW}Test 5: Missing entity type${NC}"
curl -X POST "${API_URL}/chat" \
-H "Authorization: Bearer ${BEARER_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"message": "",
"page_context": {
"page_type": "invoice_detail",
"entity_id": "12345"
}
}' | jq '.'
echo ""
# Test 6: Missing entity ID
echo -e "${YELLOW}Test 6: Missing entity ID${NC}"
curl -X POST "${API_URL}/chat" \
-H "Authorization: Bearer ${BEARER_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"message": "",
"page_context": {
"page_type": "invoice_detail",
"entity_type": "invoice"
}
}' | jq '.'
echo ""
# Test 7: With page state
echo -e "${YELLOW}Test 7: With page state${NC}"
curl -X POST "${API_URL}/chat" \
-H "Authorization: Bearer ${BEARER_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"message": "",
"page_context": {
"page_type": "invoice_detail",
"entity_type": "invoice",
"entity_id": "12345",
"page_state": {
"tab": "details",
"mode": "view"
}
}
}' | jq '.'
echo ""
echo -e "${GREEN}=== All tests completed ===${NC}"