Added more strict checks on API errors tests

This commit is contained in:
Alejandro Celaya
2019-11-27 20:48:35 +01:00
parent 5266743a0c
commit d83d2f82bd
8 changed files with 156 additions and 40 deletions

View File

@@ -11,11 +11,19 @@ class DeleteShortUrlActionTest extends ApiTestCase
/** @test */
public function notFoundErrorIsReturnWhenDeletingInvalidUrl(): void
{
$expectedDetail = 'No URL found with short code "invalid"';
$resp = $this->callApiWithKey(self::METHOD_DELETE, '/short-urls/invalid');
['error' => $error] = $this->getJsonResponsePayload($resp);
$payload = $this->getJsonResponsePayload($resp);
$this->assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode());
$this->assertEquals('INVALID_SHORTCODE', $error);
$this->assertEquals(self::STATUS_NOT_FOUND, $payload['status']);
$this->assertEquals('INVALID_SHORTCODE', $payload['type']);
$this->assertEquals('INVALID_SHORTCODE', $payload['error']); // Deprecated
$this->assertEquals($expectedDetail, $payload['detail']);
$this->assertEquals($expectedDetail, $payload['message']); // Deprecated
$this->assertEquals('Short URL not found', $payload['title']);
$this->assertEquals('invalid', $payload['shortCode']);
}
/** @test */
@@ -25,11 +33,17 @@ class DeleteShortUrlActionTest extends ApiTestCase
for ($i = 0; $i < 20; $i++) {
$this->assertEquals(self::STATUS_FOUND, $this->callShortUrl('abc123')->getStatusCode());
}
$expectedDetail = 'Impossible to delete short URL with short code "abc123" since it has more than "15" visits.';
$resp = $this->callApiWithKey(self::METHOD_DELETE, '/short-urls/abc123');
['error' => $error] = $this->getJsonResponsePayload($resp);
$payload = $this->getJsonResponsePayload($resp);
$this->assertEquals(self::STATUS_UNPROCESSABLE_ENTITY, $resp->getStatusCode());
$this->assertEquals('INVALID_SHORTCODE_DELETION', $error);
$this->assertEquals(self::STATUS_UNPROCESSABLE_ENTITY, $payload['status']);
$this->assertEquals('INVALID_SHORTCODE_DELETION', $payload['type']);
$this->assertEquals('INVALID_SHORTCODE_DELETION', $payload['error']); // Deprecated
$this->assertEquals($expectedDetail, $payload['detail']);
$this->assertEquals($expectedDetail, $payload['message']); // Deprecated
$this->assertEquals('Cannot delete short URL', $payload['title']);
}
}