Path: blob/1.0-develop/tests/Integration/Api/Application/Nests/NestControllerTest.php
7461 views
<?php12namespace Pterodactyl\Tests\Integration\Api\Application\Nests;34use Illuminate\Http\Response;5use Pterodactyl\Contracts\Repository\NestRepositoryInterface;6use Pterodactyl\Transformers\Api\Application\NestTransformer;7use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase;89class NestControllerTest extends ApplicationApiIntegrationTestCase10{11private NestRepositoryInterface $repository;1213/**14* Setup tests.15*/16public function setUp(): void17{18parent::setUp();1920$this->repository = $this->app->make(NestRepositoryInterface::class);21}2223/**24* Test that the expected nests are returned by the request.25*/26public function testNestResponse()27{28/** @var \Pterodactyl\Models\Nest[] $nests */29$nests = $this->repository->all();3031$response = $this->getJson('/api/application/nests');32$response->assertStatus(Response::HTTP_OK);33$response->assertJsonCount(count($nests), 'data');34$response->assertJsonStructure([35'object',36'data' => [['object', 'attributes' => ['id', 'uuid', 'author', 'name', 'description', 'created_at', 'updated_at']]],37'meta' => ['pagination' => ['total', 'count', 'per_page', 'current_page', 'total_pages']],38]);3940$response->assertJson([41'object' => 'list',42'data' => [],43'meta' => [44'pagination' => [45'total' => 4,46'count' => 4,47'per_page' => 50,48'current_page' => 1,49'total_pages' => 1,50],51],52]);5354foreach ($nests as $nest) {55$response->assertJsonFragment([56'object' => 'nest',57'attributes' => $this->getTransformer(NestTransformer::class)->transform($nest),58]);59}60}6162/**63* Test that getting a single nest returns the expected result.64*/65public function testSingleNestResponse()66{67$nest = $this->repository->find(1);6869$response = $this->getJson('/api/application/nests/' . $nest->id);70$response->assertStatus(Response::HTTP_OK);71$response->assertJsonStructure([72'object',73'attributes' => ['id', 'uuid', 'author', 'name', 'description', 'created_at', 'updated_at'],74]);7576$response->assertJson([77'object' => 'nest',78'attributes' => $this->getTransformer(NestTransformer::class)->transform($nest),79]);80}8182/**83* Test that including eggs in the response works as expected.84*/85public function testSingleNestWithEggsIncluded()86{87$nest = $this->repository->find(1);88$nest->loadMissing('eggs');8990$response = $this->getJson('/api/application/nests/' . $nest->id . '?include=servers,eggs');91$response->assertStatus(Response::HTTP_OK);92$response->assertJsonStructure([93'object',94'attributes' => [95'relationships' => [96'eggs' => ['object', 'data' => []],97'servers' => ['object', 'data' => []],98],99],100]);101102$response->assertJsonCount(count($nest->getRelation('eggs')), 'attributes.relationships.eggs.data');103}104105/**106* Test that a missing nest returns a 404 error.107*/108public function testGetMissingNest()109{110$response = $this->getJson('/api/application/nests/nil');111$this->assertNotFoundJson($response);112}113114/**115* Test that an authentication error occurs if a key does not have permission116* to access a resource.117*/118public function testErrorReturnedIfNoPermission()119{120$nest = $this->repository->find(1);121$this->createNewDefaultApiKey($this->getApiUser(), ['r_nests' => 0]);122123$response = $this->getJson('/api/application/nests/' . $nest->id);124$this->assertAccessDeniedJson($response);125}126}127128129