diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2021-01-02 17:57:17 +0100 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2021-02-13 13:22:57 +0100 |
commit | b4fa772bc5f23f84fc292f5d6bf884543d2bfe51 (patch) | |
tree | 8576ad3ea145f3644804e2fd93de462cfc2c2578 /tests | |
parent | ceba81060303e49b2617397397f2804516052ec9 (diff) |
Remove V1 item API
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Unit/Command/FolderDeleteTest.php | 2 | ||||
-rw-r--r-- | tests/Unit/Controller/FeedApiControllerTest.php | 46 | ||||
-rw-r--r-- | tests/Unit/Controller/FeedControllerTest.php | 73 | ||||
-rw-r--r-- | tests/Unit/Controller/FolderApiControllerTest.php | 50 | ||||
-rw-r--r-- | tests/Unit/Controller/FolderControllerTest.php | 74 | ||||
-rw-r--r-- | tests/Unit/Controller/ItemApiControllerTest.php | 288 | ||||
-rw-r--r-- | tests/Unit/Controller/ItemControllerTest.php | 246 | ||||
-rw-r--r-- | tests/Unit/Controller/PageControllerTest.php | 22 | ||||
-rw-r--r-- | tests/Unit/Db/FeedMapperTest.php | 92 | ||||
-rw-r--r-- | tests/Unit/Db/FolderMapperTest.php | 90 | ||||
-rw-r--r-- | tests/Unit/Db/ItemMapperTest.php | 2360 | ||||
-rw-r--r-- | tests/Unit/Db/MapperFactoryTest.php | 59 | ||||
-rw-r--r-- | tests/Unit/Db/MapperTestUtility.php | 2 | ||||
-rw-r--r-- | tests/Unit/Service/FeedServiceTest.php | 21 | ||||
-rw-r--r-- | tests/Unit/Service/FolderServiceTest.php | 17 | ||||
-rw-r--r-- | tests/Unit/Service/ItemServiceTest.php | 640 | ||||
-rw-r--r-- | tests/Unit/Service/ServiceTest.php | 4 | ||||
-rw-r--r-- | tests/psalm-baseline.xml | 42 |
18 files changed, 3534 insertions, 594 deletions
diff --git a/tests/Unit/Command/FolderDeleteTest.php b/tests/Unit/Command/FolderDeleteTest.php index c87b05acd..e9076d9ba 100644 --- a/tests/Unit/Command/FolderDeleteTest.php +++ b/tests/Unit/Command/FolderDeleteTest.php @@ -82,7 +82,7 @@ class FolderDeleteTest extends TestCase */ public function testInValid() { - $this->expectException('OCA\News\Service\Exceptions\ServiceException'); + $this->expectException('OCA\News\Service\Exceptions\ServiceValidationException'); $this->expectExceptionMessage('Can not remove root folder!'); $this->consoleInput->expects($this->exactly(2)) diff --git a/tests/Unit/Controller/FeedApiControllerTest.php b/tests/Unit/Controller/FeedApiControllerTest.php index a6a1db548..4e6f5f1f3 100644 --- a/tests/Unit/Controller/FeedApiControllerTest.php +++ b/tests/Unit/Controller/FeedApiControllerTest.php @@ -18,7 +18,7 @@ namespace OCA\News\Tests\Unit\Controller; use Exception; use OCA\News\Controller\FeedApiController; use OCA\News\Service\FeedServiceV2; -use OCA\News\Service\ItemService; +use OCA\News\Service\ItemServiceV2; use \OCP\AppFramework\Http; use \OCA\News\Service\Exceptions\ServiceNotFoundException; @@ -40,7 +40,7 @@ class FeedApiControllerTest extends TestCase private $feedService; /** - * @var \PHPUnit\Framework\MockObject\MockObject|ItemService + * @var \PHPUnit\Framework\MockObject\MockObject|ItemServiceV2 */ private $itemService; @@ -80,7 +80,7 @@ class FeedApiControllerTest extends TestCase $this->feedService = $this->getMockBuilder(FeedServiceV2::class) ->disableOriginalConstructor() ->getMock(); - $this->itemService = $this->getMockBuilder(ItemService::class) + $this->itemService = $this->getMockBuilder(ItemServiceV2::class) ->disableOriginalConstructor() ->getMock(); $this->class = new FeedApiController( @@ -96,18 +96,17 @@ class FeedApiControllerTest extends TestCase public function testIndex() { - $feeds = [new Feed()]; - $starredCount = 3; - $newestItemId = 2; + $feed = Feed::fromParams(['id' => 5]); + $feeds = [$feed]; $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with($this->equalTo($this->userID)) - ->will($this->returnValue($starredCount)); + ->will($this->returnValue([1, 2, 3])); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->with($this->equalTo($this->userID)) - ->will($this->returnValue($newestItemId)); + ->will($this->returnValue($feeds[0])); $this->feedService->expects($this->once()) ->method('findAllForUser') ->with($this->equalTo($this->userID)) @@ -118,8 +117,8 @@ class FeedApiControllerTest extends TestCase $this->assertEquals( [ 'feeds' => [$feeds[0]->toAPI()], - 'starredCount' => $starredCount, - 'newestItemId' => $newestItemId + 'starredCount' => 3, + 'newestItemId' => 5 ], $response ); @@ -129,14 +128,13 @@ class FeedApiControllerTest extends TestCase public function testIndexNoNewestItemId() { $feeds = [new Feed()]; - $starredCount = 3; $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with($this->equalTo($this->userID)) - ->will($this->returnValue($starredCount)); + ->will($this->returnValue([1, 2, 3])); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->with($this->equalTo($this->userID)) ->will($this->throwException(new ServiceNotFoundException(''))); $this->feedService->expects($this->once()) @@ -149,7 +147,7 @@ class FeedApiControllerTest extends TestCase $this->assertEquals( [ 'feeds' => [$feeds[0]->toAPI()], - 'starredCount' => $starredCount, + 'starredCount' => 3, ], $response ); @@ -203,8 +201,8 @@ class FeedApiControllerTest extends TestCase ->method('fetch') ->with($feeds[0]); $this->itemService->expects($this->once()) - ->method('getNewestItemId') - ->will($this->returnValue(3)); + ->method('newest') + ->will($this->returnValue(Feed::fromParams(['id' => 3]))); $response = $this->class->create('url', 3); @@ -234,7 +232,7 @@ class FeedApiControllerTest extends TestCase ->method('fetch') ->with($feeds[0]); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->will($this->throwException(new ServiceNotFoundException(''))); $response = $this->class->create('ho', 3); @@ -287,12 +285,8 @@ class FeedApiControllerTest extends TestCase public function testRead() { $this->itemService->expects($this->once()) - ->method('readFeed') - ->with( - $this->equalTo(3), - $this->equalTo(30), - $this->equalTo($this->userID) - ); + ->method('read') + ->with($this->userID,3,30); $this->class->read(3, 30); } diff --git a/tests/Unit/Controller/FeedControllerTest.php b/tests/Unit/Controller/FeedControllerTest.php index 871b781e0..b8929d373 100644 --- a/tests/Unit/Controller/FeedControllerTest.php +++ b/tests/Unit/Controller/FeedControllerTest.php @@ -18,7 +18,7 @@ use OCA\News\Db\Folder; use OCA\News\Service\FeedServiceV2; use OCA\News\Service\FolderServiceV2; use OCA\News\Service\ImportService; -use OCA\News\Service\ItemService; +use OCA\News\Service\ItemServiceV2; use OCP\AppFramework\Http; use OCA\News\Db\Feed; @@ -55,8 +55,7 @@ class FeedControllerTest extends TestCase */ private $importService; /** - * TODO: Remove - * @var MockObject|ItemService + * @var MockObject|ItemServiceV2 */ private $itemService; @@ -87,7 +86,7 @@ class FeedControllerTest extends TestCase ->disableOriginalConstructor() ->getMock(); $this->itemService = $this - ->getMockBuilder(ItemService::class) + ->getMockBuilder(ItemServiceV2::class) ->disableOriginalConstructor() ->getMock(); $this->feedService = $this @@ -138,20 +137,20 @@ class FeedControllerTest extends TestCase 'feeds' => [ ['a feed'], ], - 'starred' => 13 + 'starred' => 4 ]; $this->feedService->expects($this->once()) ->method('findAllForUser') ->with($this->uid) ->will($this->returnValue($result['feeds'])); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->with($this->uid) ->will($this->throwException(new ServiceNotFoundException(''))); $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with($this->uid) - ->will($this->returnValue($result['starred'])); + ->will($this->returnValue([1, 2, 3, 4])); $response = $this->class->index(); @@ -165,7 +164,7 @@ class FeedControllerTest extends TestCase 'feeds' => [ ['a feed'], ], - 'starred' => 13, + 'starred' => 2, 'newestItemId' => 5 ]; $this->feedService->expects($this->once()) @@ -173,13 +172,13 @@ class FeedControllerTest extends TestCase ->with($this->uid) ->will($this->returnValue($result['feeds'])); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->with($this->uid) - ->will($this->returnValue($result['newestItemId'])); + ->will($this->returnValue(Feed::fromParams(['id' => 5]))); $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with($this->uid) - ->will($this->returnValue($result['starred'])); + ->will($this->returnValue([1, 2])); $response = $this->class->index(); @@ -224,6 +223,30 @@ class FeedControllerTest extends TestCase } + public function testActiveFeed() + { + $id = 3; + $type = FeedType::FEED; + $result = [ + 'activeFeed' => [ + 'id' => $id, + 'type' => $type + ] + ]; + + $this->feedService->expects($this->once()) + ->method('find') + ->with($this->uid, $id) + ->will($this->returnValue(new Feed())); + + $this->activeInitMocks($id, $type); + + $response = $this->class->active(); + + $this->assertEquals($result, $response); + } + + public function testActiveFeedDoesNotExist() { $id = 3; @@ -313,8 +336,8 @@ class FeedControllerTest extends TestCase ]; $this->itemService->expects($this->once()) - ->method('getNewestItemId') - ->will($this->returnValue($result['newestItemId'])); + ->method('newest') + ->will($this->returnValue(Feed::fromParams(['id' => 3]))); $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->uid, false); @@ -341,8 +364,8 @@ class FeedControllerTest extends TestCase ]; $this->itemService->expects($this->once()) - ->method('getNewestItemId') - ->will($this->returnValue($result['newestItemId'])); + ->method('newest') + ->will($this->returnValue(Feed::fromParams(['id' => 3]))); $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->uid, false); @@ -370,7 +393,7 @@ class FeedControllerTest extends TestCase ->with($this->uid, false); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->will($this->throwException(new ServiceNotFoundException(''))); $this->feedService->expects($this->once()) @@ -522,9 +545,9 @@ class FeedControllerTest extends TestCase ->will($this->returnValue($feed)); $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with($this->uid) - ->will($this->returnValue(3)); + ->will($this->returnValue([1, 2, 3])); $response = $this->class->import(['json']); @@ -540,9 +563,9 @@ class FeedControllerTest extends TestCase ->will($this->returnValue(null)); $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with($this->uid) - ->will($this->returnValue(3)); + ->will($this->returnValue([1, 2, 3])); $response = $this->class->import(['json']); @@ -561,9 +584,9 @@ class FeedControllerTest extends TestCase ] ]; - $this->itemService->expects($this->once()) - ->method('readFeed') - ->with(4, 5, $this->uid); + $this->feedService->expects($this->once()) + ->method('read') + ->with($this->uid, 4, 5); $response = $this->class->read(4, 5); $this->assertEquals($expected, $response); diff --git a/tests/Unit/Controller/FolderApiControllerTest.php b/tests/Unit/Controller/FolderApiControllerTest.php index 858e7ff9e..1964f7b47 100644 --- a/tests/Unit/Controller/FolderApiControllerTest.php +++ b/tests/Unit/Controller/FolderApiControllerTest.php @@ -37,7 +37,7 @@ class FolderApiControllerTest extends TestCase private $folderService; private $itemService; - private $folderAPI; + private $class; private $user; private $msg; @@ -65,7 +65,7 @@ class FolderApiControllerTest extends TestCase $this->itemService = $this->getMockBuilder(ItemService::class) ->disableOriginalConstructor() ->getMock(); - $this->folderAPI = new FolderApiController( + $this->class = new FolderApiController( $request, $userSession, $this->folderService, @@ -84,7 +84,7 @@ class FolderApiControllerTest extends TestCase ->with($this->equalTo($this->user->getUID())) ->will($this->returnValue($folders)); - $response = $this->folderAPI->index(); + $response = $this->class->index(); $this->assertEquals( [ @@ -108,7 +108,7 @@ class FolderApiControllerTest extends TestCase ->with($this->user->getUID(), $folderName) ->will($this->returnValue($folder)); - $response = $this->folderAPI->create($folderName); + $response = $this->class->create($folderName); $this->assertEquals( [ @@ -129,7 +129,7 @@ class FolderApiControllerTest extends TestCase ->method('create') ->will($this->throwException(new ServiceConflictException($msg))); - $response = $this->folderAPI->create('hi'); + $response = $this->class->create('hi'); $data = $response->getData(); $this->assertEquals($msg, $data['message']); @@ -148,7 +148,7 @@ class FolderApiControllerTest extends TestCase ->method('create') ->will($this->throwException(new ServiceValidationException($msg))); - $response = $this->folderAPI->create('hi'); + $response = $this->class->create('hi'); $data = $response->getData(); $this->assertEquals($msg, $data['message']); @@ -164,7 +164,7 @@ class FolderApiControllerTest extends TestCase ->method('delete') ->with($this->user->getUID(), 23); - $this->folderAPI->delete(23); + $this->class->delete(23); } @@ -180,7 +180,7 @@ class FolderApiControllerTest extends TestCase ) ); - $response = $this->folderAPI->delete($folderId); + $response = $this->class->delete($folderId); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); @@ -197,7 +197,7 @@ class FolderApiControllerTest extends TestCase ->method('rename') ->with($this->user->getUID(), $folderId, $folderName); - $this->folderAPI->update($folderId, $folderName); + $this->class->update($folderId, $folderName); } public function testUpdateDoesNotExist() @@ -213,7 +213,7 @@ class FolderApiControllerTest extends TestCase ) ); - $response = $this->folderAPI->update($folderId, $folderName); + $response = $this->class->update($folderId, $folderName); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); @@ -234,7 +234,7 @@ class FolderApiControllerTest extends TestCase ) ); - $response = $this->folderAPI->update($folderId, $folderName); + $response = $this->class->update($folderId, $folderName); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); @@ -255,7 +255,7 @@ class FolderApiControllerTest extends TestCase ) ); - $response = $this->folderAPI->update($folderId, $folderName); + $response = $this->class->update($folderId, $folderName); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); @@ -267,15 +267,25 @@ class FolderApiControllerTest extends TestCase public function testRead() { - $this->itemService->expects($this->once()) - ->method('readFolder') - ->with( - $this->equalTo(3), - $this->equalTo(30), - $this->equalTo($this->user->getUID()) - ); + $this->folderService->expects($this->once()) + ->method('read') + ->with($this->user->getUID(), 3, 30); + + $this->class->read(3, 30); + } + + public function testUpdateRoot() + { + $response = $this->class->update(null, ''); + $this->assertSame(400, $response->getStatus()); + + } + + public function testDeleteRoot() + { + $response = $this->class->delete(null); + $this->assertSame(400, $response->getStatus()); - $this->folderAPI->read(3, 30); } diff --git a/tests/Unit/Controller/FolderControllerTest.php b/tests/Unit/Controller/FolderControllerTest.php index 18f4114b6..4f46e1211 100644 --- a/tests/Unit/Controller/FolderControllerTest.php +++ b/tests/Unit/Controller/FolderControllerTest.php @@ -84,8 +84,6 @@ class FolderControllerTest extends TestCase $this->class = new FolderController( $request, $this->folderService, - $this->feedService, - $this->itemService, $this->userSession ); $this->msg = 'ron'; @@ -162,6 +160,16 @@ class FolderControllerTest extends TestCase $this->class->delete(5); } + public function testDeleteRoot() + { + $this->folderService->expects($this->never()) + ->method('markDelete') + ->with('jack', 5, true); + + $response = $this->class->delete(null); + $this->assertEquals(400, $response->getStatus()); + } + public function testDeleteDoesNotExist() { $this->folderService->expects($this->once()) @@ -176,6 +184,20 @@ class FolderControllerTest extends TestCase $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } + public function testDeleteConflict() + { + $this->folderService->expects($this->once()) + ->method('markDelete') + ->will($this->throwException(new ServiceConflictException($this->msg))); + + $response = $this->class->delete(5); + + $params = json_decode($response->render(), true); + + $this->assertEquals($this->msg, $params['message']); + $this->assertEquals($response->getStatus(), Http::STATUS_CONFLICT); + } + public function testRename() { $folder = new Folder(); @@ -186,11 +208,21 @@ class FolderControllerTest extends TestCase ->with('jack', 4, 'tech') ->will($this->returnValue($folder)); - $response = $this->class->rename('tech', 4); + $response = $this->class->rename(4, 'tech'); $this->assertEquals($result, $response); } + public function testRenameRoot() + { + $this->folderService->expects($this->never()) + ->method('rename'); + + $response = $this->class->rename(null, 'tech'); + + $this->assertEquals(400, $response->getStatus()); + } + public function testRenameDoesNotExist() { $msg = 'except'; @@ -199,7 +231,7 @@ class FolderControllerTest extends TestCase ->method('rename') ->will($this->throwException($ex)); - $response = $this->class->rename('tech', 5); + $response = $this->class->rename(5, 'tech'); $params = json_decode($response->render(), true); $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); @@ -215,7 +247,7 @@ class FolderControllerTest extends TestCase ->method('rename') ->will($this->throwException($ex)); - $response = $this->class->rename('tech', 1); + $response = $this->class->rename(1, 'tech'); $params = json_decode($response->render(), true); $this->assertEquals($response->getStatus(), Http::STATUS_CONFLICT); @@ -226,19 +258,11 @@ class FolderControllerTest extends TestCase public function testRead() { - $feed = new Feed(); - $expected = ['feeds' => [$feed->toAPI()]]; - - $this->itemService->expects($this->once()) - ->method('readFolder') - ->with(4, 5, 'jack'); - $this->feedService->expects($this->once()) - ->method('findAllForUser') - ->with('jack') - ->will($this->returnValue([$feed])); + $this->folderService->expects($this->once()) + ->method('read') + ->with('jack', 4, 5); - $response = $this->class->read(4, 5); - $this->assertEquals($expected, $response); + $this->class->read(4, 5); } @@ -267,4 +291,20 @@ class FolderControllerTest extends TestCase $this->assertEquals($this->msg, $params['message']); } + + public function testRestoreConflict() + { + $this->folderService->expects($this->once()) + ->method('markDelete') + ->with('jack', 5, false) + ->will($this->throwException(new ServiceConflictException($this->msg))); + + $response = $this->class->restore(5); + + $params = json_decode($response->render(), true); + + $this->assertEquals(Http::STATUS_CONFLICT, $response->getStatus()); + $this->assertEquals($this->msg, $params['message']); + } + }
\ No newline at end of file diff --git a/tests/Unit/Controller/ItemApiControllerTest.php b/tests/Unit/Controller/ItemApiControllerTest.php index 91181333a..85e359705 100644 --- a/tests/Unit/Controller/ItemApiControllerTest.php +++ b/tests/Unit/Controller/ItemApiControllerTest.php @@ -16,7 +16,6 @@ namespace OCA\News\Tests\Unit\Controller; use OCA\News\Controller\ItemApiController; -use OCA\News\Service\ItemService; use OCA\News\Service\ItemServiceV2; use \OCP\AppFramework\Http; @@ -31,18 +30,28 @@ use PHPUnit\Framework\TestCase; class ItemApiControllerTest extends TestCase { - + /** + * @var ItemServiceV2|\PHPUnit\Framework\MockObject\MockObject + */ private $itemService; - private $oldItemService; - private $class; + /** + * @var IUserSession|\PHPUnit\Framework\MockObject\MockObject + */ private $userSession; + /** + * @var IUser|\PHPUnit\Framework\MockObject\MockObject + */ private $user; + /** + * @var IRequest|\PHPUnit\Framework\MockObject\MockObject + */ private $request; private $msg; + private $uid = 'tom'; + private $class; protected function setUp(): void { - $this->user = 'tom'; $this->appName = 'news'; $this->request = $this->getMockBuilder(IRequest::class) ->disableOriginalConstructor() @@ -58,24 +67,20 @@ class ItemApiControllerTest extends TestCase ->will($this->returnValue($this->user)); $this->user->expects($this->any()) ->method('getUID') - ->will($this->returnValue('123')); - $this->oldItemService = $this->getMockBuilder(ItemService::class) - ->disableOriginalConstructor() - ->getMock(); + ->will($this->returnValue($this->uid)); $this->itemService = $this->getMockBuilder(ItemServiceV2::class) ->disableOriginalConstructor() ->getMock(); $this->class = new ItemApiController( $this->request, $this->userSession, - $this->oldItemService, $this->itemService ); $this->msg = 'hi'; } - public function testIndex() + public function testIndexForFeed() { $item = new Item(); $item->setId(5); @@ -83,26 +88,52 @@ class ItemApiControllerTest extends TestCase $item->setGuidHash('guidhash'); $item->setFeedId(123); - $this->oldItemService->expects($this->once()) - ->method('findAllItems') - ->with( - $this->equalTo(2), - $this->equalTo(1), - $this->equalTo(30), - $this->equalTo(20), - $this->equalTo(true), - $this->equalTo(true), - $this->equalTo($this->user->getUID()) - ) + $this->itemService->expects($this->once()) + ->method('findAllInFeedWithFilters') + ->with($this->uid, 2, 30, 20, false, true) + ->will($this->returnValue([$item])); + + $response = $this->class->index(0, 2, true, 30, 20, true); + + $this->assertEquals(['items' => [$item->toApi()]], $response); + } + + + public function testIndexForFolder() + { + $item = new Item(); + $item->setId(5); + $item->setGuid('guid'); + $item->setGuidHash('guidhash'); + $item->setFeedId(123); + + $this->itemService->expects($this->once()) + ->method('findAllInFolderWithFilters') + ->with($this->uid, 2, 30, 20, false, true) ->will($this->returnValue([$item])); $response = $this->class->index(1, 2, true, 30, 20, true); - $this->assertEquals( - [ - 'items' => [$item->toApi()] - ], $response - ); + $this->assertEquals(['items' => [$item->toApi()]], $response); + } + + + public function testIndexForItems() + { + $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, 3, 30, 20, true) + ->will($this->returnValue([$item])); + |