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
|
@ -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