From 582c4d11facc0c8c97ae14d370b6c4f69b210124 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Mon, 18 Jan 2021 19:56:26 +0100 Subject: Controllers: Fetch feed after creating Signed-off-by: Sean Molenaar --- CHANGELOG.md | 2 ++ lib/Controller/FeedApiController.php | 2 ++ lib/Controller/FeedController.php | 2 ++ tests/Unit/Controller/FeedApiControllerTest.php | 8 ++++++++ tests/Unit/Controller/FeedControllerTest.php | 21 +++++++++++++++++++-- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd6f7cdda..32c749594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ The format is almost based on [Keep a Changelog](https://keepachangelog.com/en/1 ### Fixed +- Fetch feed after creation (#1058) + ## [15.2.0-beta2] - 2021-01-17 ### Fixed diff --git a/lib/Controller/FeedApiController.php b/lib/Controller/FeedApiController.php index 629f2c482..29f79b3ec 100644 --- a/lib/Controller/FeedApiController.php +++ b/lib/Controller/FeedApiController.php @@ -111,6 +111,8 @@ class FeedApiController extends ApiController $feed = $this->feedService->create($this->getUserId(), $url, $folderId); $result = ['feeds' => $this->serialize($feed)]; + $this->feedService->fetch($feed); + try { $result['newestItemId'] = $this->oldItemService->getNewestItemId($this->getUserId()); } catch (ServiceNotFoundException $ex) { diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php index ba39fdf7a..9f7c9b0d6 100644 --- a/lib/Controller/FeedController.php +++ b/lib/Controller/FeedController.php @@ -180,6 +180,8 @@ class FeedController extends Controller ); $params = ['feeds' => [$feed]]; + $this->feedService->fetch($feed); + try { $id = $this->itemService->getNewestItemId($this->getUserId()); // An exception occurs if there is a newest item. If there is none, diff --git a/tests/Unit/Controller/FeedApiControllerTest.php b/tests/Unit/Controller/FeedApiControllerTest.php index b31d9fd43..a6a1db548 100644 --- a/tests/Unit/Controller/FeedApiControllerTest.php +++ b/tests/Unit/Controller/FeedApiControllerTest.php @@ -198,6 +198,10 @@ class FeedApiControllerTest extends TestCase ->method('create') ->with($this->userID, 'url', 3) ->will($this->returnValue($feeds[0])); + + $this->feedService->expects($this->once()) + ->method('fetch') + ->with($feeds[0]); $this->itemService->expects($this->once()) ->method('getNewestItemId') ->will($this->returnValue(3)); @@ -225,6 +229,10 @@ class FeedApiControllerTest extends TestCase ->method('create') ->with($this->userID, 'ho', 3) ->will($this->returnValue($feeds[0])); + + $this->feedService->expects($this->once()) + ->method('fetch') + ->with($feeds[0]); $this->itemService->expects($this->once()) ->method('getNewestItemId') ->will($this->throwException(new ServiceNotFoundException(''))); diff --git a/tests/Unit/Controller/FeedControllerTest.php b/tests/Unit/Controller/FeedControllerTest.php index 487ef0af1..871b781e0 100644 --- a/tests/Unit/Controller/FeedControllerTest.php +++ b/tests/Unit/Controller/FeedControllerTest.php @@ -187,8 +187,13 @@ class FeedControllerTest extends TestCase } - - private function activeInitMocks($id, $type) + /** + * Configure settings with active mocks + * + * @param $id + * @param $type + */ + private function activeInitMocks($id, $type): void { $this->settings->expects($this->exactly(2)) ->method('getUserValue') @@ -313,6 +318,10 @@ class FeedControllerTest extends TestCase $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->uid, false); + + $this->feedService->expects($this->once()) + ->method('fetch') + ->with($result['feeds'][0]); $this->feedService->expects($this->once()) ->method('create') ->with($this->uid, 'hi', 4, false, 'yo') @@ -337,6 +346,10 @@ class FeedControllerTest extends TestCase $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->uid, false); + + $this->feedService->expects($this->once()) + ->method('fetch') + ->with($result['feeds'][0]); $this->feedService->expects($this->once()) ->method('create') ->with($this->uid, 'hi', null, false, 'yo') @@ -365,6 +378,10 @@ class FeedControllerTest extends TestCase ->with($this->uid, 'hi', 4, false, 'yo') ->will($this->returnValue($result['feeds'][0])); + $this->feedService->expects($this->once()) + ->method('fetch') + ->with($result['feeds'][0]); + $response = $this->class->create('hi', 4, 'yo'); $this->assertEquals($result, $response); -- cgit v1.2.3