From f306075b3294929a8f7b0a74886dd9fd6a7fad1e Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Fri, 18 Mar 2022 10:18:23 +0100 Subject: test mark items of folder as read Signed-off-by: Benjamin Brahmer --- tests/api/folders.bats | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/tests/api/folders.bats b/tests/api/folders.bats index 4dfe9129a..75d8339bb 100644 --- a/tests/api/folders.bats +++ b/tests/api/folders.bats @@ -9,8 +9,15 @@ setup() { TESTSUITE="Folders" teardown() { - ID=$(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/folders | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ') - for i in $ID; do + # delete all feeds + FEED_IDS=($(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/feeds | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) + for i in $FEED_IDS; do + http --ignore-stdin -b -a ${user}:${user} DELETE ${BASE_URLv1}/feeds/$i + done + + # delete all folders + FOLDER_IDS=($(http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/folders | grep -Po '"id":\K([0-9]+)' | tr '\n' ' ')) + for i in $FOLDER_IDS; do http --ignore-stdin -b -a ${user}:${user} DELETE ${BASE_URLv1}/folders/$i done } @@ -44,4 +51,34 @@ teardown() { run http --ignore-stdin -b -a ${user}:${user} GET ${BASE_URLv1}/folders assert_output --partial "\"name\":\"rename-${BATS_SUITE_TEST_NUMBER}\"," -} \ No newline at end of file +} + +@test "[$TESTSUITE] Mark all items as read" { + # create folder and feed in folder + FOLDER_ID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/folders name=news-${BATS_SUITE_TEST_NUMBER} | grep -Po '"id":\K([0-9]+)') + FEED_ID=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/feeds url=$NC_FEED folderId=$FOLDER_ID | grep -Po '"id":\K([0-9]+)') + + ID_LIST=($(http --ignore-stdin -b -a ${user}:${user} 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}:${user} PUT ${BASE_URLv1}/folders/$FOLDER_ID/read newestItemId="$max" 2>&1| grep HTTP/) + + # collect unread status + unread=$(http --ignore-stdin -b -a ${user}:${user} 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 +} + -- cgit v1.2.3