misc_pterodactyl-panel/tests/Traits/Http/IntegrationJsonRequestAssertions.php

48 lines
1.4 KiB
PHP
Raw Normal View History

2018-03-04 22:30:16 +00:00
<?php
namespace Pterodactyl\Tests\Traits\Http;
2018-03-04 22:30:16 +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)
{
$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)
{
$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);
}
}