-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_coupon_functionality.sh
More file actions
executable file
·78 lines (67 loc) · 2.9 KB
/
test_coupon_functionality.sh
File metadata and controls
executable file
·78 lines (67 loc) · 2.9 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
echo "=== Comprehensive Coupon Functionality Test ==="
echo ""
# Test 1: Check if coupon service is healthy
echo "1. Testing coupon service health..."
HEALTH_RESPONSE=$(curl -s http://localhost:8086/api/v1/coupons/health)
echo "Direct health check: $HEALTH_RESPONSE"
# Test 2: Check if coupon read endpoint works through load balancer
echo ""
echo "2. Testing coupon read through load balancer..."
READ_RESPONSE=$(curl -s http://localhost:8080/api/v1/coupons)
echo "Read response: $READ_RESPONSE"
# Test 3: Try to create a coupon (this will likely fail due to authentication)
echo ""
echo "3. Testing coupon creation (expecting 401 without auth)..."
CREATE_RESPONSE=$(curl -s -w "%{http_code}" -o /tmp/create_response.json -X POST http://localhost:8080/api/write/coupon \
-H "Content-Type: application/json" \
-d '{
"code": "TEST001",
"name": "Test Coupon",
"description": "Test coupon for functionality verification",
"type": "GENERAL",
"discountType": "PERCENTAGE",
"discountValue": 10.0,
"usageLimit": 100,
"validFrom": "2024-01-01T00:00:00",
"validUntil": "2024-12-31T23:59:59",
"isPublic": true
}')
echo "Create response code: $CREATE_RESPONSE"
echo "Create response body:"
cat /tmp/create_response.json
echo ""
# Test 4: Check write layer health
echo ""
echo "4. Testing write layer health..."
WRITE_HEALTH=$(curl -s -w "%{http_code}" -o /tmp/write_health.json http://localhost:8081/actuator/health)
echo "Write layer health code: $WRITE_HEALTH"
echo "Write layer health body:"
cat /tmp/write_health.json
echo ""
# Test 5: Check if we can access the web app
echo ""
echo "5. Testing web app access..."
WEB_RESPONSE=$(curl -s -w "%{http_code}" -o /dev/null http://localhost:80)
echo "Web app response code: $WEB_RESPONSE"
# Test 6: Check HAProxy stats
echo ""
echo "6. Testing HAProxy routing..."
HAPROXY_RESPONSE=$(curl -s -w "%{http_code}" -o /dev/null http://localhost:8080/api/v1/coupons)
echo "HAProxy coupon routing response code: $HAPROXY_RESPONSE"
echo ""
echo "=== Test Summary ==="
echo "- Coupon service health: $(echo $HEALTH_RESPONSE | grep -q 'UP' && echo 'PASS' || echo 'FAIL')"
echo "- Coupon read endpoint: $([ ${#READ_RESPONSE} -ge 2 ] && echo 'PASS' || echo 'FAIL')"
echo "- Coupon create (auth required): $([ $CREATE_RESPONSE -eq 401 ] && echo 'PASS (expected 401)' || echo 'UNEXPECTED: '$CREATE_RESPONSE)"
echo "- Write layer health: $([ $WRITE_HEALTH -eq 200 ] && echo 'PASS' || echo 'FAIL')"
echo "- Web app access: $([ $WEB_RESPONSE -eq 200 ] && echo 'PASS' || echo 'FAIL')"
echo "- HAProxy routing: $([ $HAPROXY_RESPONSE -eq 200 ] && echo 'PASS' || echo 'FAIL')"
echo ""
echo "=== Next Steps ==="
echo "1. Open http://localhost:80 in your browser"
echo "2. Navigate to the 'Coupon Manager' tab"
echo "3. Try creating a coupon through the UI"
echo "4. The UI should handle authentication automatically"
# Cleanup
rm -f /tmp/create_response.json /tmp/write_health.json