-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.sh
More file actions
executable file
·59 lines (49 loc) · 1.59 KB
/
test-api.sh
File metadata and controls
executable file
·59 lines (49 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# Test script for Jura API Server
set -e
echo "Starting Jura API Server Test Suite"
echo "===================================="
echo ""
# Start server
cd "$(dirname "$0")/build"
timeout 60 ./jura-api-server 8080 > /tmp/jura-server.log 2>&1 &
SERVER_PID=$!
sleep 2
echo "Server started with PID: $SERVER_PID"
echo ""
# Test function
test_endpoint() {
local name="$1"
local method="$2"
local endpoint="$3"
local data="$4"
echo "Testing: $name"
if [ "$method" = "GET" ]; then
response=$(curl -s "http://localhost:8080$endpoint")
else
response=$(curl -s -X "$method" "http://localhost:8080$endpoint" \
-H "Content-Type: application/json" \
-d "$data")
fi
echo "Response: $response"
echo ""
}
# Run tests
test_endpoint "Health Check" "GET" "/health" ""
test_endpoint "API Documentation" "GET" "/api" ""
test_endpoint "Initial Status" "GET" "/api/status" ""
test_endpoint "Connect to Device" "POST" "/api/connect" '{"device_address":"AA:BB:CC:DD:EE:FF"}'
test_endpoint "Status After Connection" "GET" "/api/status" ""
test_endpoint "Device Info" "GET" "/api/device-info" ""
test_endpoint "Brew Coffee" "POST" "/api/brew" '{"product":"espresso"}'
test_endpoint "Send Custom Command" "POST" "/api/command" '{"command":"TEST_COMMAND"}'
test_endpoint "Disconnect" "POST" "/api/disconnect" ""
test_endpoint "Status After Disconnect" "GET" "/api/status" ""
# Stop server
kill $SERVER_PID 2>/dev/null
wait $SERVER_PID 2>/dev/null || true
echo "All tests completed!"
echo ""
echo "Server logs:"
echo "============"
cat /tmp/jura-server.log