Refactor API endpoints for consistency and clarity

- Updated route paths for hackathon submissions, notifications, registrations, and teams to include more descriptive actions (e.g., "update", "create", "delete").
- Removed deprecated routes and adjusted corresponding test cases to reflect new endpoint structures.
- Enhanced test scripts to ensure compatibility with updated API routes and improved error handling for OTP resend functionality.
- Adjusted server startup script for better Windows compatibility and streamlined process management.
This commit is contained in:
MythEclipse
2025-10-29 14:27:07 +07:00
parent 98c46611fb
commit 97c2fce7be
19 changed files with 361 additions and 155 deletions
+18 -18
View File
@@ -29,12 +29,12 @@ test_hackathon_endpoints() {
],
organizers: [$user_id]
}')
local create_hackathon_response=$(test_api_endpoint "POST Create Hackathon" "POST" "/v1/hackathons" 201 "$create_hackathon_data" true)
local create_hackathon_response=$(test_api_endpoint "POST Create Hackathon" "POST" "/v1/hackathons/create" 201 "$create_hackathon_data" true)
local created_hackathon_id=$(echo "$create_hackathon_response" | jq -r '.data.id // empty')
if [ -n "$created_hackathon_id" ]; then
# Get hackathon by ID
test_api_endpoint "GET Hackathon By ID" "GET" "/v1/hackathons/$created_hackathon_id" 200 "" false
# Get hackathon by ID (requires auth)
test_api_endpoint "GET Hackathon By ID" "GET" "/v1/hackathons/detail/$created_hackathon_id" 200 "" true
# Update hackathon
local update_hackathon_data=$(jq -n '{
@@ -42,7 +42,7 @@ test_hackathon_endpoints() {
description: "Updated description",
max_teams: 150
}')
test_api_endpoint "PUT Update Hackathon" "PUT" "/v1/hackathons/$created_hackathon_id" 200 "$update_hackathon_data" true
test_api_endpoint "PUT Update Hackathon" "PUT" "/v1/hackathons/update/$created_hackathon_id" 200 "$update_hackathon_data" true
# === Hackathon Events ===
local create_event_data=$(jq -n --arg hackathon_id "$created_hackathon_id" '{
@@ -56,7 +56,7 @@ test_hackathon_endpoints() {
event_type: "workshop",
is_mandatory: true
}')
local create_event_response=$(test_api_endpoint "POST Create Hackathon Event" "POST" "/v1/hackathons/$created_hackathon_id/events" 201 "$create_event_data" true)
local create_event_response=$(test_api_endpoint "POST Create Hackathon Event" "POST" "/v1/hackathons/$created_hackathon_id/events/create" 201 "$create_event_data" true)
local created_event_id=$(echo "$create_event_response" | jq -r '.data.id // empty')
if [ -n "$created_event_id" ]; then
@@ -66,10 +66,10 @@ test_hackathon_endpoints() {
description: "Updated description",
is_mandatory: false
}')
test_api_endpoint "PUT Update Hackathon Event" "PUT" "/v1/hackathons/events/$created_event_id" 200 "$update_event_data" true
test_api_endpoint "PUT Update Hackathon Event" "PUT" "/v1/hackathons/events/update/$created_event_id" 200 "$update_event_data" true
# Delete event
test_api_endpoint "DELETE Hackathon Event" "DELETE" "/v1/hackathons/events/$created_event_id" 200 "" true
test_api_endpoint "DELETE Hackathon Event" "DELETE" "/v1/hackathons/events/delete/$created_event_id" 200 "" true
fi
# === Hackathon Timeline ===
@@ -82,7 +82,7 @@ test_hackathon_endpoints() {
end_date: "'$(date -u -d '+2 days' +%Y-%m-%dT%H:%M:%SZ)'",
allowed_operations: ["REGISTER", "FORM_TEAM"]
}')
local create_timeline_response=$(test_api_endpoint "POST Create Timeline" "POST" "/v1/hackathons/$created_hackathon_id/timeline" 201 "$create_timeline_data" true)
local create_timeline_response=$(test_api_endpoint "POST Create Timeline" "POST" "/v1/hackathons/$created_hackathon_id/timeline/create" 201 "$create_timeline_data" true)
local created_timeline_id=$(echo "$create_timeline_response" | jq -r '.data.id // empty')
if [ -n "$created_timeline_id" ]; then
@@ -92,10 +92,10 @@ test_hackathon_endpoints() {
phase_name: "Updated Registration Phase",
description: "Updated description"
}')
test_api_endpoint "PUT Update Timeline" "PUT" "/v1/hackathons/timeline/$created_timeline_id" 200 "$update_timeline_data" true
test_api_endpoint "PUT Update Timeline" "PUT" "/v1/hackathons/timeline/update/$created_timeline_id" 200 "$update_timeline_data" true
# Delete timeline
test_api_endpoint "DELETE Timeline" "DELETE" "/v1/hackathons/timeline/$created_timeline_id" 200 "" true
test_api_endpoint "DELETE Timeline" "DELETE" "/v1/hackathons/timeline/delete/$created_timeline_id" 200 "" true
fi
# === Hackathon Participants ===
@@ -107,7 +107,7 @@ test_hackathon_endpoints() {
user_id: $user_id,
role: "participant"
}')
test_api_endpoint "POST Register Participant" "POST" "/v1/hackathons/$created_hackathon_id/participants" 200 "$register_participant_data" true
test_api_endpoint "POST Register Participant" "POST" "/v1/hackathons/$created_hackathon_id/participants/create" 200 "$register_participant_data" true
# List participants
test_api_endpoint "GET List Participants" "GET" "/v1/hackathons/$created_hackathon_id/participants" 200 "" true
@@ -147,12 +147,12 @@ test_hackathon_endpoints() {
contact_twitter: "@team_twitter",
contact_linkedin: "linkedin.com/in/team"
}')
local create_submission_response=$(test_api_endpoint "POST Create Submission" "POST" "/v1/hackathons/$created_hackathon_id/teams/$team_id/submissions" 201 "$create_submission_data" true)
local create_submission_response=$(test_api_endpoint "POST Create Submission" "POST" "/v1/hackathons/$created_hackathon_id/teams/$team_id/submissions/create" 201 "$create_submission_data" true)
local submission_id=$(echo "$create_submission_response" | jq -r '.data.id // empty')
if [ -n "$submission_id" ]; then
# Get submission by ID
test_api_endpoint "GET Submission By ID" "GET" "/v1/hackathons/submissions/$submission_id" 200 "" true
test_api_endpoint "GET Submission By ID" "GET" "/v1/hackathons/submissions/detail/$submission_id" 200 "" true
# List all submissions for hackathon
test_api_endpoint "GET Hackathon Submissions" "GET" "/v1/hackathons/$created_hackathon_id/submissions" 200 "" true
@@ -168,7 +168,7 @@ test_hackathon_endpoints() {
contact_youtube: "youtube.com/@teamchannel",
contact_facebook: "facebook.com/teampage"
}')
test_api_endpoint "PUT Update Submission" "PUT" "/v1/hackathons/submissions/$submission_id" 200 "$update_submission_data" true
test_api_endpoint "PUT Update Submission" "PUT" "/v1/hackathons/submissions/update/$submission_id" 200 "$update_submission_data" true
# === Test Validation Errors ===
printf "\n${CYAN}Testing Submission Validation Errors...${NC}\n"
@@ -230,7 +230,7 @@ test_hackathon_endpoints() {
# Cleanup invalid submission
curl -s -X DELETE -H "Authorization: Bearer $AUTH_TOKEN" \
"$BASE_URL/v1/hackathons/submissions/$invalid_sub_id" > /dev/null
"$BASE_URL/v1/hackathons/submissions/delete/$invalid_sub_id" > /dev/null
fi
# === Submit Valid Submission ===
@@ -243,13 +243,13 @@ test_hackathon_endpoints() {
status: "under_review",
feedback: "Great project, under review by our panel"
}')
test_api_endpoint "PUT Update Submission Status" "PUT" "/v1/hackathons/submissions/$submission_id/status" 200 "$update_status_data" true
test_api_endpoint "PUT Update Submission Status" "PUT" "/v1/hackathons/submissions/update/$submission_id/status" 200 "$update_status_data" true
# Get user submissions
test_api_endpoint "GET User Submissions" "GET" "/v1/users/$AUTH_USER_ID/hackathon-submissions" 200 "" true
# Delete submission
test_api_endpoint "DELETE Submission" "DELETE" "/v1/hackathons/submissions/$submission_id" 200 "" true
test_api_endpoint "DELETE Submission" "DELETE" "/v1/hackathons/submissions/delete/$submission_id" 200 "" true
fi
fi
@@ -267,7 +267,7 @@ test_hackathon_endpoints() {
test_api_endpoint "POST Search Hackathons" "POST" "/v1/hackathons/search" 200 "$search_data" false
# Delete hackathon (cleanup)
test_api_endpoint "DELETE Hackathon" "DELETE" "/v1/hackathons/$created_hackathon_id" 200 "" true
test_api_endpoint "DELETE Hackathon" "DELETE" "/v1/hackathons/delete/$created_hackathon_id" 200 "" true
fi
}
+7 -7
View File
@@ -103,14 +103,14 @@ test_notification_endpoints() {
# === 4. Mark Notification as Read ===
if [ "$first_notif_read" == "false" ]; then
printf "\n${CYAN}Testing: PUT /v1/notifications/{id}/read${NC}\n"
test_api_endpoint "PUT Mark as Read" "PUT" "/v1/notifications/$first_notif_id/read" 200 "" true
printf "\n${CYAN}Testing: PUT /v1/notifications/update/{id}/read${NC}\n"
test_api_endpoint "PUT Mark as Read" "PUT" "/v1/notifications/update/$first_notif_id/read" 200 "" true
# Test marking already read notification (should fail)
printf "\n${CYAN}Testing: Mark already read notification (should fail)${NC}\n"
local already_read_response=$(curl -s -w "\n%{http_code}" -X PUT \
-H "Authorization: Bearer $AUTH_TOKEN" \
"$BASE_URL/v1/notifications/$first_notif_id/read")
"$BASE_URL/v1/notifications/update/$first_notif_id/read")
local already_read_status=$(echo "$already_read_response" | tail -n1)
if [ "$already_read_status" == "400" ]; then
printf "${GREEN}✓ Correctly rejects marking already read notification${NC}\n"
@@ -144,14 +144,14 @@ test_notification_endpoints() {
# === 6. Delete Notification ===
if [ -n "$deletable_notif_id" ]; then
printf "\n${CYAN}Testing: DELETE /v1/notifications/{id}${NC}\n"
test_api_endpoint "DELETE Notification" "DELETE" "/v1/notifications/$deletable_notif_id" 200 "" true
printf "\n${CYAN}Testing: DELETE /v1/notifications/delete/{id}${NC}\n"
test_api_endpoint "DELETE Notification" "DELETE" "/v1/notifications/delete/$deletable_notif_id" 200 "" true
# Test deleting non-existent notification (should fail)
printf "\n${CYAN}Testing: Delete non-existent notification (should fail)${NC}\n"
local nonexistent_response=$(curl -s -w "\n%{http_code}" -X DELETE \
-H "Authorization: Bearer $AUTH_TOKEN" \
"$BASE_URL/v1/notifications/nonexistent123")
"$BASE_URL/v1/notifications/delete/nonexistent123")
local nonexistent_status=$(echo "$nonexistent_response" | tail -n1)
if [ "$nonexistent_status" == "404" ] || [ "$nonexistent_status" == "500" ]; then
printf "${GREEN}✓ Correctly handles non-existent notification${NC}\n"
@@ -186,7 +186,7 @@ test_notification_endpoints() {
# This would require knowing another user's notification ID, so we'll test with a fake ID
local other_user_response=$(curl -s -w "\n%{http_code}" -X PUT \
-H "Authorization: Bearer $AUTH_TOKEN" \
"$BASE_URL/v1/notifications/fake_other_user_notif_123/read")
"$BASE_URL/v1/notifications/update/fake_other_user_notif_123/read")
local other_user_status=$(echo "$other_user_response" | tail -n1)
if [ "$other_user_status" == "403" ] || [ "$other_user_status" == "404" ]; then
printf "${GREEN}✓ Correctly prevents access to other user's notification${NC}\n"
+14 -14
View File
@@ -38,7 +38,7 @@ test_hackathon_registration_endpoints() {
printf "${GREEN}✓ Created test hackathon: $hackathon_id${NC}\n"
# === 1. Register for Hackathon ===
printf "\n${CYAN}Testing: POST /v1/hackathons/{id}/register${NC}\n"
printf "\n${CYAN}Testing: POST /v1/hackathons/{id}/registrations/create${NC}\n"
local register_data=$(jq -n '{
role: "individual",
skills: ["Rust", "Web Development", "API Design"],
@@ -53,7 +53,7 @@ test_hackathon_registration_endpoints() {
emergency_contact_relationship: "Father"
}')
local register_response=$(test_api_endpoint "POST Register for Hackathon" "POST" "/v1/hackathons/$hackathon_id/register" 200 "$register_data" true)
local register_response=$(test_api_endpoint "POST Register for Hackathon" "POST" "/v1/hackathons/$hackathon_id/registrations/create" 200 "$register_data" true)
local registration_id=$(echo "$register_response" | jq -r '.data.id // empty')
if [ -z "$registration_id" ]; then
@@ -66,7 +66,7 @@ test_hackathon_registration_endpoints() {
local dup_response=$(curl -s -w "\n%{http_code}" -X POST \
-H "Authorization: Bearer $AUTH_TOKEN" \
-H "Content-Type: application/json" -d "$register_data" \
"$BASE_URL/v1/hackathons/$hackathon_id/register")
"$BASE_URL/v1/hackathons/$hackathon_id/registrations/create")
local dup_status=$(echo "$dup_response" | tail -n1)
if [ "$dup_status" == "400" ]; then
printf "${GREEN}✓ Duplicate registration prevented${NC}\n"
@@ -85,14 +85,14 @@ test_hackathon_registration_endpoints() {
test_api_endpoint "GET My Hackathons" "GET" "/v1/users/me/hackathons" 200 "" true
# === 4. Update Registration Status ===
printf "\n${CYAN}Testing: PUT /v1/hackathons/{hackathon_id}/registrations/{registration_id}/status${NC}\n"
printf "\n${CYAN}Testing: PUT /v1/hackathons/{hackathon_id}/registrations/update/{registration_id}/status${NC}\n"
# Approve registration
local approve_data=$(jq -n '{
status: "approved",
reason: "Your application meets all requirements. Welcome!"
}')
test_api_endpoint "PUT Approve Registration" "PUT" "/v1/hackathons/$hackathon_id/registrations/$registration_id/status" 200 "$approve_data" true
test_api_endpoint "PUT Approve Registration" "PUT" "/v1/hackathons/$hackathon_id/registrations/update/$registration_id/status" 200 "$approve_data" true
# Test reject status
local reject_data=$(jq -n '{
@@ -103,12 +103,12 @@ test_hackathon_registration_endpoints() {
local reject_response=$(curl -s -w "\n%{http_code}" -X PUT \
-H "Authorization: Bearer $AUTH_TOKEN" \
-H "Content-Type: application/json" -d "$reject_data" \
"$BASE_URL/v1/hackathons/$hackathon_id/registrations/$registration_id/status")
"$BASE_URL/v1/hackathons/$hackathon_id/registrations/update/$registration_id/status")
# Re-approve for check-in test
curl -s -X PUT -H "Authorization: Bearer $AUTH_TOKEN" \
-H "Content-Type: application/json" -d "$approve_data" \
"$BASE_URL/v1/hackathons/$hackathon_id/registrations/$registration_id/status" > /dev/null
"$BASE_URL/v1/hackathons/$hackathon_id/registrations/update/$registration_id/status" > /dev/null
# Test waitlist status
local waitlist_data=$(jq -n '{
@@ -117,12 +117,12 @@ test_hackathon_registration_endpoints() {
}')
curl -s -X PUT -H "Authorization: Bearer $AUTH_TOKEN" \
-H "Content-Type: application/json" -d "$waitlist_data" \
"$BASE_URL/v1/hackathons/$hackathon_id/registrations/$registration_id/status" > /dev/null
"$BASE_URL/v1/hackathons/$hackathon_id/registrations/update/$registration_id/status" > /dev/null
# Re-approve again for check-in
curl -s -X PUT -H "Authorization: Bearer $AUTH_TOKEN" \
-H "Content-Type: application/json" -d "$approve_data" \
"$BASE_URL/v1/hackathons/$hackathon_id/registrations/$registration_id/status" > /dev/null
"$BASE_URL/v1/hackathons/$hackathon_id/registrations/update/$registration_id/status" > /dev/null
# === 5. Check-in Participant ===
printf "\n${CYAN}Testing: POST /v1/hackathons/{hackathon_id}/registrations/{registration_id}/check-in${NC}\n"
@@ -198,11 +198,11 @@ test_hackathon_registration_endpoints() {
emergency_contact_phone: "+0987654321",
emergency_contact_relationship: "Mother"
}')
test_api_endpoint "POST Register with Team" "POST" "/v1/hackathons/$hackathon2_id/register" 200 "$team_register_data" true
test_api_endpoint "POST Register with Team" "POST" "/v1/hackathons/$hackathon2_id/registrations/create" 200 "$team_register_data" true
# Cleanup second hackathon
curl -s -X DELETE -H "Authorization: Bearer $AUTH_TOKEN" \
"$BASE_URL/v1/hackathons/$hackathon2_id" > /dev/null
"$BASE_URL/v1/hackathons/delete/$hackathon2_id" > /dev/null
fi
fi
@@ -233,18 +233,18 @@ test_hackathon_registration_endpoints() {
motivation: "I want to challenge myself with advanced projects",
tshirt_size: "L"
}')
test_api_endpoint "POST Register as Advanced Individual" "POST" "/v1/hackathons/$hackathon3_id/register" 200 "$individual_advanced_register" true
test_api_endpoint "POST Register as Advanced Individual" "POST" "/v1/hackathons/$hackathon3_id/registrations/create" 200 "$individual_advanced_register" true
# Cleanup third hackathon
curl -s -X DELETE -H "Authorization: Bearer $AUTH_TOKEN" \
"$BASE_URL/v1/hackathons/$hackathon3_id" > /dev/null
"$BASE_URL/v1/hackathons/delete/$hackathon3_id" > /dev/null
fi
fi
# Cleanup test hackathon
if [ -n "$hackathon_id" ]; then
curl -s -X DELETE -H "Authorization: Bearer $AUTH_TOKEN" \
"$BASE_URL/v1/hackathons/$hackathon_id" > /dev/null
"$BASE_URL/v1/hackathons/delete/$hackathon_id" > /dev/null
printf "\n${GREEN}✓ Cleaned up test hackathon${NC}\n"
fi
}