Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/tests/Traits/Http/IntegrationJsonRequestAssertions.php
7461 views
1
<?php
2
3
namespace Pterodactyl\Tests\Traits\Http;
4
5
use Illuminate\Http\Response;
6
use Illuminate\Testing\TestResponse;
7
8
trait IntegrationJsonRequestAssertions
9
{
10
/**
11
* Make assertions about a 404 response on the API.
12
*/
13
public function assertNotFoundJson(TestResponse $response): void
14
{
15
$response->assertStatus(Response::HTTP_NOT_FOUND);
16
$response->assertJsonStructure(['errors' => [['code', 'status', 'detail']]]);
17
$response->assertJsonCount(1, 'errors');
18
$response->assertJson([
19
'errors' => [
20
[
21
'code' => 'NotFoundHttpException',
22
'status' => '404',
23
'detail' => 'The requested resource could not be found on the server.',
24
],
25
],
26
], true);
27
}
28
29
/**
30
* Make assertions about a 403 error returned by the API.
31
*/
32
public function assertAccessDeniedJson(TestResponse $response): void
33
{
34
$response->assertStatus(Response::HTTP_FORBIDDEN);
35
$response->assertJsonStructure(['errors' => [['code', 'status', 'detail']]]);
36
$response->assertJsonCount(1, 'errors');
37
$response->assertJson([
38
'errors' => [
39
[
40
'code' => 'AccessDeniedHttpException',
41
'status' => '403',
42
'detail' => 'This action is unauthorized.',
43
],
44
],
45
], true);
46
}
47
}
48
49