1
0
mirror of https://github.com/chylex/Nextcloud-News.git synced 2024-11-24 04:42:46 +01:00
Nextcloud-News/tests/api/items.bats
Benjamin Brahmer a70d155ce4 Set lastmodified in read all
if this is not updated the API won't work correctly and we get sync errors.
Adjust test to use item api

Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
2023-04-05 19:43:02 +02:00

76 lines
2.6 KiB
Bash

#!/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}/items/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[@]}
}