From 33767251523b5250e04ae288506937f4a5c24545 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 21 Aug 2016 18:06:34 +0200 Subject: [PATCH] Created EditTagsActiontest --- .../Rest/test/Action/EditTagsActionTest.php | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 module/Rest/test/Action/EditTagsActionTest.php 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()); + } +}