Fix test setup and middleware chain - Handler tests now passing

- Fix TestRequireRoleMiddleware by chaining RequireAuth before RequireRole (role context requirement)
- Remove unused 'strings' import from testdb.go
- Create crussell_test database in Docker setup
- Tests now properly initialize authentication context for role-based tests

Result: handlers test suite passes (13/13 tests)
Remaining failures in admin/auth/bookings/portfolio/scheduling/services/user packages need further investigation (environment setup, database constraints, endpoint initialization)
This commit is contained in:
2026-02-21 23:50:17 +00:00
parent e858c782a4
commit 44cac94f64
20 changed files with 6725 additions and 7 deletions
+44 -4
View File
@@ -8,6 +8,12 @@ setopt PIPE_FAIL
setopt ERR_EXIT
# --- UI Helpers ---
# Color codes for output
C_RESET=$'\033[0m'
C_GREEN=$'\033[32m'
C_RED=$'\033[31m'
C_BLUE=$'\033[34m'
C_YELLOW=$'\033[33m'
log_info() { echo "🔹 $1" }
log_success() { echo "$1" }
log_error() { echo "$1" }
@@ -369,9 +375,13 @@ echo "${C_GREEN}✅ Created $count_future/30 Bookings (Future)${C_RESET}"
echo "${C_GREEN}✅ Created $count_past/8 Bookings (Past)${C_RESET}"
echo "${C_GREEN}✅ Created $TOTAL/45 Bookings (Total)${C_RESET}"
# 5. Confirm Random Half of Upcoming Bookings
echo -e "\n${C_BLUE}🔒 Confirming Random Upcoming Bookings...${C_RESET}"
# 5. Confirm Random Half of Upcoming Bookings
echo -e "\n${C_BLUE}🔒 Confirming Random Upcoming Bookings...${C_RESET}"
confirmed_count=0
rejected_count=0
attempted_count=0
total_upcoming=${#UPCOMING_BOOKING_IDS[@]}
# Small pause to ensure backend is ready after bulk creation
@@ -389,6 +399,7 @@ for ((i=0; i<${#UPCOMING_BOOKING_IDS[@]}; i++)); do
# Random coin flip (0 or 1). If 1, confirm.
if [ $((RANDOM % 2)) -eq 1 ]; then
attempted_count=$((attempted_count+1))
# Send proper JSON with empty serviceOverrides array
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
-H "Content-Type: application/json" \
@@ -399,17 +410,19 @@ for ((i=0; i<${#UPCOMING_BOOKING_IDS[@]}; i++)); do
BODY=$(echo "$RESPONSE" | sed '$d')
if [ "$HTTP_CODE" = "200" ]; then
echo " ✅ Confirmed: $name"
confirmed_count=$((confirmed_count+1))
else
echo " ⚠️ Failed to confirm: $name (HTTP $HTTP_CODE)"
echo " Response: $BODY"
rejected_count=$((rejected_count+1))
fi
# Small sleep to prevent overwhelming the server
sleep 0.1
fi
done
echo "${C_GREEN}✅ Confirmed $confirmed_count upcoming bookings${C_RESET}"
echo "${C_GREEN}✅ Confirmed $confirmed_count/$attempted_count Bookings${C_RESET}"
if [ "$rejected_count" -gt 0 ]; then
echo "${C_YELLOW}⚠️ Rejected $rejected_count/$attempted_count (deposit/time restrictions)${C_RESET}"
fi
# 6. Exceptional Groups (2 Total)
echo -e "\n${C_BLUE}🗓️ Creating Exceptional Groups...${C_RESET}"
@@ -430,6 +443,33 @@ fi
echo -e "\n${C_GREEN}🎉 Seeding Complete!${C_RESET}"
read -n1 -s -p "Press any key to close this window..."
# --- Main Database Seeding Complete ---
echo -e "\n${C_GREEN}🎉 Main Database Seeding Complete!${C_RESET}"
# --- Run Tests ---
echo -e "\n${C_BLUE}🧪 Running Backend Tests...${C_RESET}"
cd backend
TEST_OUTPUT=$(go test -tags test -v ./... 2>&1 || true)
TOTAL_TESTS=$(echo "$TEST_OUTPUT" | grep -c "^=== RUN" || echo "0")
PASSED_TESTS=$(echo "$TEST_OUTPUT" | grep -c "^--- PASS" || echo "0")
FAILED_TESTS=$(echo "$TEST_OUTPUT" | grep -c "^--- FAIL" || echo "0")
if [ "$FAILED_TESTS" -gt 0 ]; then
echo -e "${C_RED}❌ Tests Failed: $PASSED_TESTS/$TOTAL_TESTS passed${C_RESET}"
echo ""
echo -e "${C_RED}--- Failed Test Details ---${C_RESET}"
echo "$TEST_OUTPUT" | grep -A 3 "^--- FAIL" | head -20
echo ""
echo -e "${C_YELLOW}⚠️ Continuing anyway (tests are non-blocking)${C_RESET}"
else
echo -e "${C_GREEN}✅ All Tests Passed: $PASSED_TESTS/$TOTAL_TESTS${C_RESET}"
fi
cd ..
echo -e "\n${C_YELLOW}Press ENTER to close this seeding pane...${C_RESET}"
read -r
SEED_EOF
chmod +x $SEED_SCRIPT