From b18c9e495fa5260eb5f756f764556962171d326f Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 22 Jan 2023 11:47:45 +0100 Subject: [PATCH] Add API test for short URL edition with device long URLs --- .../Rest/test-api/Action/EditShortUrlTest.php | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/module/Rest/test-api/Action/EditShortUrlTest.php b/module/Rest/test-api/Action/EditShortUrlTest.php index fefbdcba..74fdebc5 100644 --- a/module/Rest/test-api/Action/EditShortUrlTest.php +++ b/module/Rest/test-api/Action/EditShortUrlTest.php @@ -154,7 +154,7 @@ class EditShortUrlTest extends ApiTestCase $editResp = $this->callApiWithKey(self::METHOD_PATCH, (string) $url, [RequestOptions::JSON => [ 'maxVisits' => 100, ]]); - $editedShortUrl = $this->getJsonResponsePayload($this->callApiWithKey(self::METHOD_GET, (string) $url)); + $editedShortUrl = $this->getJsonResponsePayload($editResp); self::assertEquals(self::STATUS_OK, $editResp->getStatusCode()); self::assertEquals($domain, $editedShortUrl['domain']); @@ -170,4 +170,27 @@ class EditShortUrlTest extends ApiTestCase ]; yield 'no domain' => [null, 'https://shlink.io/documentation/']; } + + /** @test */ + public function deviceLongUrlsCanBeEdited(): void + { + $shortCode = 'def456'; + $url = new Uri(sprintf('/short-urls/%s', $shortCode)); + $editResp = $this->callApiWithKey(self::METHOD_PATCH, (string) $url, [RequestOptions::JSON => [ + 'deviceLongUrls' => [ + 'android' => null, // This one will get removed + 'ios' => 'https://blog.alejandrocelaya.com/ios/edited', // This one will be edited + 'desktop' => 'https://blog.alejandrocelaya.com/desktop', // This one is new and will be created + ], + ]]); + $deviceLongUrls = $this->getJsonResponsePayload($editResp)['deviceLongUrls'] ?? []; + + self::assertEquals(self::STATUS_OK, $editResp->getStatusCode()); + self::assertArrayHasKey('ios', $deviceLongUrls); + self::assertEquals('https://blog.alejandrocelaya.com/ios/edited', $deviceLongUrls['ios']); + self::assertArrayHasKey('desktop', $deviceLongUrls); + self::assertEquals('https://blog.alejandrocelaya.com/desktop', $deviceLongUrls['desktop']); + self::assertArrayHasKey('android', $deviceLongUrls); + self::assertNull($deviceLongUrls['android']); + } }