Refactor how repositories for the daemon work.

This commit is contained in:
Dane Everitt 2018-01-05 18:27:47 -06:00
parent 5f9fe4a69b
commit d2afc29a80
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
58 changed files with 388 additions and 997 deletions

View file

@ -12,6 +12,7 @@ namespace Tests\Unit\Services\DaemonKeys;
use Mockery as m;
use Tests\TestCase;
use Illuminate\Log\Writer;
use GuzzleHttp\Psr7\Response;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\DaemonKey;
use GuzzleHttp\Exception\RequestException;
@ -98,8 +99,8 @@ class DaemonKeyDeletionServiceTest extends TestCase
])->once()->andReturn($key);
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturn(1);
$this->daemonRepository->shouldReceive('setNode')->with($server->node_id)->once()->andReturnSelf()
->shouldReceive('revokeAccessKey')->with($key->secret)->once()->andReturnNull();
$this->daemonRepository->shouldReceive('setServer')->with($server)->once()->andReturnSelf()
->shouldReceive('revokeAccessKey')->with($key->secret)->once()->andReturn(new Response);
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
$this->service->handle($server, 100);
@ -122,8 +123,8 @@ class DaemonKeyDeletionServiceTest extends TestCase
])->once()->andReturn($key);
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturn(1);
$this->daemonRepository->shouldReceive('setNode')->with($server->node_id)->once()->andReturnSelf()
->shouldReceive('revokeAccessKey')->with($key->secret)->once()->andReturnNull();
$this->daemonRepository->shouldReceive('setServer')->with($server)->once()->andReturnSelf()
->shouldReceive('revokeAccessKey')->with($key->secret)->once()->andReturn(new Response);
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
$this->service->handle($server->id, 100);
@ -145,7 +146,7 @@ class DaemonKeyDeletionServiceTest extends TestCase
])->once()->andReturn($key);
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturn(1);
$this->daemonRepository->shouldReceive('setNode')->with($server->node_id)->once()->andThrow($this->exception);
$this->daemonRepository->shouldReceive('setServer')->with($server)->once()->andThrow($this->exception);
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnNull();
$this->connection->shouldReceive('rollBack')->withNoArgs()->once()->andReturnNull();
$this->writer->shouldReceive('warning')->with($this->exception)->once()->andReturnNull();