-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-structure.sh
More file actions
executable file
·149 lines (132 loc) · 4.07 KB
/
validate-structure.sh
File metadata and controls
executable file
·149 lines (132 loc) · 4.07 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
148
149
#!/bin/bash
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
API_URL="https://api.anuragd.me"
PASSED=0
FAILED=0
echo "=========================================="
echo "API Structure Validation"
echo "=========================================="
# Test public endpoints
echo -e "\n${YELLOW}Testing Public Endpoints...${NC}"
# Root endpoint
response=$(curl -s -w "\n%{http_code}" "$API_URL/")
status=$(echo "$response" | tail -n1)
if [ "$status" = "200" ]; then
echo -e "${GREEN}✓${NC} Root endpoint (/) - Status: 200"
PASSED=$((PASSED + 1))
else
echo -e "${RED}✗${NC} Root endpoint (/) - Status: $status"
FAILED=$((FAILED + 1))
fi
# OpenAPI spec
response=$(curl -s -w "\n%{http_code}" "$API_URL/openapi.json")
status=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$status" = "200" ]; then
# Check if it has the base URL
if echo "$body" | grep -q "api.anuragd.me"; then
echo -e "${GREEN}✓${NC} OpenAPI spec (/openapi.json) - Status: 200, Base URL configured"
PASSED=$((PASSED + 1))
else
echo -e "${YELLOW}⚠${NC} OpenAPI spec (/openapi.json) - Status: 200, but base URL might be missing"
PASSED=$((PASSED + 1))
fi
else
echo -e "${RED}✗${NC} OpenAPI spec (/openapi.json) - Status: $status"
FAILED=$((FAILED + 1))
fi
# Test authentication on protected endpoints
echo -e "\n${YELLOW}Testing Authentication...${NC}"
endpoints=(
"/health"
"/v1/profile"
"/v1/projects"
"/v1/shelf"
"/v1/uses"
"/v1/wakatime"
"/v1/github"
"/v1/health"
)
for endpoint in "${endpoints[@]}"; do
response=$(curl -s -w "\n%{http_code}" "$API_URL$endpoint")
status=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
# Should return 401 (missing auth) or 403 (invalid token)
if [ "$status" = "401" ] || [ "$status" = "403" ]; then
echo -e "${GREEN}✓${NC} $endpoint - Auth required (Status: $status)"
PASSED=$((PASSED + 1))
else
echo -e "${RED}✗${NC} $endpoint - Unexpected status: $status"
echo " Response: $body"
FAILED=$((FAILED + 1))
fi
done
# Test TypeScript compilation
echo -e "\n${YELLOW}Testing TypeScript Compilation...${NC}"
cd /Users/aarekaz/Development/api
if npx tsc --noEmit 2>&1 | grep -q "error TS"; then
echo -e "${RED}✗${NC} TypeScript compilation has errors"
FAILED=$((FAILED + 1))
else
echo -e "${GREEN}✓${NC} TypeScript compilation successful"
PASSED=$((PASSED + 1))
fi
# Check file structure
echo -e "\n${YELLOW}Checking File Structure...${NC}"
required_files=(
"src/index.ts"
"src/types/env.ts"
"src/types/common.ts"
"src/middleware/auth.ts"
"src/utils/date.ts"
"src/utils/json.ts"
"src/utils/response.ts"
"src/utils/validation.ts"
"src/utils/normalizers.ts"
"src/schemas/common.ts"
"src/schemas/profile.ts"
"src/schemas/content.ts"
"src/schemas/health.ts"
"src/schemas/openapi.ts"
"src/services/wakatime.ts"
"src/services/github.ts"
"src/services/lanyard.ts"
"src/routes/profile.ts"
"src/routes/shelf.ts"
"src/routes/uses.ts"
"src/routes/wakatime.ts"
"src/routes/github.ts"
"src/routes/health-data.ts"
"src/scheduled.ts"
)
for file in "${required_files[@]}"; do
if [ -f "$file" ]; then
echo -e "${GREEN}✓${NC} $file exists"
PASSED=$((PASSED + 1))
else
echo -e "${RED}✗${NC} $file missing"
FAILED=$((FAILED + 1))
fi
done
# Summary
TOTAL=$((PASSED + FAILED))
SUCCESS_RATE=$(awk "BEGIN {printf \"%.1f\", ($PASSED/$TOTAL)*100}")
echo -e "\n=========================================="
echo -e "VALIDATION SUMMARY"
echo -e "=========================================="
echo -e "Total Checks: $TOTAL"
echo -e "${GREEN}Passed: $PASSED${NC}"
echo -e "${RED}Failed: $FAILED${NC}"
echo -e "Success Rate: ${SUCCESS_RATE}%"
echo -e "=========================================="
if [ $FAILED -eq 0 ]; then
echo -e "${GREEN}✓ All validation checks passed!${NC}"
exit 0
else
echo -e "${RED}✗ Some validation checks failed${NC}"
exit 1
fi