2018-03-04 22:30:16 +00:00
|
|
|
<?php
|
|
|
|
|
2021-01-23 20:09:16 +00:00
|
|
|
namespace Pterodactyl\Tests\Traits\Http;
|
2018-03-04 22:30:16 +00:00
|
|
|
|
2018-03-05 04:35:57 +00:00
|
|
|
use Illuminate\Http\Response;
|
2020-06-26 04:42:21 +00:00
|
|
|
use Illuminate\Testing\TestResponse;
|
2018-03-04 22:30:16 +00:00
|
|
|
|
|
|
|
trait IntegrationJsonRequestAssertions
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Make assertions about a 404 response on the API.
|
|
|
|
*/
|
|
|
|
public function assertNotFoundJson(TestResponse $response)
|
|
|
|
{
|
2018-03-05 04:35:57 +00:00
|
|
|
$response->assertStatus(Response::HTTP_NOT_FOUND);
|
2018-03-04 22:30:16 +00:00
|
|
|
$response->assertJsonStructure(['errors' => [['code', 'status', 'detail']]]);
|
|
|
|
$response->assertJsonCount(1, 'errors');
|
|
|
|
$response->assertJson([
|
|
|
|
'errors' => [
|
|
|
|
[
|
|
|
|
'code' => 'NotFoundHttpException',
|
|
|
|
'status' => '404',
|
2021-08-07 23:17:16 +00:00
|
|
|
'detail' => 'The requested resource could not be found on the server.',
|
2018-03-04 22:30:16 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
], true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make assertions about a 403 error returned by the API.
|
|
|
|
*/
|
|
|
|
public function assertAccessDeniedJson(TestResponse $response)
|
|
|
|
{
|
2018-03-05 04:35:57 +00:00
|
|
|
$response->assertStatus(Response::HTTP_FORBIDDEN);
|
2018-03-04 22:30:16 +00:00
|
|
|
$response->assertJsonStructure(['errors' => [['code', 'status', 'detail']]]);
|
|
|
|
$response->assertJsonCount(1, 'errors');
|
|
|
|
$response->assertJson([
|
|
|
|
'errors' => [
|
|
|
|
[
|
|
|
|
'code' => 'AccessDeniedHttpException',
|
|
|
|
'status' => '403',
|
|
|
|
'detail' => 'This action is unauthorized.',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
], true);
|
|
|
|
}
|
|
|
|
}
|