-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_functions.sh
More file actions
executable file
·145 lines (127 loc) · 4.77 KB
/
test_functions.sh
File metadata and controls
executable file
·145 lines (127 loc) · 4.77 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
#!/bin/bash
# Variables
API_BASE_URL="https://checklist-api.codein.ca/api"
GITHUB_USER_ID="test-user-123"
# Generate a unique checklist ID for each run to avoid conflicts
CHECKLIST_ID="test-checklist-$(date +%s)"
# Color coding for better readability
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}=== Testing Azure Functions API ===${NC}"
echo "Base URL: $API_BASE_URL"
echo "GitHub User ID: $GITHUB_USER_ID"
echo "Checklist ID: $CHECKLIST_ID"
echo ""
# 1. Test addChecklist - Create a new checklist
echo -e "${BLUE}1. Testing addChecklist (POST) - Creating a new checklist${NC}"
add_response=$(curl -s -X POST "$API_BASE_URL/checklist" \
-H "Content-Type: application/json" \
-H "x-github-user-id: $GITHUB_USER_ID" \
-d "{
\"checklistName\": \"$CHECKLIST_ID\",
\"content\": {
\"sections\": [
{
\"title\": \"Section 1\",
\"items\": [
{\"text\": \"Task 1\", \"isCompleted\": false},
{\"text\": \"Task 2\", \"isCompleted\": false}
]
}
],
\"lastUpdated\": \"$(date -u +"%Y-%m-%dT%H:%M:%SZ")\"
}
}")
echo "Response: $add_response"
if [[ $add_response == *"saved successfully"* ]]; then
echo -e "${GREEN}✓ addChecklist test passed${NC}"
else
echo -e "${RED}✗ addChecklist test failed${NC}"
fi
echo ""
# 2. Test getAllChecklists - Retrieve all checklist IDs for the user
echo -e "${BLUE}2. Testing getAllChecklists (GET) - Retrieving all checklist IDs${NC}"
ids_response=$(curl -s -X GET "$API_BASE_URL/checklists" \
-H "x-github-user-id: $GITHUB_USER_ID")
echo "Response: $ids_response"
if [[ $ids_response == *"$CHECKLIST_ID"* ]]; then
echo -e "${GREEN}✓ getAllChecklists test passed${NC}"
else
echo -e "${RED}✗ getAllChecklists test failed${NC}"
fi
echo ""
# 3. Test getChecklist - Retrieve a single checklist by name
echo -e "${BLUE}3. Testing getChecklist (GET) - Retrieving a single checklist${NC}"
get_response=$(curl -s -X GET "$API_BASE_URL/checklist/$CHECKLIST_ID" \
-H "x-github-user-id: $GITHUB_USER_ID")
echo "Response: $get_response"
if [[ $get_response == *"$CHECKLIST_ID"* && $get_response == *"Section 1"* ]]; then
echo -e "${GREEN}✓ getChecklist test passed${NC}"
else
echo -e "${RED}✗ getChecklist test failed${NC}"
fi
echo ""
# 4. Test updateChecklist - Update an existing checklist
echo -e "${BLUE}4. Testing updateChecklist (PUT) - Updating a checklist${NC}"
update_response=$(curl -s -X PUT "$API_BASE_URL/checklist" \
-H "Content-Type: application/json" \
-H "x-github-user-id: $GITHUB_USER_ID" \
-d "{
\"checklistName\": \"$CHECKLIST_ID\",
\"content\": {
\"sections\": [
{
\"title\": \"Section 1 Updated\",
\"items\": [
{\"text\": \"Task 1\", \"isCompleted\": true},
{\"text\": \"Task 2\", \"isCompleted\": false},
{\"text\": \"Task 3\", \"isCompleted\": false}
]
}
],
\"lastUpdated\": \"$(date -u +"%Y-%m-%dT%H:%M:%SZ")\"
}
}")
echo "Response: $update_response"
if [[ $update_response == *"updated successfully"* ]]; then
echo -e "${GREEN}✓ updateChecklist test passed${NC}"
else
echo -e "${RED}✗ updateChecklist test failed${NC}"
fi
echo ""
# 5. Verify update - Get the updated checklist
echo -e "${BLUE}5. Verifying update - Getting the updated checklist${NC}"
verify_update_response=$(curl -s -X GET "$API_BASE_URL/checklist/$CHECKLIST_ID" \
-H "x-github-user-id: $GITHUB_USER_ID")
echo "Response: $verify_update_response"
if [[ $verify_update_response == *"Section 1 Updated"* && $verify_update_response == *"Task 3"* ]]; then
echo -e "${GREEN}✓ Update verification test passed${NC}"
else
echo -e "${RED}✗ Update verification test failed${NC}"
fi
echo ""
# 6. Test deleteChecklist - Delete a specific checklist
echo -e "${BLUE}6. Testing deleteChecklist (DELETE) - Deleting a checklist${NC}"
delete_response=$(curl -s -X DELETE "$API_BASE_URL/checklist?userId=$GITHUB_USER_ID&checklistName=$CHECKLIST_ID" \
-H "x-github-user-id: $GITHUB_USER_ID")
echo "Response: $delete_response"
if [[ $delete_response == *"deleted successfully"* ]]; then
echo -e "${GREEN}✓ deleteChecklist test passed${NC}"
else
echo -e "${RED}✗ deleteChecklist test failed${NC}"
fi
echo ""
# 7. Verify deletion - Check IDs list again
echo -e "${BLUE}7. Verifying deletion - Checking IDs list again${NC}"
verify_response=$(curl -s -X GET "$API_BASE_URL/checklists" \
-H "x-github-user-id: $GITHUB_USER_ID")
echo "Response: $verify_response"
if [[ $verify_response != *"$CHECKLIST_ID"* ]]; then
echo -e "${GREEN}✓ Deletion verification test passed - Checklist was properly deleted${NC}"
else
echo -e "${RED}✗ Deletion verification test failed - Checklist still exists${NC}"
fi
echo ""
echo -e "${BLUE}All tests completed.${NC}"