2018-03-25 22:41:36 +00:00
|
|
|
<?php
|
|
|
|
|
2022-12-15 02:13:00 +00:00
|
|
|
namespace Pterodactyl\Tests\Integration\Api\Application\Eggs;
|
2018-03-25 22:41:36 +00:00
|
|
|
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
use Illuminate\Http\Response;
|
2022-12-15 02:13:00 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
2018-03-25 22:41:36 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Application\EggTransformer;
|
|
|
|
use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase;
|
|
|
|
|
|
|
|
class EggControllerTest extends ApplicationApiIntegrationTestCase
|
|
|
|
{
|
2022-12-15 02:13:00 +00:00
|
|
|
private EggRepositoryInterface $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->repository = $this->app->make(EggRepositoryInterface::class);
|
|
|
|
}
|
|
|
|
|
2018-03-25 22:41:36 +00:00
|
|
|
/**
|
2021-11-15 18:29:22 +00:00
|
|
|
* Test that all the eggs belonging to a given nest can be returned.
|
2018-03-25 22:41:36 +00:00
|
|
|
*/
|
|
|
|
public function testListAllEggsInNest()
|
|
|
|
{
|
2022-12-15 02:13:00 +00:00
|
|
|
$eggs = $this->repository->findWhere([['nest_id', '=', 1]]);
|
2018-03-25 22:41:36 +00:00
|
|
|
|
|
|
|
$response = $this->getJson('/api/application/nests/' . $eggs->first()->nest_id . '/eggs');
|
|
|
|
$response->assertStatus(Response::HTTP_OK);
|
|
|
|
$response->assertJsonCount(count($eggs), 'data');
|
|
|
|
$response->assertJsonStructure([
|
|
|
|
'object',
|
|
|
|
'data' => [
|
|
|
|
[
|
|
|
|
'object',
|
|
|
|
'attributes' => [
|
|
|
|
'id', 'uuid', 'nest', 'author', 'description', 'docker_image', 'startup', 'created_at', 'updated_at',
|
|
|
|
'script' => ['privileged', 'install', 'entry', 'container', 'extends'],
|
|
|
|
'config' => [
|
|
|
|
'files' => [],
|
2021-07-17 17:02:00 +00:00
|
|
|
'startup' => ['done'],
|
2018-03-25 22:41:36 +00:00
|
|
|
'stop',
|
|
|
|
'extends',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
foreach (array_get($response->json(), 'data') as $datum) {
|
|
|
|
$egg = $eggs->where('id', '=', $datum['attributes']['id'])->first();
|
|
|
|
|
|
|
|
$expected = json_encode(Arr::sortRecursive($datum['attributes']));
|
2022-12-15 02:13:00 +00:00
|
|
|
$actual = json_encode(Arr::sortRecursive((new EggTransformer())->transform($egg)));
|
2018-03-25 22:41:36 +00:00
|
|
|
|
2022-12-15 02:13:00 +00:00
|
|
|
$this->assertJsonStringEqualsJsonString(
|
2021-01-23 20:33:34 +00:00
|
|
|
$expected,
|
|
|
|
$actual,
|
2022-12-15 02:13:00 +00:00
|
|
|
'Unable to find JSON fragment: ' . PHP_EOL . PHP_EOL . "[{$expected}]" . PHP_EOL . PHP_EOL . 'within' . PHP_EOL . PHP_EOL . "[{$actual}]."
|
2018-03-25 22:41:36 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a single egg can be returned.
|
|
|
|
*/
|
|
|
|
public function testReturnSingleEgg()
|
|
|
|
{
|
2022-12-15 02:13:00 +00:00
|
|
|
$egg = $this->repository->find(1);
|
2018-03-25 22:41:36 +00:00
|
|
|
|
2022-12-15 02:13:00 +00:00
|
|
|
$response = $this->getJson('/api/application/eggs/' . $egg->id);
|
2018-03-25 22:41:36 +00:00
|
|
|
$response->assertStatus(Response::HTTP_OK);
|
|
|
|
$response->assertJsonStructure([
|
|
|
|
'object',
|
|
|
|
'attributes' => [
|
|
|
|
'id', 'uuid', 'nest', 'author', 'description', 'docker_image', 'startup', 'script' => [], 'config' => [], 'created_at', 'updated_at',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response->assertJson([
|
|
|
|
'object' => 'egg',
|
2022-12-15 02:13:00 +00:00
|
|
|
'attributes' => json_decode(json_encode((new EggTransformer())->transform($egg)), true),
|
2018-03-25 22:41:36 +00:00
|
|
|
], true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-14 16:59:20 +00:00
|
|
|
* Test that a single egg and all the defined relationships can be returned.
|
2018-03-25 22:41:36 +00:00
|
|
|
*/
|
|
|
|
public function testReturnSingleEggWithRelationships()
|
|
|
|
{
|
2022-12-15 02:13:00 +00:00
|
|
|
$egg = $this->repository->find(1);
|
2018-03-25 22:41:36 +00:00
|
|
|
|
2022-12-15 02:13:00 +00:00
|
|
|
$response = $this->getJson('/api/application/eggs/' . $egg->id . '?include=servers,variables,nest');
|
2018-03-25 22:41:36 +00:00
|
|
|
$response->assertStatus(Response::HTTP_OK);
|
|
|
|
$response->assertJsonStructure([
|
|
|
|
'object',
|
|
|
|
'attributes' => [
|
|
|
|
'relationships' => [
|
|
|
|
'nest' => ['object', 'attributes'],
|
|
|
|
'servers' => ['object', 'data' => []],
|
|
|
|
'variables' => ['object', 'data' => []],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a missing egg returns a 404 error.
|
|
|
|
*/
|
|
|
|
public function testGetMissingEgg()
|
|
|
|
{
|
2022-12-15 02:13:00 +00:00
|
|
|
$response = $this->getJson('/api/application/eggs/nil');
|
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:13:00 +00:00
|
|
|
$this->markTestSkipped('todo: implement proper admin api key permissions system');
|
|
|
|
}
|
2018-03-25 22:41:36 +00:00
|
|
|
}
|