Add API test for short URL edition with device long URLs

This commit is contained in:
Alejandro Celaya 2023-01-22 11:47:45 +01:00
parent d3590234a3
commit b18c9e495f

View file

@ -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']);
}
}