diff --git a/module/Rest/test/Action/EditTagsActionTest.php b/module/Rest/test/Action/EditTagsActionTest.php new file mode 100644 index 00000000..b0813519 --- /dev/null +++ b/module/Rest/test/Action/EditTagsActionTest.php @@ -0,0 +1,76 @@ +shortUrlService = $this->prophesize(ShortUrlService::class); + $this->action = new EditTagsAction($this->shortUrlService->reveal(), Translator::factory([])); + } + + /** + * @test + */ + public function notProvidingTagsReturnsError() + { + $response = $this->action->__invoke( + ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123'), + new Response() + ); + $this->assertEquals(400, $response->getStatusCode()); + } + + /** + * @test + */ + public function anInvalidShortCodeReturnsNotFound() + { + $shortCode = 'abc123'; + $this->shortUrlService->setTagsByShortCode($shortCode, [])->willThrow(InvalidShortCodeException::class) + ->shouldBeCalledTimes(1); + + $response = $this->action->__invoke( + ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123') + ->withParsedBody(['tags' => []]), + new Response() + ); + $this->assertEquals(404, $response->getStatusCode()); + } + + /** + * @test + */ + public function tagsListIsReturnedIfCorrectShortCodeIsProvided() + { + $shortCode = 'abc123'; + $this->shortUrlService->setTagsByShortCode($shortCode, [])->willReturn(new ShortUrl()) + ->shouldBeCalledTimes(1); + + $response = $this->action->__invoke( + ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123') + ->withParsedBody(['tags' => []]), + new Response() + ); + $this->assertEquals(200, $response->getStatusCode()); + } +}