From 909631896836e4ad0e81da0d68a7ecded1314d3e Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 20 Nov 2019 20:38:19 +0100 Subject: [PATCH] Created API tests for errors when deleting short URLs --- module/Rest/src/Util/RestUtils.php | 1 - .../Action/DeleteShortUrlActionTest.php | 37 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 module/Rest/test-api/Action/DeleteShortUrlActionTest.php diff --git a/module/Rest/src/Util/RestUtils.php b/module/Rest/src/Util/RestUtils.php index 3b56fef0..60aade54 100644 --- a/module/Rest/src/Util/RestUtils.php +++ b/module/Rest/src/Util/RestUtils.php @@ -9,7 +9,6 @@ use Shlinkio\Shlink\Core\Exception as Core; use Shlinkio\Shlink\Rest\Exception as Rest; use Throwable; -/** @deprecated */ class RestUtils { public const INVALID_SHORTCODE_ERROR = 'INVALID_SHORTCODE'; diff --git a/module/Rest/test-api/Action/DeleteShortUrlActionTest.php b/module/Rest/test-api/Action/DeleteShortUrlActionTest.php new file mode 100644 index 00000000..60631565 --- /dev/null +++ b/module/Rest/test-api/Action/DeleteShortUrlActionTest.php @@ -0,0 +1,37 @@ +callApiWithKey(self::METHOD_DELETE, '/short-urls/invalid'); + ['error' => $error] = $this->getJsonResponsePayload($resp); + + $this->assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode()); + $this->assertEquals(RestUtils::INVALID_SHORTCODE_ERROR, $error); + } + + /** @test */ + public function badRequestIsReturnedWhenTryingToDeleteUrlWithTooManyVisits(): void + { + // Generate visits first + for ($i = 0; $i < 20; $i++) { + $this->assertEquals(self::STATUS_FOUND, $this->callShortUrl('abc123')->getStatusCode()); + } + + $resp = $this->callApiWithKey(self::METHOD_DELETE, '/short-urls/abc123'); + ['error' => $error] = $this->getJsonResponsePayload($resp); + + $this->assertEquals(self::STATUS_BAD_REQUEST, $resp->getStatusCode()); + $this->assertEquals(RestUtils::INVALID_SHORTCODE_DELETION_ERROR, $error); + } +}