Skip to content

Commit

Permalink
implemented tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mast3rwaf1z committed Apr 2, 2024
1 parent 1c59982 commit 1ee0dc7
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/api-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Backend tests"

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test-all:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
submodules: recursive
- name: setup-env
run: sudo apt install cmake sqlite3 gcc curl jq
- name: build
run: cmake -B build && cmake --build build
env:
CXX: g++-13
- name: run-test
run: ./build/src/api_test --addrport localhost:8080 & bash ./tests/api-test.sh
108 changes: 108 additions & 0 deletions tests/api-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
addr="http://localhost:8080"
username="$(cat ./files/testdata/default.json | jq -r .user.username)"
password="$(cat ./files/testdata/default.json | jq -r .user.password)"
authjson="{"username":"$username", "password": "$password"}"

# /register
curl -X 'POST' -d "$authjson" $addr/register

# /auth
token=$(curl -X 'POST' -d "$authjson" $addr/auth)

# /user/ids/<n-m>
ids=$(curl -X 'GET' $addr/ids)
# get the one user id
uid=$(echo "$ids" | jq -r .[0])

# /user/data/update
curl -X 'POST' -d "{\"token\":\"$token\", \"data\":{}}" $addr/user/data/update

# /user/get/<uid>
userdata=$(curl -X 'GET' $addr/user/get/$uid)

# /journals/new
curl -X 'POST' -d "{\"token\":\"$token\", \"data\":[{\"question\":\"q1\", \"answer\":\"a1\"}]}" $addr/journals/new

# /journals/ids/<uid>
jids=$(curl -X 'GET' $addr/journals/ids/$uid)
# get the one journal
jid=$(echo "$jids" | jq -r .[0])

# /journals/get/<jid>
journal=$(curl -X 'GET' $addr/journals/get/$jid)

# /journals/delete/<uid>/<jid>
curl -X 'DELETE' $addr/journals/delete/$uid/$jid

# /settings/update
curl -X 'POST' -d "{\"token\":\"$token\", \"settings\":{\"key\":\"value\", \"key1\": \"value1\"}}" $addr/settings/update

# /settings/get/<uid>
settings=$(curl -X 'GET' $addr/settings/get/$uid)

# /questions/defaults
questions=$(curl -X 'GET' $addr/questions/defaults)

# /questions/get/<tags>
default_questions=$(curl -X 'GET' $addr/questions/get/default)

echo "---------------------TEST COMPLETE---------------------"
echo "addr: $addr"
echo "username: $username"
echo "password: $password"
echo "authjson: $authjson"
echo "token: $token"
echo "ids: $ids"
echo "uid: $uid"
echo "userdata: $userdata"
echo "jids: $jids"
echo "jid: $jid"
echo "journal: $journal"
echo "settings: $settings"
echo "questions: $questions"
echo "default questions: $default_questions"

# verify if all data is intact
if [[ "$addr" == "" ]]; then
exit 1
fi
if [[ "$username" == "" ]]; then
exit 1
fi
if [[ "$password" == "" ]]; then
exit 1
fi
if [[ "$authjson" == "" ]]; then
exit 1
fi
if [[ "$token" == "" ]]; then
exit 1
fi
if [[ "$ids" == "" ]]; then
exit 1
fi
if [[ "$uid" == "" ]]; then
exit 1
fi
if [[ "$userdata" == "" ]]; then
exit 1
fi
if [[ "$jids" == "" ]]; then
exit 1
fi
if [[ "$jid" == "" ]]; then
exit 1
fi
if [[ "$journal" == "" ]]; then
exit 1
fi
if [[ "$settings" == "" ]]; then
exit 1
fi
if [[ "$questions" == "" ]]; then
exit 1
fi
if [[ "$default_questions" == "" ]]; then
exit 1
fi
exit 0

0 comments on commit 1ee0dc7

Please sign in to comment.