forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackUpdateServiceTest.php
More file actions
99 lines (84 loc) · 3.12 KB
/
PackUpdateServiceTest.php
File metadata and controls
99 lines (84 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?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 Tests\Unit\Services\Packs;
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Models\Pack;
use Pterodactyl\Services\Packs\PackUpdateService;
use Pterodactyl\Contracts\Repository\PackRepositoryInterface;
use Pterodactyl\Exceptions\Service\HasActiveServersException;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class PackUpdateServiceTest extends TestCase
{
/**
* @var \Pterodactyl\Contracts\Repository\PackRepositoryInterface|\Mockery\Mock
*/
protected $repository;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface|\Mockery\Mock
*/
protected $serverRepository;
/**
* @var \Pterodactyl\Services\Packs\PackUpdateService
*/
protected $service;
/**
* Setup tests.
*/
public function setUp(): void
{
parent::setUp();
$this->repository = m::mock(PackRepositoryInterface::class);
$this->serverRepository = m::mock(ServerRepositoryInterface::class);
$this->service = new PackUpdateService($this->repository, $this->serverRepository);
}
/**
* Test that a pack is updated.
*/
public function testPackIsUpdated()
{
$model = factory(Pack::class)->make();
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
'locked' => false,
'visible' => false,
'selectable' => false,
'test-data' => 'value',
])->once()->andReturn(1);
$this->assertEquals(1, $this->service->handle($model, ['test-data' => 'value']));
}
/**
* Test that an exception is thrown if the pack option ID is changed while servers are using the pack.
*/
public function testExceptionIsThrownIfModifyingEggIdWhenServersAreAttached()
{
$model = factory(Pack::class)->make();
$this->serverRepository->shouldReceive('findCountWhere')->with([['pack_id', '=', $model->id]])->once()->andReturn(1);
try {
$this->service->handle($model, ['egg_id' => 0]);
} catch (HasActiveServersException $exception) {
$this->assertEquals(trans('exceptions.packs.update_has_servers'), $exception->getMessage());
}
}
/**
* Test that an ID for a pack can be passed in place of the model.
*/
public function testPackIdCanBePassedInPlaceOfModel()
{
$model = factory(Pack::class)->make();
$this->repository->shouldReceive('setColumns')->with(['id', 'egg_id'])->once()->andReturnSelf()
->shouldReceive('find')->with($model->id)->once()->andReturn($model);
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
'locked' => false,
'visible' => false,
'selectable' => false,
'test-data' => 'value',
])->once()->andReturn(1);
$this->assertEquals(1, $this->service->handle($model->id, ['test-data' => 'value']));
}
}