mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-23 07:33:58 -06:00
Added API test for malformed request JSON body
This commit is contained in:
parent
812c5f4993
commit
112cbb9039
27
module/Rest/test-api/Middleware/BodyParserTest.php
Normal file
27
module/Rest/test-api/Middleware/BodyParserTest.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioApiTest\Shlink\Rest\Middleware;
|
||||
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
||||
|
||||
class BodyParserTest extends ApiTestCase
|
||||
{
|
||||
/** @test */
|
||||
public function returnsErrorWhenRequestBodyIsInvalidJson(): void
|
||||
{
|
||||
$resp = $this->callApiWithKey(self::METHOD_POST, '/short-urls', [
|
||||
RequestOptions::HEADERS => ['content-type' => 'application/json'],
|
||||
RequestOptions::BODY => '{"foo',
|
||||
]);
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
self::assertEquals(400, $resp->getStatusCode());
|
||||
self::assertEquals(400, $payload['status']);
|
||||
self::assertEquals('Provided request does not contain a valid JSON body.', $payload['detail']);
|
||||
self::assertEquals('Malformed request body', $payload['title']);
|
||||
self::assertEquals('https://shlink.io/api/error/malformed-request-body', $payload['type']);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user