diff --git a/lib/REST/Miniflux/V1.php b/lib/REST/Miniflux/V1.php index 2ad0f66f..2438494e 100644 --- a/lib/REST/Miniflux/V1.php +++ b/lib/REST/Miniflux/V1.php @@ -702,6 +702,18 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler { return new Response($out); } + protected function getFeed(array $path): ResponseInterface { + $tr = Arsse::$db->begin(); + try { + $sub = Arsse::$db->subscriptionPropertiesGet(Arsse::$user->id, (int) $path[1]); + } catch (ExceptionInput $e) { + return new ErrorResponse("404", 404); + } + // compile the list of folders; the feed list includes folder names + $folders = $this->mapFolders(); + return new Response($this->transformFeed($sub, $folders)); + } + protected function createFeed(array $data): ResponseInterface { try { Arsse::$db->feedAdd($data['feed_url'], (string) $data['username'], (string) $data['password'], false, (bool) $data['crawler']); diff --git a/tests/cases/REST/Miniflux/TestV1.php b/tests/cases/REST/Miniflux/TestV1.php index dae4e415..9b5877d7 100644 --- a/tests/cases/REST/Miniflux/TestV1.php +++ b/tests/cases/REST/Miniflux/TestV1.php @@ -564,9 +564,7 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest { } public function testListFeedsOfTheRootCategory(): void { - \Phake::when(Arsse::$db)->folderList->thenReturn(new Result($this->v([ - ['id' => 5, 'name' => "Cat Ook"], - ]))); + \Phake::when(Arsse::$db)->folderList->thenReturn(new Result($this->v([['id' => 5, 'name' => "Cat Ook"],]))); \Phake::when(Arsse::$db)->subscriptionList->thenReturn(new Result($this->v($this->feeds))); $exp = new Response($this->feedsOut); $this->assertMessage($exp, $this->req("GET", "/categories/1/feeds")); @@ -580,6 +578,21 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest { \Phake::verify(Arsse::$db)->subscriptionList(Arsse::$user->id, 2111, true); } + public function testGetAFeed(): void { + \Phake::when(Arsse::$db)->subscriptionPropertiesGet->thenReturn($this->v($this->feeds[0]))->thenReturn($this->v($this->feeds[1])); + \Phake::when(Arsse::$db)->folderList->thenReturn(new Result($this->v([['id' => 5, 'name' => "Cat Ook"],]))); + $this->assertMessage(new Response($this->feedsOut[0]), $this->req("GET", "/feeds/1")); + \Phake::verify(Arsse::$db)->subscriptionPropertiesGet(Arsse::$user->id, 1); + $this->assertMessage(new Response($this->feedsOut[1]), $this->req("GET", "/feeds/55")); + \Phake::verify(Arsse::$db)->subscriptionPropertiesGet(Arsse::$user->id, 55); + } + + public function testGetAMissingFeed(): void { + \Phake::when(Arsse::$db)->subscriptionPropertiesGet->thenThrow(new ExceptionInput("subjectMissing")); + $this->assertMessage(new ErrorResponse("404", 404), $this->req("GET", "/feeds/1")); + \Phake::verify(Arsse::$db)->subscriptionPropertiesGet(Arsse::$user->id, 1); + } + /** @dataProvider provideFeedCreations */ public function testCreateAFeed(array $in, $out1, $out2, $out3, $out4, ResponseInterface $exp): void { if ($out1 instanceof \Exception) {