misc_pterodactyl-panel/tests/Integration/Api/Application/Nests/NestControllerTest.php

124 lines
3.8 KiB
PHP
Raw Permalink Normal View History

2018-03-25 22:41:36 +00:00
<?php
namespace Pterodactyl\Tests\Integration\Api\Application\Nests;
use Illuminate\Http\Response;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\NestTransformer;
use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase;
class NestControllerTest extends ApplicationApiIntegrationTestCase
{
private NestRepositoryInterface $repository;
2018-03-25 22:41:36 +00:00
/**
* Setup tests.
*/
public function setUp(): void
2018-03-25 22:41:36 +00:00
{
parent::setUp();
$this->repository = $this->app->make(NestRepositoryInterface::class);
}
/**
* Test that the expected nests are returned by the request.
2018-03-25 22:41:36 +00:00
*/
public function testNestResponse()
{
/** @var \Pterodactyl\Models\Nest[] $nests */
$nests = $this->repository->all();
$response = $this->getJson('/api/application/nests');
$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(count($nests), 'data');
$response->assertJsonStructure([
'object',
'data' => [['object', 'attributes' => ['id', 'uuid', 'author', 'name', 'description', 'created_at', 'updated_at']]],
'meta' => ['pagination' => ['total', 'count', 'per_page', 'current_page', 'total_pages']],
]);
$response->assertJson([
'object' => 'list',
'data' => [],
'meta' => [
'pagination' => [
'total' => 4,
'count' => 4,
'per_page' => 10,
2018-03-25 22:41:36 +00:00
'current_page' => 1,
'total_pages' => 1,
],
],
]);
foreach ($nests as $nest) {
$response->assertJsonFragment([
'object' => 'nest',
2023-01-12 20:19:01 +00:00
'attributes' => (new NestTransformer())->transform($nest),
2018-03-25 22:41:36 +00:00
]);
}
}
/**
* Test that getting a single nest returns the expected result.
*/
public function testSingleNestResponse()
{
$nest = $this->repository->find(1);
$response = $this->getJson('/api/application/nests/' . $nest->id);
$response->assertStatus(Response::HTTP_OK);
$response->assertJsonStructure([
'object',
'attributes' => ['id', 'uuid', 'author', 'name', 'description', 'created_at', 'updated_at'],
]);
$response->assertJson([
'object' => 'nest',
2023-01-12 20:19:01 +00:00
'attributes' => (new NestTransformer())->transform($nest),
2018-03-25 22:41:36 +00:00
]);
}
/**
* Test that including eggs in the response works as expected.
*/
public function testSingleNestWithEggsIncluded()
{
$nest = $this->repository->find(1);
$nest->loadMissing('eggs');
$response = $this->getJson('/api/application/nests/' . $nest->id . '?include=servers,eggs');
$response->assertStatus(Response::HTTP_OK);
$response->assertJsonStructure([
'object',
'attributes' => [
'relationships' => [
'eggs' => ['object', 'data' => []],
'servers' => ['object', 'data' => []],
],
],
]);
$response->assertJsonCount(count($nest->getRelation('eggs')), 'attributes.relationships.eggs.data');
}
/**
* Test that a missing nest returns a 404 error.
*/
public function testGetMissingNest()
{
$response = $this->getJson('/api/application/nests/0');
2018-03-25 22:41:36 +00:00
$this->assertNotFoundJson($response);
}
/**
* Test that an authentication error occurs if a key does not have permission
* to access a resource.
*/
public function testErrorReturnedIfNoPermission()
{
$this->markTestSkipped('todo: implement proper admin api key permissions system');
2018-03-25 22:41:36 +00:00
}
}