From 4a107b3d53c4fe651ac704251b99e04a53cd587f Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 16 Feb 2021 21:17:10 +0100 Subject: General: Fix folder query Signed-off-by: Sean Molenaar --- .github/workflows/api-integration-tests.yml | 7 +++--- CHANGELOG.md | 1 + lib/Controller/FeedController.php | 8 +++---- lib/Controller/ItemApiController.php | 10 ++++---- lib/Controller/ItemController.php | 10 ++++---- lib/Controller/PageController.php | 4 ++-- lib/Db/ItemMapperV2.php | 15 ++++++++---- lib/Db/ListType.php | 16 ++++++------- lib/Service/ItemServiceV2.php | 4 ++-- tests/Unit/Controller/FeedControllerTest.php | 14 ++++++------ tests/Unit/Controller/ItemControllerTest.php | 34 ++++++++++++++-------------- tests/Unit/Controller/PageControllerTest.php | 6 ++--- tests/Unit/Db/ItemMapperTest.php | 3 ++- tests/Unit/Service/ItemServiceTest.php | 8 +++---- 14 files changed, 74 insertions(+), 66 deletions(-) diff --git a/.github/workflows/api-integration-tests.yml b/.github/workflows/api-integration-tests.yml index 809d63e4c..29df1d65d 100644 --- a/.github/workflows/api-integration-tests.yml +++ b/.github/workflows/api-integration-tests.yml @@ -133,9 +133,10 @@ jobs: - name: Functional tests items working-directory: ../server run: | - ./occ news:item:list-feed "admin" $(./occ news:feed:list 'admin' | grep 'github\.com' -1 | head -1 | grep -oE '[0-9]*') --limit 200 | grep '15.3.2' - ./occ news:item:list-folder "admin" --limit 200 | grep '15.3.2' - ./occ news:item:list "admin" --limit 200 | grep '15.3.2' + TAG=$(curl --silent "https://api.github.com/repos/nextcloud/news/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + ./occ news:item:list-feed "admin" $(./occ news:feed:list 'admin' | grep 'github\.com' -1 | head -1 | grep -oE '[0-9]*') --limit 200 | grep "$TAG" + ./occ news:item:list-folder "admin" --limit 200 | grep "$TAG" + ./occ news:item:list "admin" --limit 200 | grep "$TAG" - name: Functional tests opml working-directory: ../server diff --git a/CHANGELOG.md b/CHANGELOG.md index 270484703..c7b5cd099 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is almost based on [Keep a Changelog](https://keepachangelog.com/en/1 - Add CI for item lists ### Fixed +- Item list throwing error for folder and "all items" ## [15.3.2] - 2021-02-10 No changes compared to RC2 diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php index 681dda4bc..c80a5c327 100644 --- a/lib/Controller/FeedController.php +++ b/lib/Controller/FeedController.php @@ -24,7 +24,7 @@ use OCP\IRequest; use OCP\IConfig; use OCP\AppFramework\Http; -use OCA\News\Db\FeedType; +use OCA\News\Db\ListType; use OCP\IUserSession; class FeedController extends Controller @@ -122,10 +122,10 @@ class FeedController extends Controller $feedType = intval($feedType); switch ($feedType) { - case FeedType::FOLDER: + case ListType::FOLDER: $this->folderService->find($this->getUserId(), $feedId); break; - case FeedType::FEED: + case ListType::FEED: $this->feedService->find($this->getUserId(), $feedId); break; default: @@ -133,7 +133,7 @@ class FeedController extends Controller } } catch (ServiceNotFoundException $ex) { $feedId = 0; - $feedType = FeedType::SUBSCRIPTIONS; + $feedType = ListType::ALL_ITEMS; } return [ diff --git a/lib/Controller/ItemApiController.php b/lib/Controller/ItemApiController.php index 003c61fa2..5f9da73a6 100644 --- a/lib/Controller/ItemApiController.php +++ b/lib/Controller/ItemApiController.php @@ -15,7 +15,7 @@ namespace OCA\News\Controller; -use OCA\News\Db\FeedType; +use OCA\News\Db\ListType; use OCA\News\Service\Exceptions\ServiceConflictException; use OCA\News\Service\Exceptions\ServiceValidationException; use OCA\News\Service\ItemServiceV2; @@ -73,7 +73,7 @@ class ItemApiController extends ApiController bool $oldestFirst = false ): array { switch ($type) { - case FeedType::FEED: + case ListType::FEED: $items = $this->itemService->findAllInFeedWithFilters( $this->getUserId(), $id, @@ -83,7 +83,7 @@ class ItemApiController extends ApiController $oldestFirst ); break; - case FeedType::FOLDER: + case ListType::FOLDER: $items = $this->itemService->findAllInFolderWithFilters( $this->getUserId(), $id, @@ -130,10 +130,10 @@ class ItemApiController extends ApiController } switch ($type) { - case FeedType::FEED: + case ListType::FEED: $items = $this->itemService->findAllInFeedAfter($this->getUserId(), $id, $paddedLastModified, false); break; - case FeedType::FOLDER: + case ListType::FOLDER: $items = $this->itemService->findAllInFolderAfter($this->getUserId(), $id, $paddedLastModified, false); break; default: diff --git a/lib/Controller/ItemController.php b/lib/Controller/ItemController.php index 02a308d87..85f67ef7a 100644 --- a/lib/Controller/ItemController.php +++ b/lib/Controller/ItemController.php @@ -13,7 +13,7 @@ namespace OCA\News\Controller; -use OCA\News\Db\FeedType; +use OCA\News\Db\ListType; use OCA\News\Service\Exceptions\ServiceConflictException; use OCA\News\Service\FeedServiceV2; use OCP\AppFramework\Http\JSONResponse; @@ -136,7 +136,7 @@ class ItemController extends Controller } switch ($type) { - case FeedType::FEED: + case ListType::FEED: $items = $this->itemService->findAllInFeedWithFilters( $this->getUserId(), $id, @@ -147,7 +147,7 @@ class ItemController extends Controller $search_items ); break; - case FeedType::FOLDER: + case ListType::FOLDER: $items = $this->itemService->findAllInFolderWithFilters( $this->getUserId(), $id, @@ -201,7 +201,7 @@ class ItemController extends Controller try { switch ($type) { - case FeedType::FEED: + case ListType::FEED: $items = $this->itemService->findAllInFeedAfter( $this->getUserId(), $id, @@ -209,7 +209,7 @@ class ItemController extends Controller !$showAll ); break; - case FeedType::FOLDER: + case ListType::FOLDER: $items = $this->itemService->findAllInFolderAfter( $this->getUserId(), $id, diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 87ed91c73..9f17f5690 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -25,7 +25,7 @@ use OCP\AppFramework\Http\ContentSecurityPolicy; use OCA\News\Service\StatusService; use OCA\News\Explore\RecommendedSites; -use OCA\News\Db\FeedType; +use OCA\News\Db\ListType; use OCP\IUserSession; class PageController extends Controller @@ -204,7 +204,7 @@ class PageController extends Controller $this->getUserId(), $this->appName, 'lastViewedFeedType', - FeedType::EXPLORE + ListType::EXPLORE ); try { diff --git a/lib/Db/ItemMapperV2.php b/lib/Db/ItemMapperV2.php index cfd30b75e..1ef9da244 100644 --- a/lib/Db/ItemMapperV2.php +++ b/lib/Db/ItemMapperV2.php @@ -12,6 +12,7 @@ namespace OCA\News\Db; +use OC\DB\QueryBuilder\Literal; use OCA\News\Service\Exceptions\ServiceValidationException; use Doctrine\DBAL\FetchMode; use OCA\News\Utility\Time; @@ -386,12 +387,14 @@ class ItemMapperV2 extends NewsMapperV2 ->addOrderBy('items.id', 'DESC'); switch ($feedType) { - case FeedType::STARRED: + case ListType::STARRED: $builder->andWhere('items.starred = 1'); break; - case FeedType::UNREAD: + case ListType::UNREAD: $builder->andWhere('items.unread = 1'); break; + case ListType::ALL_ITEMS: + break; default: throw new ServiceValidationException('Unexpected Feed type in call'); } @@ -473,7 +476,7 @@ class ItemMapperV2 extends NewsMapperV2 if ($folderId === null) { $folderWhere = $builder->expr()->isNull('feeds.folder_id'); } else { - $folderWhere = $builder->expr()->eq('feeds.folder_id', $folderId); + $folderWhere = $builder->expr()->eq('feeds.folder_id', new Literal($folderId), IQueryBuilder::PARAM_INT); } $builder->select('items.*') @@ -542,12 +545,14 @@ class ItemMapperV2 extends NewsMapperV2 } switch ($type) { - case FeedType::STARRED: + case ListType::STARRED: $builder->andWhere('items.starred = 1'); break; - case FeedType::UNREAD: + case ListType::UNREAD: $builder->andWhere('items.unread = 1'); break; + case ListType::ALL_ITEMS: + break; default: throw new ServiceValidationException('Unexpected Feed type in call'); } diff --git a/lib/Db/ListType.php b/lib/Db/ListType.php index 1ccd592a8..e96e29ed6 100644 --- a/lib/Db/ListType.php +++ b/lib/Db/ListType.php @@ -18,13 +18,13 @@ namespace OCA\News\Db; * * @package OCA\News\Db */ -class FeedType +class ListType { - const FEED = 0; - const FOLDER = 1; - const STARRED = 2; - const SUBSCRIPTIONS = 3; - const SHARED = 4; - const EXPLORE = 5; - const UNREAD = 6; + const FEED = 0; + const FOLDER = 1; + const STARRED = 2; + const ALL_ITEMS = 3; + const SHARED = 4; + const EXPLORE = 5; + const UNREAD = 6; } diff --git a/lib/Service/ItemServiceV2.php b/lib/Service/ItemServiceV2.php index 8a518b5bd..da675450f 100644 --- a/lib/Service/ItemServiceV2.php +++ b/lib/Service/ItemServiceV2.php @@ -14,7 +14,7 @@ namespace OCA\News\Service; use OCA\News\AppInfo\Application; use OCA\News\Db\Feed; -use OCA\News\Db\FeedType; +use OCA\News\Db\ListType; use OCA\News\Db\Item; use OCA\News\Db\ItemMapperV2; use OCA\News\Service\Exceptions\ServiceConflictException; @@ -307,7 +307,7 @@ class ItemServiceV2 extends Service */ public function findAllAfter(string $userId, int $feedType, int $updatedSince): array { - if (!in_array($feedType, [FeedType::STARRED, FeedType::UNREAD])) { + if (!in_array($feedType, [ListType::STARRED, ListType::UNREAD, ListType::ALL_ITEMS])) { throw new ServiceValidationException('Trying to find in unknown type'); } diff --git a/tests/Unit/Controller/FeedControllerTest.php b/tests/Unit/Controller/FeedControllerTest.php index b8929d373..cf7bc501e 100644 --- a/tests/Unit/Controller/FeedControllerTest.php +++ b/tests/Unit/Controller/FeedControllerTest.php @@ -22,7 +22,7 @@ use OCA\News\Service\ItemServiceV2; use OCP\AppFramework\Http; use OCA\News\Db\Feed; -use OCA\News\Db\FeedType; +use OCA\News\Db\ListType; use OCA\News\Service\Exceptions\ServiceNotFoundException; use OCA\News\Service\Exceptions\ServiceConflictException; use OCP\IConfig; @@ -125,7 +125,7 @@ class FeedControllerTest extends TestCase $this->exampleResult = [ 'activeFeed' => [ 'id' => 0, - 'type' => FeedType::SUBSCRIPTIONS + 'type' => ListType::ALL_ITEMS ] ]; } @@ -207,7 +207,7 @@ class FeedControllerTest extends TestCase public function testActive() { $id = 3; - $type = FeedType::STARRED; + $type = ListType::STARRED; $result = [ 'activeFeed' => [ 'id' => $id, @@ -226,7 +226,7 @@ class FeedControllerTest extends TestCase public function testActiveFeed() { $id = 3; - $type = FeedType::FEED; + $type = ListType::FEED; $result = [ 'activeFeed' => [ 'id' => $id, @@ -250,7 +250,7 @@ class FeedControllerTest extends TestCase public function testActiveFeedDoesNotExist() { $id = 3; - $type = FeedType::FEED; + $type = ListType::FEED; $ex = new ServiceNotFoundException('hiu'); $result = $this->exampleResult; @@ -269,7 +269,7 @@ class FeedControllerTest extends TestCase public function testActiveFolder() { - $type = FeedType::FOLDER; + $type = ListType::FOLDER; $folder = new Folder(); $folder->setId(3); @@ -296,7 +296,7 @@ class FeedControllerTest extends TestCase public function testActiveFolderDoesNotExist() { $id = 3; - $type = FeedType::FOLDER; + $type = ListType::FOLDER; $ex = new ServiceNotFoundException('hiu'); $result = $this->exampleResult; diff --git a/tests/Unit/Controller/ItemControllerTest.php b/tests/Unit/Controller/ItemControllerTest.php index 546b39278..c64cd9330 100644 --- a/tests/Unit/Controller/ItemControllerTest.php +++ b/tests/Unit/Controller/ItemControllerTest.php @@ -20,7 +20,7 @@ use \OCP\AppFramework\Http; use \OCA\News\Db\Item; use \OCA\News\Db\Feed; -use \OCA\News\Db\FeedType; +use \OCA\News\Db\ListType; use \OCA\News\Service\Exceptions\ServiceNotFoundException; use OCP\IConfig; use OCP\IRequest; @@ -234,7 +234,7 @@ class ItemControllerTest extends TestCase 'starred' => 3 ]; - $this->itemsApiExpects(2, FeedType::FEED, '0'); + $this->itemsApiExpects(2, ListType::FEED, '0'); $this->feedService->expects($this->once()) ->method('findAllForUser') @@ -256,7 +256,7 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, 0, false, false, []) ->will($this->returnValue($result['items'])); - $response = $this->controller->index(FeedType::FEED, 2, 3); + $response = $this->controller->index(ListType::FEED, 2, 3); $this->assertEquals($result, $response); } @@ -271,7 +271,7 @@ class ItemControllerTest extends TestCase 'starred' => 3 ]; - $this->itemsApiExpects(2, FeedType::FOLDER, '0'); + $this->itemsApiExpects(2, ListType::FOLDER, '0'); $this->feedService->expects($this->once()) ->method('findAllForUser') @@ -293,7 +293,7 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, 0, false, false, []) ->will($this->returnValue($result['items'])); - $response = $this->controller->index(FeedType::FOLDER, 2, 3); + $response = $this->controller->index(ListType::FOLDER, 2, 3); $this->assertEquals($result, $response); } @@ -308,7 +308,7 @@ class ItemControllerTest extends TestCase 'starred' => 3 ]; - $this->itemsApiExpects(2, FeedType::STARRED, '0'); + $this->itemsApiExpects(2, ListType::STARRED, '0'); $this->feedService->expects($this->once()) ->method('findAllForUser') @@ -330,7 +330,7 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, 0, false, []) ->will($this->returnValue($result['items'])); - $response = $this->controller->index(FeedType::STARRED, 2, 3); + $response = $this->controller->index(ListType::STARRED, 2, 3); $this->assertEquals($result, $response); } @@ -345,7 +345,7 @@ class ItemControllerTest extends TestCase 'starred' => 3 ]; - $this->itemsApiExpects(2, FeedType::FEED, '0'); + $this->itemsApiExpects(2, ListType::FEED, '0'); $this->feedService->expects($this->once()) ->method('findAllForUser') @@ -367,7 +367,7 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, 0, false, false, ['test', 'search']) ->will($this->returnValue($result['items'])); - $response = $this->controller->index(FeedType::FEED, 2, 3, 0, null, null, 'test%20%20search%20'); + $response = $this->controller->index(ListType::FEED, 2, 3, 0, null, null, 'test%20%20search%20'); $this->assertEquals($result, $response); } @@ -376,7 +376,7 @@ class ItemControllerTest extends TestCase { $result = ['items' => [new Item()]]; - $this->itemsApiExpects(2, FeedType::FEED); + $this->itemsApiExpects(2, ListType::FEED); $this->itemService->expects($this->once()) ->method('findAllInFeedWithFilters') @@ -386,21 +386,21 @@ class ItemControllerTest extends TestCase $this->feedService->expects($this->never()) ->method('findAllForUser'); - $response = $this->controller->index(FeedType::FEED, 2, 3, 10); + $response = $this->controller->index(ListType::FEED, 2, 3, 10); $this->assertEquals($result, $response); } public function testGetItemsNoNewestItemsId() { - $this->itemsApiExpects(2, FeedType::FEED); + $this->itemsApiExpects(2, ListType::FEED); $this->itemService->expects($this->once()) ->method('newest') ->with('user') ->will($this->throwException(new ServiceNotFoundException(''))); - $response = $this->controller->index(FeedType::FEED, 2, 3); + $response = $this->controller->index(ListType::FEED, 2, 3); $this->assertEquals([], $response); } @@ -440,7 +440,7 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, false) ->will($this->returnValue($result['items'])); - $response = $this->controller->newItems(FeedType::FEED, 2, 3); + $response = $this->controller->newItems(ListType::FEED, 2, 3); $this->assertEquals($result, $response); } @@ -480,7 +480,7 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, false) ->will($this->returnValue($result['items'])); - $response = $this->controller->newItems(FeedType::FOLDER, 2, 3); + $response = $this->controller->newItems(ListType::FOLDER, 2, 3); $this->assertEquals($result, $response); } @@ -520,7 +520,7 @@ class ItemControllerTest extends TestCase ->with('user', 6, 3) ->will($this->returnValue($result['items'])); - $response = $this->controller->newItems(FeedType::UNREAD, 2, 3); + $response = $this->controller->newItems(ListType::UNREAD, 2, 3); $this->assertEquals($result, $response); } @@ -537,7 +537,7 @@ class ItemControllerTest extends TestCase ->with('user') ->will($this->throwException(new ServiceNotFoundException(''))); - $response = $this->controller->newItems(FeedType::FEED, 2, 3); + $response = $this->controller->newItems(ListType::FEED, 2, 3); $this->assertEquals([], $response); } diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index 5f62bfe9f..4e2950479 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -15,7 +15,7 @@ namespace OCA\News\Tests\Unit\Controller; use OC\L10N\L10N; use OCA\News\Controller\PageController; -use \OCA\News\Db\FeedType; +use \OCA\News\Db\ListType; use OCA\News\Explore\Exceptions\RecommendedSiteNotFoundException; use OCA\News\Explore\RecommendedSites; use OCA\News\Service\StatusService; @@ -264,7 +264,7 @@ class PageControllerTest extends TestCase ->method('setUserValue') ->withConsecutive( ['becka', 'news', 'lastViewedFeedId', 0], - ['becka', 'news', 'lastViewedFeedType', FeedType::EXPLORE] + ['becka', 'news', 'lastViewedFeedType', ListType::EXPLORE] ); $this->recommended->expects($this->once()) @@ -284,7 +284,7 @@ class PageControllerTest extends TestCase ->method('setUserValue') ->withConsecutive( ['becka', 'news', 'lastViewedFeedId', 0], - ['becka', 'news', 'lastViewedFeedType', FeedType::EXPLORE] + ['becka', 'news', 'lastViewedFeedType', ListType::EXPLORE] ); $this->recommended->expects($this->once()) diff --git a/tests/Unit/Db/ItemMapperTest.php b/tests/Unit/Db/ItemMapperTest.php index 878f8c59d..c1e946d2b 100644 --- a/tests/Unit/Db/ItemMapperTest.php +++ b/tests/Unit/Db/ItemMapperTest.php @@ -13,6 +13,7 @@ namespace OCA\News\Tests\Unit\Db; +use OC\DB\QueryBuilder\Literal; use OCA\News\Db\Feed; use OCA\News\Db\FeedMapperV2; use OCA\News\Db\Folder; @@ -1691,7 +1692,7 @@ class ItemMapperTest extends MapperTestUtility $expr->expects($this->once()) ->method('eq') - ->with('feeds.folder_id', 2) + ->with('feeds.folder_id', new Literal(2)) ->will($this->returnValue('x = y')); $this->db->expects($this->once()) diff --git a/tests/Unit/Service/ItemServiceTest.php b/tests/Unit/Service/ItemServiceTest.php index e82d5eda7..f91692cda 100644 --- a/tests/Unit/Service/ItemServiceTest.php +++ b/tests/Unit/Service/ItemServiceTest.php @@ -21,7 +21,7 @@ use OCA\News\Service\ItemServiceV2; use \OCP\AppFramework\Db\DoesNotExistException; use \OCA\News\Db\Item; -use \OCA\News\Db\FeedType; +use \OCA\News\Db\ListType; use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\IConfig; @@ -133,7 +133,7 @@ class ItemServiceTest extends TestCase $this->mapper->expects($this->never()) ->method('findAllAfter'); - $result = $this->class->findAllAfter($this->user, 3, 20333); + $result = $this->class->findAllAfter($this->user, 5, 20333); $this->assertEquals([], $result); } @@ -176,7 +176,7 @@ class ItemServiceTest extends TestCase public function testFindAllItems() { - $type = FeedType::STARRED; + $type = ListType::STARRED; $this->mapper->expects($this->once()) ->method('findAllItems') ->with('jack', $type, 20, 5, true, []) @@ -188,7 +188,7 @@ class ItemServiceTest extends TestCase public function testFindAllSearch() { - $type = FeedType::STARRED; + $type = ListType::STARRED; $search = ['test']; -- cgit v1.2.3