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.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function assertNotFoundJson(TestResponse $response): void
|
2018-03-04 22:30:16 +00:00
|
|
|
{
|
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',
|
2022-05-22 18:10:01 +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.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function assertAccessDeniedJson(TestResponse $response): void
|
2018-03-04 22:30:16 +00:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
}
|