#!/bin/bash # HTTP Endpoint Testing Script for Phase 1 # Run this after starting the Svrnty.Sample application set -e BASE_URL="http://localhost:6001" GREEN='\033[0;32m' BLUE='\033[0;34m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${BLUE}================================${NC}" echo -e "${BLUE}Phase 1 HTTP Endpoint Tests${NC}" echo -e "${BLUE}================================${NC}" echo "" # Check if server is running echo -e "${YELLOW}Checking if server is running...${NC}" if ! curl -s --fail "${BASE_URL}/swagger" > /dev/null; then echo "❌ Server is not running on ${BASE_URL}" echo "Please start the application first: cd Svrnty.Sample && dotnet run" exit 1 fi echo -e "${GREEN}✓ Server is running${NC}" echo "" # Test 1: Add User Command echo -e "${YELLOW}Test 1: Add User Command${NC}" echo "POST ${BASE_URL}/api/command/addUser" RESPONSE=$(curl -s -X POST "${BASE_URL}/api/command/addUser" \ -H "Content-Type: application/json" \ -d '{ "name": "John Doe", "email": "john@example.com" }') echo "Response: ${RESPONSE}" if [ -n "$RESPONSE" ] && [ "$RESPONSE" -gt 0 ] 2>/dev/null; then echo -e "${GREEN}✓ Test 1 passed: User created with ID ${RESPONSE}${NC}" else echo -e "❌ Test 1 failed: Unexpected response" fi echo "" # Test 2: Invite User Command echo -e "${YELLOW}Test 2: Invite User Command${NC}" echo "POST ${BASE_URL}/api/command/inviteUser" INVITATION_ID=$(curl -s -X POST "${BASE_URL}/api/command/inviteUser" \ -H "Content-Type: application/json" \ -d '{ "email": "jane@example.com", "inviterName": "Admin" }' | tr -d '"') echo "Invitation ID: ${INVITATION_ID}" if [ -n "$INVITATION_ID" ]; then echo -e "${GREEN}✓ Test 2 passed: Invitation created with ID ${INVITATION_ID}${NC}" else echo -e "❌ Test 2 failed: No invitation ID returned" fi echo "" # Test 3: Accept Invitation echo -e "${YELLOW}Test 3: Accept Invitation${NC}" echo "POST ${BASE_URL}/api/command/acceptInvite" ACCEPT_RESPONSE=$(curl -s -X POST "${BASE_URL}/api/command/acceptInvite" \ -H "Content-Type: application/json" \ -d "{ \"invitationId\": \"${INVITATION_ID}\", \"email\": \"jane@example.com\", \"name\": \"Jane Doe\" }") echo "Response: ${ACCEPT_RESPONSE}" if [ -n "$ACCEPT_RESPONSE" ] && [ "$ACCEPT_RESPONSE" -gt 0 ] 2>/dev/null; then echo -e "${GREEN}✓ Test 3 passed: Invitation accepted, User ID ${ACCEPT_RESPONSE}${NC}" else echo -e "❌ Test 3 failed: Unexpected response" fi echo "" # Test 4: Multiple Events (Broadcast Test) echo -e "${YELLOW}Test 4: Multiple Events (Testing Broadcast Mode)${NC}" echo "Adding 5 users in sequence..." for i in {1..5}; do RESPONSE=$(curl -s -X POST "${BASE_URL}/api/command/addUser" \ -H "Content-Type: application/json" \ -d "{\"name\": \"User $i\", \"email\": \"user$i@example.com\"}") echo " User $i created with ID: ${RESPONSE}" sleep 0.5 done echo -e "${GREEN}✓ Test 4 passed: 5 events generated${NC}" echo -e "${BLUE}Check the application logs to verify EventConsumerBackgroundService received all 5 events${NC}" echo "" # Test 5: Validation Error echo -e "${YELLOW}Test 5: Validation Error (Invalid Command)${NC}" echo "POST ${BASE_URL}/api/command/addUser (empty body)" VALIDATION_RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" -X POST "${BASE_URL}/api/command/addUser" \ -H "Content-Type: application/json" \ -d '{}') HTTP_STATUS=$(echo "$VALIDATION_RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2) if [ "$HTTP_STATUS" = "400" ]; then echo -e "${GREEN}✓ Test 5 passed: Validation error returned HTTP 400${NC}" else echo -e "❌ Test 5 failed: Expected HTTP 400, got ${HTTP_STATUS}" fi echo "" # Test 6: Query Endpoint echo -e "${YELLOW}Test 6: Query Endpoint${NC}" echo "GET ${BASE_URL}/api/query/fetchUser?userId=1234" QUERY_RESPONSE=$(curl -s "${BASE_URL}/api/query/fetchUser?userId=1234") echo "Response: ${QUERY_RESPONSE}" if echo "$QUERY_RESPONSE" | grep -q "userId"; then echo -e "${GREEN}✓ Test 6 passed: Query endpoint works${NC}" else echo -e "❌ Test 6 failed: Unexpected response" fi echo "" # Test 7: Decline Invitation echo -e "${YELLOW}Test 7: Decline Invitation${NC}" echo "Creating new invitation..." INVITATION_ID_2=$(curl -s -X POST "${BASE_URL}/api/command/inviteUser" \ -H "Content-Type: application/json" \ -d '{ "email": "bob@example.com", "inviterName": "Admin" }' | tr -d '"') echo "Invitation ID: ${INVITATION_ID_2}" echo "Declining invitation..." curl -s -X POST "${BASE_URL}/api/command/declineInvite" \ -H "Content-Type: application/json" \ -d "{ \"invitationId\": \"${INVITATION_ID_2}\", \"reason\": \"Not interested\" }" > /dev/null echo -e "${GREEN}✓ Test 7 passed: Invitation declined${NC}" echo "" # Summary echo -e "${BLUE}================================${NC}" echo -e "${BLUE}Test Summary${NC}" echo -e "${BLUE}================================${NC}" echo -e "All HTTP endpoint tests completed!" echo -e "" echo -e "${YELLOW}Next Steps:${NC}" echo -e "1. Check application logs to verify events were received by EventConsumerBackgroundService" echo -e "2. Run gRPC tests: ./test-grpc-endpoints.sh" echo -e "3. Review full test results in PHASE1-TESTING-GUIDE.md" echo ""