Added API tests for the edition of the longURL

This commit is contained in:
Alejandro Celaya 2020-03-22 17:30:01 +01:00
parent 5432eb7b77
commit 3beb27acc2

View file

@ -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