-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.sh
46 lines (37 loc) · 1.45 KB
/
integration_test.sh
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
#!/bin/bash
set -e
# Wait for the application to start
echo "Waiting for the application to be ready..."
sleep 20 # Adjust this time as necessary
# Create a user
echo "Creating a new user..."
response=$(curl -s -X POST http://localhost:8080/users \
-H "Content-Type: application/json" \
-d '{"user_name": "testuser16", "password": "mypassword15", "email": "[email protected]"}')
echo $response
# Assert the response message
expected_message="User created successfully"
if [[ $(echo "$response" | jq -r '.message') == "$expected_message" ]]; then
echo "User creation assertion passed: $expected_message"
else
echo "User creation assertion failed: Expected '$expected_message', got '$response'"
exit 1
fi
# Login the user and extract the token
echo "Logging in the user..."
login_response=$(curl -s -X POST http://localhost:8080/login \
-H "Content-Type: application/json" \
-d '{"username": "testuser16", "password": "mypassword15"}')
token=$(echo $login_response | jq -r '.token')
echo "Received JWT token: $token"
# Create a ToDo
echo "Creating a ToDo..."
curl -s -X POST http://localhost:8080/todos \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
-d '{"title": "My New Todo", "description": "This is a description of my new todo"}'
# Get ToDos
echo "Getting the ToDos..."
curl -s -X GET http://localhost:8080/todos \
-H "Authorization: Bearer $token"
echo "Integration test completed successfully."