#!/bin/bash
# Test script for list_invoices tool
# This tests the invoice listing functionality with various filters
set -e
echo "=== Testing List Invoices 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: Basic invoice listing
echo -e "${YELLOW}Test 1: Basic invoice listing (first page)${NC}"
curl -X POST "${API_URL}/chat" \
-H "Authorization: Bearer ${BEARER_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"message": "List all invoices",
"page_context": {
"page_type": "invoice_table"
}
}' | jq '.'
echo ""
# Test 2: Filter by status
echo -e "${YELLOW}Test 2: Filter invoices by status (approved)${NC}"
curl -X POST "${API_URL}/chat" \
-H "Authorization: Bearer ${BEARER_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"message": "Show me approved invoices",
"page_context": {
"page_type": "invoice_table"
}
}' | jq '.'
echo ""
# Test 3: Dashboard filter - Due Today
echo -e "${YELLOW}Test 3: Dashboard filter - Invoices due today${NC}"
curl -X POST "${API_URL}/chat" \
-H "Authorization: Bearer ${BEARER_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"message": "Show invoices due today",
"page_context": {
"page_type": "invoice_table"
}
}' | jq '.'
echo ""
# Test 4: Filter by vendor name
echo -e "${YELLOW}Test 4: Filter by vendor name${NC}"
curl -X POST "${API_URL}/chat" \
-H "Authorization: Bearer ${BEARER_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"message": "Show invoices from ABC Supplies",
"page_context": {
"page_type": "invoice_table"
}
}' | jq '.'
echo ""
# Test 5: Pagination
echo -e "${YELLOW}Test 5: Pagination (page 2, 25 items per page)${NC}"
curl -X POST "${API_URL}/chat" \
-H "Authorization: Bearer ${BEARER_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"message": "Show me page 2 of invoices with 25 items per page",
"page_context": {
"page_type": "invoice_table"
}
}' | jq '.'
echo ""
# Test 6: Date range filter
echo -e "${YELLOW}Test 6: Date range filter${NC}"
curl -X POST "${API_URL}/chat" \
-H "Authorization: Bearer ${BEARER_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"message": "Show invoices due between 01-01-2024 and 01-31-2024",
"page_context": {
"page_type": "invoice_table"
}
}' | jq '.'
echo ""
# Test 7: Wrong page context (should fail)
echo -e "${YELLOW}Test 7: Wrong page context (should fail - tool not available)${NC}"
curl -X POST "${API_URL}/chat" \
-H "Authorization: Bearer ${BEARER_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"message": "List all invoices",
"page_context": {
"page_type": "dashboard"
}
}' | jq '.'
echo ""
echo -e "${GREEN}=== All tests completed ===${NC}"