diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2021-05-14 22:10:29 +0200 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2021-05-16 16:31:16 +0200 |
commit | 2fa2fddc11cf15a594cbbc03ba1b14afa3344f01 (patch) | |
tree | 47ab198e5ebd7fbd5fd8e8413ed8cba7bb01d729 | |
parent | 9f36b3af3fdd9b4a95f349277d00334c5d7b59f2 (diff) |
controller: getRead + all_items is now unread type
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/Controller/ItemApiController.php | 7 | ||||
-rw-r--r-- | tests/Unit/Controller/ItemApiControllerTest.php | 36 |
3 files changed, 44 insertions, 0 deletions
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(); |