From 2fa2fddc11cf15a594cbbc03ba1b14afa3344f01 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Fri, 14 May 2021 22:10:29 +0200 Subject: controller: getRead + all_items is now unread type Signed-off-by: Sean Molenaar --- CHANGELOG.md | 1 + lib/Controller/ItemApiController.php | 7 +++++ tests/Unit/Controller/ItemApiControllerTest.php | 36 +++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3f8928eb..c5d9dd894 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ The format is almost based on [Keep a Changelog](https://keepachangelog.com/en/1 ### Changed ### Fixed +- allow calling `/items?getRead=false` without a feed/folder # Releases ## [15.4.3] - 2021-05-05 diff --git a/lib/Controller/ItemApiController.php b/lib/Controller/ItemApiController.php index 5f9da73a6..2e59d5b3a 100644 --- a/lib/Controller/ItemApiController.php +++ b/lib/Controller/ItemApiController.php @@ -94,6 +94,13 @@ class ItemApiController extends ApiController ); break; default: + // Fallback in case people try getRead here + if ($getRead === false && $type === ListType::ALL_ITEMS) { + $type = ListType::UNREAD; + } elseif ($getRead === false) { + return ['message' => 'Setting getRead on an already filtered list is not allowed!']; + } + $items = $this->itemService->findAllWithFilters( $this->getUserId(), $type, diff --git a/tests/Unit/Controller/ItemApiControllerTest.php b/tests/Unit/Controller/ItemApiControllerTest.php index 85e359705..e5d53a940 100644 --- a/tests/Unit/Controller/ItemApiControllerTest.php +++ b/tests/Unit/Controller/ItemApiControllerTest.php @@ -156,6 +156,42 @@ class ItemApiControllerTest extends TestCase } + public function testIndexListensToGetReadOnAllItems() + { + $item = new Item(); + $item->setId(5); + $item->setGuid('guid'); + $item->setGuidHash('guidhash'); + $item->setFeedId(123); + + $this->itemService->expects($this->once()) + ->method('findAllWithFilters') + ->with($this->uid, 6, -1, 0, false, []) + ->will($this->returnValue([$item])); + + $response = $this->class->index(3, 0, false); + + $this->assertEquals(['items' => [$item->toApi()]], $response); + } + + + public function testIndexListensToGetReadOnItems() + { + $item = new Item(); + $item->setId(5); + $item->setGuid('guid'); + $item->setGuidHash('guidhash'); + $item->setFeedId(123); + + $this->itemService->expects($this->never()) + ->method('findAllWithFilters'); + + $response = $this->class->index(6, 0, false); + + $this->assertEquals(['message' => 'Setting getRead on an already filtered list is not allowed!'], $response); + } + + public function testUpdatedFeed() { $item = new Item(); -- cgit v1.2.3