mirror of
https://github.com/pterodactyl/panel.git
synced 2024-11-22 09:02:28 +01:00
Fix failing tests due to way nest creation worked
This commit is contained in:
parent
233cbfda09
commit
f5b20e38c4
@ -1,11 +1,4 @@
|
||||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Nests;
|
||||
|
||||
@ -19,12 +12,12 @@ class NestCreationService
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository
|
||||
*/
|
||||
protected $config;
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* NestCreationService constructor.
|
||||
@ -41,16 +34,16 @@ class NestCreationService
|
||||
/**
|
||||
* Create a new nest on the system.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
* @param string|null $author
|
||||
* @return \Pterodactyl\Models\Nest
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function handle(array $data): Nest
|
||||
public function handle(array $data, string $author = null): Nest
|
||||
{
|
||||
return $this->repository->create([
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
'author' => $this->config->get('pterodactyl.service.author'),
|
||||
'author' => $author ?? $this->config->get('pterodactyl.service.author'),
|
||||
'name' => array_get($data, 'name'),
|
||||
'description' => array_get($data, 'description'),
|
||||
], true, true);
|
||||
|
@ -11,8 +11,7 @@ return [
|
||||
| standard Pterodactyl shipped services.
|
||||
*/
|
||||
'service' => [
|
||||
'core' => 'ptrdctyl-v040-11e6-8b77-86f30ca893d3',
|
||||
'author' => env('SERVICE_AUTHOR'),
|
||||
'author' => env('SERVICE_AUTHOR', 'unknown@unknown.com'),
|
||||
],
|
||||
|
||||
/*
|
||||
|
@ -59,7 +59,7 @@ class NestSeeder extends Seeder
|
||||
$this->creationService->handle([
|
||||
'name' => 'Minecraft',
|
||||
'description' => 'Minecraft - the classic game from Mojang. With support for Vanilla MC, Spigot, and many others!',
|
||||
]);
|
||||
], 'support@pterodactyl.io');
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ class NestSeeder extends Seeder
|
||||
$this->creationService->handle([
|
||||
'name' => 'Source Engine',
|
||||
'description' => 'Includes support for most Source Dedicated Server games.',
|
||||
]);
|
||||
], 'support@pterodactyl.io');
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ class NestSeeder extends Seeder
|
||||
$this->creationService->handle([
|
||||
'name' => 'Voice Servers',
|
||||
'description' => 'Voice servers such as Mumble and Teamspeak 3.',
|
||||
]);
|
||||
], 'support@pterodactyl.io');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ namespace Tests\Unit\Services\Services;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Tests\Traits\MocksUuids;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
@ -25,17 +24,12 @@ class NestCreationServiceTest extends TestCase
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository|\Mockery\Mock
|
||||
*/
|
||||
protected $config;
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface|\Mockery\Mock
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Nests\NestCreationService
|
||||
*/
|
||||
protected $service;
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
@ -46,8 +40,6 @@ class NestCreationServiceTest extends TestCase
|
||||
|
||||
$this->config = m::mock(Repository::class);
|
||||
$this->repository = m::mock(NestRepositoryInterface::class);
|
||||
|
||||
$this->service = new NestCreationService($this->config, $this->repository);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,21 +48,48 @@ class NestCreationServiceTest extends TestCase
|
||||
public function testCreateNewService()
|
||||
{
|
||||
$model = factory(Nest::class)->make();
|
||||
$data = [
|
||||
'name' => $model->name,
|
||||
'description' => $model->description,
|
||||
];
|
||||
|
||||
$this->config->shouldReceive('get')->with('pterodactyl.service.author')->once()->andReturn('testauthor@example.com');
|
||||
$this->repository->shouldReceive('create')->with([
|
||||
'uuid' => $this->getKnownUuid(),
|
||||
'author' => 'testauthor@example.com',
|
||||
'name' => $data['name'],
|
||||
'description' => $data['description'],
|
||||
'name' => $model->name,
|
||||
'description' => $model->description,
|
||||
], true, true)->once()->andReturn($model);
|
||||
|
||||
$response = $this->service->handle($data);
|
||||
$response = $this->getService()->handle(['name' => $model->name, 'description' => $model->description]);
|
||||
$this->assertInstanceOf(Nest::class, $response);
|
||||
$this->assertEquals($model, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creation of a new nest with a defined author. This is used by seeder
|
||||
* scripts which need to set a specific author for nests in order for other
|
||||
* functionality to work correctly.
|
||||
*/
|
||||
public function testCreateServiceWithDefinedAuthor()
|
||||
{
|
||||
$model = factory(Nest::class)->make();
|
||||
|
||||
$this->repository->shouldReceive('create')->with([
|
||||
'uuid' => $this->getKnownUuid(),
|
||||
'author' => 'support@pterodactyl.io',
|
||||
'name' => $model->name,
|
||||
'description' => $model->description,
|
||||
], true, true)->once()->andReturn($model);
|
||||
|
||||
$response = $this->getService()->handle(['name' => $model->name, 'description' => $model->description], 'support@pterodactyl.io');
|
||||
$this->assertInstanceOf(Nest::class, $response);
|
||||
$this->assertEquals($model, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of the service with mocked dependencies.
|
||||
*
|
||||
* @return \Pterodactyl\Services\Nests\NestCreationService
|
||||
*/
|
||||
private function getService(): NestCreationService
|
||||
{
|
||||
return new NestCreationService($this->config, $this->repository);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user