insightfy-bloom-ms-mpms / test_login_fix.sh
MukeshKapoor25's picture
feat(auth): Enhance Login API with Access Menu Support
5836efd
#!/bin/bash
# Test script to verify the ObjectId serialization fix for enhanced login
echo "Testing Enhanced Login with ObjectId Fix"
echo "========================================"
# API endpoint
BASE_URL="http://127.0.0.1:8000"
LOGIN_ENDPOINT="$BASE_URL/merchant/login"
# Test credentials
LOGIN_INPUT="mk@bookmyservice.tech"
OTP="777777"
echo "Endpoint: $LOGIN_ENDPOINT"
echo "Login Input: $LOGIN_INPUT"
echo "OTP: $OTP"
echo ""
echo "Making login request..."
echo "----------------------"
# Make the login request and capture both response and HTTP status
response=$(curl -s -w "\n%{http_code}" -X 'POST' \
"$LOGIN_ENDPOINT" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d "{
\"login_input\": \"$LOGIN_INPUT\",
\"otp\": \"$OTP\"
}")
# Split response and status code
http_code=$(echo "$response" | tail -n1)
response_body=$(echo "$response" | head -n -1)
echo "HTTP Status Code: $http_code"
echo ""
if [ "$http_code" = "200" ]; then
echo "βœ… Login request successful!"
echo ""
# Check if response is valid JSON
if echo "$response_body" | jq . > /dev/null 2>&1; then
echo "βœ… Response is valid JSON!"
# Pretty print the response
echo "Response:"
echo "$response_body" | jq '.'
# Check for access_menu
if echo "$response_body" | jq -e '.access_menu' > /dev/null 2>&1; then
echo ""
echo "βœ… Access menu is present in response!"
# Extract key metrics
permissions_count=$(echo "$response_body" | jq '.access_menu.permissions | length' 2>/dev/null || echo "0")
widgets_count=$(echo "$response_body" | jq '.access_menu.accessible_widgets | length' 2>/dev/null || echo "0")
menu_items_count=$(echo "$response_body" | jq '.access_menu.menu_items | length' 2>/dev/null || echo "0")
role_name=$(echo "$response_body" | jq -r '.access_menu.role_info.role_name' 2>/dev/null || echo "Unknown")
api_version=$(echo "$response_body" | jq -r '.api_version' 2>/dev/null || echo "1.0")
echo "Access Menu Summary:"
echo " - API Version: $api_version"
echo " - Role: $role_name"
echo " - Permissions: $permissions_count"
echo " - Accessible Widgets: $widgets_count"
echo " - Menu Items: $menu_items_count"
if [ "$api_version" = "2.0" ]; then
echo ""
echo "πŸŽ‰ Enhanced login with access menu is working correctly!"
echo "βœ… ObjectId serialization fix successful!"
else
echo ""
echo "⚠️ API version is not 2.0, might be using legacy response"
fi
else
echo ""
echo "⚠️ Access menu not found in response"
# Check for warnings
if echo "$response_body" | jq -e '.warnings' > /dev/null 2>&1; then
echo "Warnings found:"
echo "$response_body" | jq -r '.warnings[]' | while read warning; do
echo " - $warning"
done
fi
fi
else
echo "❌ Response is not valid JSON!"
echo "Raw response:"
echo "$response_body"
fi
elif [ "$http_code" = "500" ]; then
echo "❌ Internal Server Error (500)"
echo "This might indicate ObjectId serialization issues or other server errors."
echo ""
echo "Raw response:"
echo "$response_body"
else
echo "❌ Unexpected HTTP status code: $http_code"
echo ""
echo "Raw response:"
echo "$response_body"
fi
echo ""
echo "Test completed!"