[IMPROVE] Better error handling in test script
- Stop execution if register fails (don't try login with non-existent user) - Add warning when register fails (backend may need restart) - Skip login test if register failed - Better error messages
This commit is contained in:
parent
a52be650c5
commit
163d5e0890
1 changed files with 19 additions and 7 deletions
|
|
@ -167,20 +167,27 @@ phase_1_auth() {
|
|||
log_info "AUTH-003: Registering new user"
|
||||
local register_data="{\"email\":\"$TEST_EMAIL\",\"username\":\"$TEST_USERNAME\",\"password\":\"$TEST_PASSWORD\",\"password_confirm\":\"$TEST_PASSWORD\"}"
|
||||
local register_response=$(test_request "POST" "$API_URL/auth/register" 201 "Register new user" "$register_data" "")
|
||||
local register_status=$?
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
if [ $register_status -eq 0 ]; then
|
||||
USER_ID=$(echo "$register_response" | jq -r '.data.user.id // .user.id // .id // ""' 2>/dev/null || echo "")
|
||||
if [ -n "$USER_ID" ]; then
|
||||
log_success "User created with ID: $USER_ID"
|
||||
fi
|
||||
else
|
||||
log_error "AUTH-003: Registration failed - cannot proceed with login test"
|
||||
log_warning "Note: Backend may need to be restarted for BUG-004 fix to take effect"
|
||||
# Continue anyway to test other endpoints, but skip login
|
||||
ACCESS_TOKEN=""
|
||||
fi
|
||||
|
||||
# Test AUTH-004: Login avec nouvel utilisateur
|
||||
log_info "AUTH-004: Logging in with new user"
|
||||
local login_data="{\"email\":\"$TEST_EMAIL\",\"password\":\"$TEST_PASSWORD\"}"
|
||||
local login_response=$(test_request "POST" "$API_URL/auth/login" 200 "Login with new user" "$login_data" "")
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
# Test AUTH-004: Login avec nouvel utilisateur (only if register succeeded)
|
||||
if [ $register_status -eq 0 ]; then
|
||||
log_info "AUTH-004: Logging in with new user"
|
||||
local login_data="{\"email\":\"$TEST_EMAIL\",\"password\":\"$TEST_PASSWORD\"}"
|
||||
local login_response=$(test_request "POST" "$API_URL/auth/login" 200 "Login with new user" "$login_data" "")
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
# Le format réel est: .data.token.access_token (pas .data.access_token)
|
||||
ACCESS_TOKEN=$(echo "$login_response" | jq -r '.data.token.access_token // .data.access_token // .access_token // .token.access_token // ""' 2>/dev/null || echo "")
|
||||
REFRESH_TOKEN=$(echo "$login_response" | jq -r '.data.token.refresh_token // .data.refresh_token // .refresh_token // .token.refresh_token // ""' 2>/dev/null || echo "")
|
||||
|
|
@ -192,6 +199,11 @@ phase_1_auth() {
|
|||
log_info "Response structure: $(echo "$login_response" | jq 'keys' 2>/dev/null || echo 'invalid json')"
|
||||
log_info "Data keys: $(echo "$login_response" | jq '.data | keys' 2>/dev/null || echo 'no data')"
|
||||
fi
|
||||
else
|
||||
log_error "AUTH-004: Login failed"
|
||||
fi
|
||||
else
|
||||
log_warning "AUTH-004: Skipped (registration failed in AUTH-003)"
|
||||
fi
|
||||
|
||||
# Test AUTH-005: Accès route protégée avec token
|
||||
|
|
|
|||
Loading…
Reference in a new issue