Merge branch 'develop' into feature/api-v1
# Conflicts: # app/Contracts/Repository/RepositoryInterface.php # app/Repositories/Eloquent/EloquentRepository.php # app/Services/Nodes/NodeUpdateService.php # tests/Unit/Services/Nodes/NodeUpdateServiceTest.php
This commit is contained in:
commit
800e2df6b2
187 changed files with 1878 additions and 3143 deletions
|
@ -62,14 +62,11 @@ class NodeDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testNodeIsDeletedIfNoServersAreAttached()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['node_id', '=', 1]])->once()->andReturn(0);
|
||||
$this->repository->shouldReceive('delete')->with(1)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('delete')->with(1)->once()->andReturn(1);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->service->handle(1),
|
||||
'Assert that deletion returns a positive boolean value.'
|
||||
);
|
||||
$this->assertEquals(1, $this->service->handle(1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +76,7 @@ class NodeDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testExceptionIsThrownIfServersAreAttachedToNode()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['node_id', '=', 1]])->once()->andReturn(1);
|
||||
$this->translator->shouldReceive('trans')->with('exceptions.node.servers_attached')->once()->andReturnNull();
|
||||
$this->repository->shouldNotReceive('delete');
|
||||
|
@ -94,13 +91,10 @@ class NodeDeletionServiceTest extends TestCase
|
|||
{
|
||||
$node = factory(Node::class)->make();
|
||||
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['node_id', '=', $node->id]])->once()->andReturn(0);
|
||||
$this->repository->shouldReceive('delete')->with($node->id)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('delete')->with($node->id)->once()->andReturn(1);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->service->handle($node),
|
||||
'Assert that deletion returns a positive boolean value.'
|
||||
);
|
||||
$this->assertEquals(1, $this->service->handle($node));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ use Tests\TestCase;
|
|||
use Illuminate\Log\Writer;
|
||||
use phpmock\phpunit\PHPMock;
|
||||
use Pterodactyl\Models\Node;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Services\Nodes\NodeUpdateService;
|
||||
|
@ -84,13 +85,14 @@ class NodeUpdateServiceTest extends TestCase
|
|||
$this->getFunctionMock('\\Pterodactyl\\Services\\Nodes', 'str_random')
|
||||
->expects($this->once())->willReturn('random_string');
|
||||
|
||||
$this->repository->->shouldReceive('update')->with($this->node->id, [
|
||||
'name' => 'NewName',
|
||||
'daemonSecret' => 'random_string',
|
||||
])->andReturn($this->node);
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->node->id, [
|
||||
'name' => 'NewName',
|
||||
'daemonSecret' => 'random_string',
|
||||
])->andReturn(true);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node->id)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturnNull();
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
||||
|
||||
$response = $this->service->handle($this->node, ['name' => 'NewName', 'reset_secret' => true]);
|
||||
$this->assertInstanceOf(Node::class, $response);
|
||||
|
@ -102,12 +104,13 @@ class NodeUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testNodeIsUpdatedAndDaemonSecretIsNotChanged()
|
||||
{
|
||||
$this->repository->shouldReceive('update')->with($this->node->id, [
|
||||
'name' => 'NewName',
|
||||
])->andReturn($this->node);
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->node->id, [
|
||||
'name' => 'NewName',
|
||||
])->andReturn(true);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node->id)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturnNull();
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
||||
|
||||
$response = $this->service->handle($this->node, ['name' => 'NewName']);
|
||||
$this->assertInstanceOf(Node::class, $response);
|
||||
|
@ -119,11 +122,12 @@ class NodeUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testExceptionCausedByDaemonIsHandled()
|
||||
{
|
||||
$this->repository->->shouldReceive('update')->with($this->node->id, [
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->node->id, [
|
||||
'name' => 'NewName',
|
||||
])->andReturn(true);
|
||||
])->andReturn(new Response);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node->id)->once()->andThrow($this->exception);
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node)->once()->andThrow($this->exception);
|
||||
$this->writer->shouldReceive('warning')->with($this->exception)->once()->andReturnNull();
|
||||
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('getStatusCode')->withNoArgs()->once()->andReturn(400);
|
||||
|
@ -145,13 +149,13 @@ class NodeUpdateServiceTest extends TestCase
|
|||
public function testFunctionCanAcceptANodeIdInPlaceOfModel()
|
||||
{
|
||||
$this->repository->shouldReceive('find')->with($this->node->id)->once()->andReturn($this->node);
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->node->id, [
|
||||
'name' => 'NewName',
|
||||
])->andReturn(true);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node->id)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturnNull();
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
||||
|
||||
$this->assertTrue($this->service->handle($this->node->id, ['name' => 'NewName']));
|
||||
}
|
||||
|
|
Reference in a new issue