Fix failing tests due to way nest creation worked
This commit is contained in:
parent
233cbfda09
commit
f5b20e38c4
4 changed files with 46 additions and 35 deletions
|
@ -1,11 +1,4 @@
|
||||||
<?php
|
<?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;
|
namespace Pterodactyl\Services\Nests;
|
||||||
|
|
||||||
|
@ -19,12 +12,12 @@ class NestCreationService
|
||||||
/**
|
/**
|
||||||
* @var \Illuminate\Contracts\Config\Repository
|
* @var \Illuminate\Contracts\Config\Repository
|
||||||
*/
|
*/
|
||||||
protected $config;
|
private $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
|
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
|
||||||
*/
|
*/
|
||||||
protected $repository;
|
private $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NestCreationService constructor.
|
* NestCreationService constructor.
|
||||||
|
@ -41,16 +34,16 @@ class NestCreationService
|
||||||
/**
|
/**
|
||||||
* Create a new nest on the system.
|
* Create a new nest on the system.
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
* @param string|null $author
|
||||||
* @return \Pterodactyl\Models\Nest
|
* @return \Pterodactyl\Models\Nest
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||||
*/
|
*/
|
||||||
public function handle(array $data): Nest
|
public function handle(array $data, string $author = null): Nest
|
||||||
{
|
{
|
||||||
return $this->repository->create([
|
return $this->repository->create([
|
||||||
'uuid' => Uuid::uuid4()->toString(),
|
'uuid' => Uuid::uuid4()->toString(),
|
||||||
'author' => $this->config->get('pterodactyl.service.author'),
|
'author' => $author ?? $this->config->get('pterodactyl.service.author'),
|
||||||
'name' => array_get($data, 'name'),
|
'name' => array_get($data, 'name'),
|
||||||
'description' => array_get($data, 'description'),
|
'description' => array_get($data, 'description'),
|
||||||
], true, true);
|
], true, true);
|
||||||
|
|
|
@ -11,8 +11,7 @@ return [
|
||||||
| standard Pterodactyl shipped services.
|
| standard Pterodactyl shipped services.
|
||||||
*/
|
*/
|
||||||
'service' => [
|
'service' => [
|
||||||
'core' => 'ptrdctyl-v040-11e6-8b77-86f30ca893d3',
|
'author' => env('SERVICE_AUTHOR', 'unknown@unknown.com'),
|
||||||
'author' => env('SERVICE_AUTHOR'),
|
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -59,7 +59,7 @@ class NestSeeder extends Seeder
|
||||||
$this->creationService->handle([
|
$this->creationService->handle([
|
||||||
'name' => 'Minecraft',
|
'name' => 'Minecraft',
|
||||||
'description' => 'Minecraft - the classic game from Mojang. With support for Vanilla MC, Spigot, and many others!',
|
'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([
|
$this->creationService->handle([
|
||||||
'name' => 'Source Engine',
|
'name' => 'Source Engine',
|
||||||
'description' => 'Includes support for most Source Dedicated Server games.',
|
'description' => 'Includes support for most Source Dedicated Server games.',
|
||||||
]);
|
], 'support@pterodactyl.io');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ class NestSeeder extends Seeder
|
||||||
$this->creationService->handle([
|
$this->creationService->handle([
|
||||||
'name' => 'Voice Servers',
|
'name' => 'Voice Servers',
|
||||||
'description' => 'Voice servers such as Mumble and Teamspeak 3.',
|
'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 Mockery as m;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Ramsey\Uuid\Uuid;
|
|
||||||
use Pterodactyl\Models\Nest;
|
use Pterodactyl\Models\Nest;
|
||||||
use Tests\Traits\MocksUuids;
|
use Tests\Traits\MocksUuids;
|
||||||
use Illuminate\Contracts\Config\Repository;
|
use Illuminate\Contracts\Config\Repository;
|
||||||
|
@ -25,17 +24,12 @@ class NestCreationServiceTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @var \Illuminate\Contracts\Config\Repository|\Mockery\Mock
|
* @var \Illuminate\Contracts\Config\Repository|\Mockery\Mock
|
||||||
*/
|
*/
|
||||||
protected $config;
|
private $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface|\Mockery\Mock
|
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface|\Mockery\Mock
|
||||||
*/
|
*/
|
||||||
protected $repository;
|
private $repository;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Services\Nests\NestCreationService
|
|
||||||
*/
|
|
||||||
protected $service;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup tests.
|
* Setup tests.
|
||||||
|
@ -46,8 +40,6 @@ class NestCreationServiceTest extends TestCase
|
||||||
|
|
||||||
$this->config = m::mock(Repository::class);
|
$this->config = m::mock(Repository::class);
|
||||||
$this->repository = m::mock(NestRepositoryInterface::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()
|
public function testCreateNewService()
|
||||||
{
|
{
|
||||||
$model = factory(Nest::class)->make();
|
$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->config->shouldReceive('get')->with('pterodactyl.service.author')->once()->andReturn('testauthor@example.com');
|
||||||
$this->repository->shouldReceive('create')->with([
|
$this->repository->shouldReceive('create')->with([
|
||||||
'uuid' => $this->getKnownUuid(),
|
'uuid' => $this->getKnownUuid(),
|
||||||
'author' => 'testauthor@example.com',
|
'author' => 'testauthor@example.com',
|
||||||
'name' => $data['name'],
|
'name' => $model->name,
|
||||||
'description' => $data['description'],
|
'description' => $model->description,
|
||||||
], true, true)->once()->andReturn($model);
|
], 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->assertInstanceOf(Nest::class, $response);
|
||||||
$this->assertEquals($model, $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 a new issue