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
|
|
|
|
{
|
2022-10-14 16:59:20 +00:00
|
|
|
private NestRepositoryInterface $repository;
|
2018-03-25 22:41:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
2020-05-09 16:00:52 +00:00
|
|
|
public function setUp(): void
|
2018-03-25 22:41:36 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->repository = $this->app->make(NestRepositoryInterface::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-14 16:59:20 +00:00
|
|
|
* 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,
|
2022-12-15 02:53:07 +00:00
|
|
|
'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',
|
|
|
|
'attributes' => $this->getTransformer(NestTransformer::class)->transform($nest),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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',
|
|
|
|
'attributes' => $this->getTransformer(NestTransformer::class)->transform($nest),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
{
|
2022-11-25 20:29:04 +00:00
|
|
|
$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()
|
|
|
|
{
|
2022-12-15 02:53:07 +00:00
|
|
|
$this->markTestSkipped('todo: implement proper admin api key permissions system');
|
2018-03-25 22:41:36 +00:00
|
|
|
}
|
|
|
|
}
|