Skip to content

Commit

Permalink
work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Grotax committed Dec 23, 2024
1 parent 91f0127 commit 04455fb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
10 changes: 9 additions & 1 deletion lib/Fetcher/FeedFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ public function fetch(
);

$feed->setNextUpdateTime($resource->getNextUpdate()?->getTimestamp());
$this->logger->debug(
'Feed {url} was parsed and nextUpdateTime is {nextUpdateTime}',
[
'url' => $url,
'nextUpdateTime' => $resource->getNextUpdate()->getTimestamp(),
]
);

if (!is_null($resource->getResponse()->getLastModified())) {
$feed->setHttpLastModified($resource->getResponse()->getLastModified()->format(DateTime::RSS));
Expand All @@ -158,10 +165,11 @@ public function fetch(
$feedName = $parsedFeed->getTitle();
$feedAuthor = $parsedFeed->getAuthor();
$this->logger->debug(
'Feed {url} was modified since last fetch. #{count} items',
'Feed {url} was modified since last fetch. #{count} items, nextUpdateTime is {nextUpdateTime}',
[
'url' => $url,
'count' => count($parsedFeed),
'nextUpdateTime' => $feed->getNextUpdateTime(),
]
);

Expand Down
2 changes: 1 addition & 1 deletion tests/test_helper/php-feed-generator
60 changes: 42 additions & 18 deletions tests/updater/update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -59,43 +59,39 @@ teardown() {
assert_equal "${ID_LIST1[*]}" "${ID_LIST2[*]}"
}

@test "[$TESTSUITE] Test simple update with new content" {
@test "[$TESTSUITE] Test if nextUpdateTime is updated" {
# Create Feed
FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$TEST_FEED | grep -Po '"id":\K([0-9]+)')
FEED=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$TEST_FEED)

UpdateTime1=$(echo $FEED | jq '.feeds | .[0].nextUpdateTime')
FEEDID=$(echo $FEED | jq '.feeds | .[0].id')

assert_equal ${UpdateTime1} null

sleep 2

# Get Items
ID_LIST1=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))

php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 15 -s 9 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/test.xml

# Trigger Update
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds/update userId=${user} feedId=$FEEDID

sleep 2

# Get Items again
ID_LIST2=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
sleep 2

output="${ID_LIST2[*]}"
UpdateTime2=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | jq '.feeds | .[0].nextUpdateTime')

assert_equal ${UpdateTime2} 1

# Check that they are not equal but that they match partially.
assert_not_equal "${ID_LIST1[*]}" "${ID_LIST2[*]}"
assert_output --partial "${ID_LIST1[*]}"
}

@test "[$TESTSUITE] Test feed with 'outdated' items https://github.com/nextcloud/news/issues/2236 " {
# Create Feed, for the first fetch a timestamp today -1 year is used.
@test "[$TESTSUITE] Test simple update with new content" {
# Create Feed
FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$TEST_FEED | grep -Po '"id":\K([0-9]+)')

sleep 2

# Get Items
ID_LIST1=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))

# Generate Feed with older items (-o yes)
php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 15 -s 9 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/test.xml -o yes
php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 15 -s 9 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/test.xml

# Trigger Update
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds/update userId=${user} feedId=$FEEDID
Expand All @@ -112,6 +108,34 @@ teardown() {
assert_output --partial "${ID_LIST1[*]}"
}

# older date is not a thing anymore
#@test "[$TESTSUITE] Test feed with 'outdated' items https://github.com/nextcloud/news/issues/2236 " {
# # Create Feed, for the first fetch a timestamp today -1 year is used.
# FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$TEST_FEED | grep -Po '"id":\K([0-9]+)')
#
# sleep 2
#
# # Get Items
# ID_LIST1=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
#
# # Generate Feed with older items (-o yes)
# php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 15 -s 9 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/test.xml -o yes
#
# # Trigger Update
# http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds/update userId=${user} feedId=$FEEDID
#
# sleep 2
#
# # Get Items again
# ID_LIST2=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
#
# output="${ID_LIST2[*]}"
#
# # Check that they are not equal but that they match partially.
# assert_not_equal "${ID_LIST1[*]}" "${ID_LIST2[*]}"
# assert_output --partial "${ID_LIST1[*]}"
#}

@test "[$TESTSUITE] Test purge with small feed" {
# Generate Feed with 210 items.
php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 50 -s 0 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/test.xml
Expand Down

0 comments on commit 04455fb

Please sign in to comment.