From e87d4d61bc7a15adb27df6e9df9bde284262106a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 2 Feb 2020 10:53:49 +0100 Subject: [PATCH] Added API test for editing tags with and without domain --- .../Action/EditShortUrlTagsActionTest.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/module/Rest/test-api/Action/EditShortUrlTagsActionTest.php b/module/Rest/test-api/Action/EditShortUrlTagsActionTest.php index d48ffc5f..f120adf8 100644 --- a/module/Rest/test-api/Action/EditShortUrlTagsActionTest.php +++ b/module/Rest/test-api/Action/EditShortUrlTagsActionTest.php @@ -41,4 +41,25 @@ class EditShortUrlTagsActionTest extends ApiTestCase $this->assertEquals('Short URL not found', $payload['title']); $this->assertEquals('invalid', $payload['shortCode']); } + + /** @test */ + public function tagsAreSetOnProperShortUrlBasedOnProvidedDomain(): void + { + $urlWithoutDomain = '/short-urls/ghi789/tags'; + $urlWithDomain = $urlWithoutDomain . '?domain=example.com'; + + $setTagsWithDomain = $this->callApiWithKey(self::METHOD_PUT, $urlWithDomain, [RequestOptions::JSON => [ + 'tags' => ['foo', 'bar'], + ]]); + $fetchWithoutDomain = $this->getJsonResponsePayload( + $this->callApiWithKey(self::METHOD_GET, '/short-urls/ghi789'), + ); + $fetchWithDomain = $this->getJsonResponsePayload( + $this->callApiWithKey(self::METHOD_GET, '/short-urls/ghi789?domain=example.com'), + ); + + $this->assertEquals(self::STATUS_OK, $setTagsWithDomain->getStatusCode()); + $this->assertEquals([], $fetchWithoutDomain['tags']); + $this->assertEquals(['bar', 'foo'], $fetchWithDomain['tags']); + } }