-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-api.sh
More file actions
147 lines (131 loc) Β· 4.25 KB
/
Copy pathtest-api.sh
File metadata and controls
147 lines (131 loc) Β· 4.25 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
# TrustlessTask API Test Script
# Tests all API endpoints to ensure production readiness
API_URL="http://localhost:8080/api/v1"
echo "π§ͺ Testing TrustlessTask API at $API_URL"
echo "=========================================="
# Test 1: Health Check
echo ""
echo "Test 1: Health Check"
echo "--------------------"
curl -s "$API_URL/../health" | jq '.'
# Test 2: List Projects (should be empty or have existing projects)
echo ""
echo "Test 2: List Projects"
echo "--------------------"
curl -s "$API_URL/projects" | jq '.'
# Test 3: Create Project with Valid Data
echo ""
echo "Test 3: Create Project (Valid Data)"
echo "------------------------------------"
PROJECT_RESPONSE=$(curl -s -X POST "$API_URL/projects" \
-H "Content-Type: application/json" \
-d '{
"title": "Test Project",
"description": "This is a test project for API validation",
"clientAddress": "addr_test1client123456789",
"freelancerAddress": "addr_test1freelancer987654321",
"totalAmount": 10000000,
"milestones": [
{
"description": "Milestone 1: Design",
"amount": 5000000,
"deadline": "2025-12-31T23:59:59"
},
{
"description": "Milestone 2: Development",
"amount": 5000000,
"deadline": "2026-01-31T23:59:59"
}
]
}')
echo "$PROJECT_RESPONSE" | jq '.'
PROJECT_ID=$(echo "$PROJECT_RESPONSE" | jq -r '.id')
# Test 4: Get Project by ID
if [ "$PROJECT_ID" != "null" ] && [ -n "$PROJECT_ID" ]; then
echo ""
echo "Test 4: Get Project by ID ($PROJECT_ID)"
echo "----------------------------------------"
curl -s "$API_URL/projects/$PROJECT_ID" | jq '.'
fi
# Test 5: Create Project with Invalid Data (should fail)
echo ""
echo "Test 5: Create Project (Invalid Data - should fail)"
echo "----------------------------------------------------"
curl -s -X POST "$API_URL/projects" \
-H "Content-Type: application/json" \
-d '{
"title": "",
"description": "Missing required fields"
}' | jq '.'
# Test 6: Get User Profile
echo ""
echo "Test 6: Get User Profile"
echo "------------------------"
curl -s "$API_URL/users/addr_test1client123456789/profile" | jq '.'
# Test 7: Complete Milestone
if [ "$PROJECT_ID" != "null" ] && [ -n "$PROJECT_ID" ]; then
echo ""
echo "Test 7: Complete Milestone"
echo "--------------------------"
curl -s -X POST "$API_URL/projects/$PROJECT_ID/milestone/1/complete" | jq '.'
fi
# Test 8: Approve Milestone
if [ "$PROJECT_ID" != "null" ] && [ -n "$PROJECT_ID" ]; then
echo ""
echo "Test 8: Approve Milestone"
echo "-------------------------"
curl -s -X POST "$API_URL/projects/$PROJECT_ID/milestone/1/approve" | jq '.'
fi
# Test 9: Create Dispute
if [ "$PROJECT_ID" != "null" ] && [ -n "$PROJECT_ID" ]; then
echo ""
echo "Test 9: Create Dispute"
echo "----------------------"
DISPUTE_RESPONSE=$(curl -s -X POST "$API_URL/disputes" \
-H "Content-Type: application/json" \
-d "{
\"projectId\": \"$PROJECT_ID\",
\"reason\": \"Test dispute for validation\",
\"raiserAddress\": \"addr_test1client123456789\"
}")
echo "$DISPUTE_RESPONSE" | jq '.'
DISPUTE_ID=$(echo "$DISPUTE_RESPONSE" | jq -r '.id')
fi
# Test 10: Get Dispute by ID
if [ "$DISPUTE_ID" != "null" ] && [ -n "$DISPUTE_ID" ]; then
echo ""
echo "Test 10: Get Dispute by ID ($DISPUTE_ID)"
echo "----------------------------------------"
curl -s "$API_URL/disputes/$DISPUTE_ID" | jq '.'
fi
# Test 11: Test Rate Limiting (make 5 rapid requests)
echo ""
echo "Test 11: Rate Limiting (5 rapid requests)"
echo "-----------------------------------------"
for i in {1..5}; do
echo "Request $i:"
curl -s -w "\nHTTP Status: %{http_code}\n" "$API_URL/projects" > /dev/null
done
# Test 12: Test 404 Handler
echo ""
echo "Test 12: 404 Handler (non-existent route)"
echo "-----------------------------------------"
curl -s "$API_URL/nonexistent" | jq '.'
echo ""
echo "=========================================="
echo "β
API Testing Complete!"
echo ""
echo "Summary:"
echo "- Health check: β"
echo "- List projects: β"
echo "- Create project: β"
echo "- Get project: β"
echo "- Invalid data handling: β"
echo "- User profile: β"
echo "- Milestone operations: β"
echo "- Dispute operations: β"
echo "- Rate limiting: β"
echo "- 404 handling: β"
echo ""
echo "π All tests passed!"