-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-cart-fixed.sh
More file actions
executable file
·41 lines (33 loc) · 1.18 KB
/
Copy pathdebug-cart-fixed.sh
File metadata and controls
executable file
·41 lines (33 loc) · 1.18 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
#!/bin/bash
echo "=== DEBUGGING CART ISSUE (FIXED) ==="
# 1. Register
TIMESTAMP=$(date +%s)
USERNAME="debug_user_$TIMESTAMP"
echo "Registering $USERNAME..."
REGISTER_RESPONSE=$(curl -s -X POST http://localhost:8080/api/auth/register \
-H "Content-Type: application/json" \
-d "{\"username\":\"$USERNAME\",\"email\":\"$USERNAME@test.com\",\"password\":\"password123\"}")
# Extract token using grep/sed/awk to avoid jq issues if any
TOKEN=$(echo $REGISTER_RESPONSE | grep -o '"token":"[^"]*' | cut -d'"' -f4)
if [ -z "$TOKEN" ]; then
echo "Failed to extract token. Response:"
echo "$REGISTER_RESPONSE"
exit 1
fi
echo "Token: $TOKEN"
# 2. Add to Cart
echo "Adding to cart..."
curl -v -X POST http://localhost:8080/api/cart \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"productId":1,"quantity":2}'
# 3. Check Cart
echo -e "\nChecking cart..."
curl -s -X GET http://localhost:8080/api/cart \
-H "Authorization: Bearer $TOKEN"
# 4. Checkout
echo -e "\nChecking out..."
curl -v -X POST http://localhost:8080/api/orders/checkout \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"shippingAddress":"Debug Address"}'