diff --git a/module/Rest/test-api/Action/EditShortUrlActionTest.php b/module/Rest/test-api/Action/EditShortUrlActionTest.php index 171a40cc..b5cd4fd4 100644 --- a/module/Rest/test-api/Action/EditShortUrlActionTest.php +++ b/module/Rest/test-api/Action/EditShortUrlActionTest.php @@ -71,6 +71,32 @@ class EditShortUrlActionTest extends ApiTestCase return $matchingShortUrl['meta'] ?? null; } + /** + * @test + * @dataProvider provideLongUrls + */ + public function longUrlCanBeEditedIfItIsValid(string $longUrl, int $expectedStatus, ?string $expectedError): void + { + $shortCode = 'abc123'; + $url = sprintf('/short-urls/%s', $shortCode); + + $resp = $this->callApiWithKey(self::METHOD_PATCH, $url, [RequestOptions::JSON => [ + 'longUrl' => $longUrl, + ]]); + + $this->assertEquals($expectedStatus, $resp->getStatusCode()); + if ($expectedError !== null) { + $payload = $this->getJsonResponsePayload($resp); + $this->assertEquals($expectedError, $payload['type']); + } + } + + public function provideLongUrls(): iterable + { + yield 'valid URL' => ['https://shlink.io', self::STATUS_NO_CONTENT, null]; + yield 'invalid URL' => ['htt:foo', self::STATUS_BAD_REQUEST, 'INVALID_URL']; + } + /** * @test * @dataProvider provideInvalidUrls