diff options
author | Devlin Junker <devlin.junker@gmail.com> | 2022-11-09 21:52:11 -0800 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2022-11-17 14:50:53 +0100 |
commit | c6b4bcc00e5202e85388a0624d149e8b1df386f8 (patch) | |
tree | 7063a29710dfd0a363f3462fee8a0e8185488e15 /tests/api | |
parent | 760c44288256b104b662ade7a892a6ec0b898851 (diff) |
upmerging master into vue-rewrite
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
Diffstat (limited to 'tests/api')
-rw-r--r-- | tests/api/feeds.bats | 145 | ||||
-rw-r--r-- | tests/api/folders.bats | 97 | ||||
-rw-r--r-- | tests/api/helpers/settings.bash | 5 | ||||
-rw-r--r-- | tests/api/items.bats | 76 |
4 files changed, 323 insertions, 0 deletions
diff --git a/tests/api/feeds.bats b/tests/api/feeds.bats new file mode 100644 index 000000000..845a18eda --- /dev/null +++ b/tests/api/feeds.bats @@ -0,0 +1,145 @@ +#!/usr/bin/env bats + +setup_file(){ + load "helpers/settings" + + if test -f "tests/api/helpers/settings-override.bash"; then + load "helpers/settings-override" + fi + + export APP_PASSWORD=$(NC_PASS=${user} ./occ user:add-app-password ${user} --password-from-env | grep -Po '([A-Z|a-z|0-9]{72})') +} + +teardown_file(){ + http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${NC_HOST}/ocs/v2.php/core/apppassword OCS-APIRequest:true +} + +setup() { + load "../test_helper/bats-support/load" + load "../test_helper/bats-assert/load" +} + +TESTSUITE="Feeds" + +teardown() { + # delete all feeds + ID_LIST=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) + for i in $ID_LIST; do + http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/feeds/$i > /dev/null + done + + # delete all folders + ID_LIST=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/folders | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) + for i in $ID_LIST; do + http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/folders/$i > /dev/null + done +} + +@test "[$TESTSUITE] Read empty" { + run http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds + + assert_output --partial "\"feeds\":[]" + assert_output --partial "\"starredCount\":0" +} + +@test "[$TESTSUITE] Create new" { + # run is not working here. + output=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED | jq '.feeds | .[0].url') + + assert_output '"http://localhost:8090/Nextcloud.rss"' +} + +@test "[$TESTSUITE] Create new inside folder" { + # create folder and store id + ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)') + + # run is not working here. + output=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED folderId=$ID | jq '.feeds | .[0].folderId') + + # check if ID matches + assert_output "$ID" +} + +@test "[$TESTSUITE] Delete one" { + ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED | grep -Po '"id":\K([0-9]+)') + + run http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/feeds/$ID + + assert_output "[]" +} + +@test "[$TESTSUITE] Move feed to different folder" { + # create folders and store ids + FIRST_FOLDER_ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)') + SECCOND_FOLDER_ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)') + + FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED folderId=$FIRST_FOLDER_ID | grep -Po '"id":\K([0-9]+)') + + # move feed, returns nothing + http --ignore-stdin -b -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEEDID/move folderId=$SECCOND_FOLDER_ID + + # run is not working here. + output=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | jq '.feeds | .[0].folderId') + + # look for second folder id + assert_output "$SECCOND_FOLDER_ID" +} + +@test "[$TESTSUITE] Move feed to root" { + # create folder and store id + FOLDER_ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)') + + FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED folderId=$FOLDER_ID | grep -Po '"id":\K([0-9]+)') + + # move feed to "null", returns nothing + http --ignore-stdin -b -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEEDID/move folderId=null + + # run is not working here. + output=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | jq '.feeds | .[0].folderId') + + # new "folder" should be null + assert_output null +} + +@test "[$TESTSUITE] Rename feed" { + # create feed and store id + FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED | grep -Po '"id":\K([0-9]+)') + + # rename feed, returns nothing + http --ignore-stdin -b -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEEDID/rename feedTitle="Great Title" + + # run is not working here. + output=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | jq '.feeds | .[0].title') + + # Check if title matches + assert_output '"Great Title"' +} + +@test "[$TESTSUITE] Mark all items as read" { + # create feed and store id + FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED | grep -Po '"id":\K([0-9]+)') + + ID_LIST=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) + + # get biggest item ID + max=${ID_LIST[0]} + for n in "${ID_LIST[@]}" ; do + ((n > max)) && max=$n + done + + # mark all items of feed as read, returns nothing + STATUS_CODE=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEEDID/read newestItemId="$max" 2>&1| grep HTTP/) + + # collect unread status + unread=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"unread":\K((true)|(false))' | tr '\n' ' ') + + for n in "${unread[@]}" ; do + if $n + then + echo "Item was not marked as read" + echo $STATUS_CODE + false + fi + done +} + diff --git a/tests/api/folders.bats b/tests/api/folders.bats new file mode 100644 index 000000000..77f23814f --- /dev/null +++ b/tests/api/folders.bats @@ -0,0 +1,97 @@ +#!/usr/bin/env bats + +setup_file(){ + load "helpers/settings" + + if test -f "tests/api/helpers/settings-override.bash"; then + load "helpers/settings-override" + fi + + export APP_PASSWORD=$(NC_PASS=${user} ./occ user:add-app-password ${user} --password-from-env | grep -Po '([A-Z|a-z|0-9]{72})') +} + +teardown_file(){ + http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${NC_HOST}/ocs/v2.php/core/apppassword OCS-APIRequest:true +} + +setup() { + load "../test_helper/bats-support/load" + load "../test_helper/bats-assert/load" +} + +TESTSUITE="Folders" + +teardown() { + # delete all feeds + FEED_IDS=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) + for i in $FEED_IDS; do + http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/feeds/$i > /dev/null + done + + # delete all folders + FOLDER_IDS=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/folders | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) + for i in $FOLDER_IDS; do + http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/folders/$i > /dev/null + done +} + +@test "[$TESTSUITE] Read empty" { + run http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/folders + + assert_output --partial "\"folders\":[]" +} + +@test "[$TESTSUITE] Create new" { + run http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} + + assert_output --partial "\"name\":\"news-${BATS_SUITE_TEST_NUMBER}\"," +} + +@test "[$TESTSUITE] Delete folder" { + ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)') + + run http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/folders/$ID + + assert_output "[]" +} + +@test "[$TESTSUITE] Rename folder" { + ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)') + + # Rename folder + http --ignore-stdin -b -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/folders/$ID name=rename-${BATS_SUITE_TEST_NUMBER} + + run http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/folders + + assert_output --partial "\"name\":\"rename-${BATS_SUITE_TEST_NUMBER}\"," +} + +@test "[$TESTSUITE] Mark all items as read" { + # create folder and feed in folder + FOLDER_ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)') + FEED_ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED folderId=$FOLDER_ID | grep -Po '"id":\K([0-9]+)') + + ID_LIST=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) + + # get biggest item ID + max=${ID_LIST[0]} + for n in "${ID_LIST[@]}" ; do + ((n > max)) && max=$n + done + + # mark all items of feed as read, returns nothing + STATUS_CODE=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/folders/$FOLDER_ID/read newestItemId="$max" 2>&1| grep HTTP/) + + # collect unread status + unread=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"unread":\K((true)|(false))' | tr '\n' ' ') + + for n in "${unread[@]}" ; do + if $n + then + echo "Item was not marked as read" + echo $STATUS_CODE + false + fi + done +} + diff --git a/tests/api/helpers/settings.bash b/tests/api/helpers/settings.bash new file mode 100644 index 000000000..84fdaf936 --- /dev/null +++ b/tests/api/helpers/settings.bash @@ -0,0 +1,5 @@ +export user=admin +export NC_FEED="http://localhost:8090/Nextcloud.rss" +export HEISE_FEED="http://localhost:8090/heise.xml" +export BASE_URLv1="http://localhost:8080/index.php/apps/news/api/v1-2" +export NC_HOST="http://localhost:8080"
\ No newline at end of file diff --git a/tests/api/items.bats b/tests/api/items.bats new file mode 100644 index 000000000..d6896785f --- /dev/null +++ b/tests/api/items.bats @@ -0,0 +1,76 @@ +#!/usr/bin/env bats + +setup_file(){ + load "helpers/settings" + + if test -f "tests/api/helpers/settings-override.bash"; then + load "helpers/settings-override" + fi + + export APP_PASSWORD=$(NC_PASS=${user} ./occ user:add-app-password ${user} --password-from-env | grep -Po '([A-Z|a-z|0-9]{72})') +} + +teardown_file(){ + http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${NC_HOST}/ocs/v2.php/core/apppassword OCS-APIRequest:true +} + +setup() { + load "../test_helper/bats-support/load" + load "../test_helper/bats-assert/load" +} + + +TESTSUITE="Items" + +teardown() { + # delete all feeds + FEED_IDS=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) + for i in $FEED_IDS; do + http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/feeds/$i > /dev/null + done + + # delete all folders + FOLDER_IDS=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/folders | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) + for i in $FOLDER_IDS; do + http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/folders/$i > /dev/null + done +} + +@test "[$TESTSUITE] Read empty" { + run http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items + + assert_output --partial "\"items\":[]" +} + +@test "[$TESTSUITE] Read 5" { + http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED + + ID_LIST=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items batchSize=5 | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) + + output=${#ID_LIST[@]} + + assert_output --partial "5" +} + +# TODO GET /items has more options that could be tested. + +@test "[$TESTSUITE] Check updated" { + FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED | grep -Po '"id":\K([0-9]+)') + ID_LIST=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items id=$FEEDID | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) + + # get biggest item ID + max=${ID_LIST[0]} + for n in "${ID_LIST[@]}" ; do + ((n > max)) && max=$n + done + + SYNC_TIME=$(date +%s) + + # mark all items of feed as read, returns nothing (other client marks items as read) + STATUS_CODE=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEEDID/read newestItemId="$max" 2>&1| grep HTTP/) + + # client 2 checks for updates since last sync + UPDATED_ITEMS=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items/updated id=$FEEDID lastModified=$SYNC_TIME | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) + + assert_equal ${#ID_LIST[@]} ${#UPDATED_ITEMS[@]} +}
\ No newline at end of file |