misc_pterodactyl-panel/tests/Traits/Http/IntegrationJsonRequestAssertions.php
DaneEveritt e313dff674
Massively simplify API binding logic
Changes the API internals to use normal Laravel binding which automatically supports nested-models and can determine their relationships. This removes a lot of confusingly complex internal logic and replaces it with standard Laravel code.

This also removes a deprecated "getModel" method and fully replaces it with a "parameter" method that does stricter type-checking.
2022-05-22 14:10:01 -04:00

47 lines
1.4 KiB
PHP

<?php
namespace Pterodactyl\Tests\Traits\Http;
use Illuminate\Http\Response;
use Illuminate\Testing\TestResponse;
trait IntegrationJsonRequestAssertions
{
/**
* Make assertions about a 404 response on the API.
*/
public function assertNotFoundJson(TestResponse $response)
{
$response->assertStatus(Response::HTTP_NOT_FOUND);
$response->assertJsonStructure(['errors' => [['code', 'status', 'detail']]]);
$response->assertJsonCount(1, 'errors');
$response->assertJson([
'errors' => [
[
'code' => 'NotFoundHttpException',
'status' => '404',
'detail' => 'The requested resource could not be found on the server.',
],
],
], true);
}
/**
* Make assertions about a 403 error returned by the API.
*/
public function assertAccessDeniedJson(TestResponse $response)
{
$response->assertStatus(Response::HTTP_FORBIDDEN);
$response->assertJsonStructure(['errors' => [['code', 'status', 'detail']]]);
$response->assertJsonCount(1, 'errors');
$response->assertJson([
'errors' => [
[
'code' => 'AccessDeniedHttpException',
'status' => '403',
'detail' => 'This action is unauthorized.',
],
],
], true);
}
}