-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestCurlScript.sh
More file actions
executable file
·60 lines (48 loc) · 1.77 KB
/
Copy pathtestCurlScript.sh
File metadata and controls
executable file
·60 lines (48 loc) · 1.77 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# Define variables
serverUrl="https://bob-server.vercel.app"
email="goathawona@gmail.com"
password="#254Rodgers"
# Function to authenticate and get the auth token
get_auth_token() {
local serverUrl=$1
local email=$2
local password=$3
response=$(curl -s -X POST "$serverUrl/users/login" \
-H "Content-Type: application/json" \
-d "{\"email\":\"$email\", \"password\":\"$password\"}")
authToken=$(echo "$response" | jq -r '.token')
if [ "$authToken" == "null" ] || [ -z "$authToken" ]; then
echo "Error logging in: $(echo "$response" | jq -r '.error')"
exit 1
fi
echo "$authToken"
}
# Function to answer assessment questions
answer_assessment_questions() {
local serverUrl=$1
local authToken=$2
questions=$(cat <<EOF
[
{"questionId": "0f53be1c-a8e9-4114-a390-30d5b472ef08", "answer": "15000"},
{"questionId": "10fa9a5b-0d6b-4c49-b570-87f5ae8dc947", "answer": "10000-19999"},
{"questionId": "26e82f70-4311-4d88-b4c9-6d0e286d8170", "answer": "7000"},
{"questionId": "3c43cada-2aaf-41c2-9ea5-c2d2a9a607f1", "answer": "Employment"},
{"questionId": "4d70a426-f204-4f1d-beab-1572df15d8cb", "answer": "50000"},
{"questionId": "af101a95-77de-42db-af49-df577e4bbbc4", "answer": "Vacation"},
{"questionId": "f43a7877-21fd-4636-b50f-f2f49527abd6", "answer": "3000"}
]
EOF
)
response=$(curl -s -X POST "$serverUrl/assessments/answers" \
-H "Content-Type: application/json" \
-H "x-token: $authToken" \
-d "{\"answers\": $questions}")
echo "Answers submitted successfully:"
echo "$response" | jq
}
# Main script
authToken=$(get_auth_token "$serverUrl" "$email" "$password")
if [ -n "$authToken" ]; then
answer_assessment_questions "$serverUrl" "$authToken"
fi