Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/tests/Integration/Api/Application/Nodes/NodeController/UpdateNodeTest.php
10263 views
1
<?php
2
3
namespace Pterodactyl\Tests\Integration\Api\Application\Nodes\NodeController;
4
5
use Mockery\MockInterface;
6
use Pterodactyl\Models\Node;
7
use GuzzleHttp\Psr7\Response;
8
use Pterodactyl\Models\Location;
9
use Pterodactyl\Repositories\Wings\DaemonConfigurationRepository;
10
use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase;
11
12
class UpdateNodeTest extends ApplicationApiIntegrationTestCase
13
{
14
public function testCanUpdateNodeProperties(): void
15
{
16
$node = Node::factory()->for(Location::factory())->create();
17
$location = Location::factory()->create();
18
19
$this->mock(DaemonConfigurationRepository::class, function (MockInterface $mock) use ($node) {
20
$mock->expects('setNode')->with(\Mockery::on(fn ($value) => $value->is($node)))->andReturnSelf();
21
$mock->expects('update')->withAnyArgs()->andReturn(
22
new Response()
23
);
24
});
25
26
$this->patchJson(route('api.application.nodes.update', ['node' => $node]), [
27
'name' => 'New Name',
28
'description' => 'New Description',
29
'location_id' => $location->id,
30
'fqdn' => 'new.example.com',
31
'scheme' => 'https',
32
'memory' => 100,
33
'memory_overallocate' => 10,
34
'disk' => 200,
35
'disk_overallocate' => 20,
36
'daemon_sftp' => 1101,
37
'daemon_listen' => 1102,
38
])
39
->assertOk()
40
->assertJsonPath('object', 'node')
41
->assertJsonPath('attributes.name', 'New Name')
42
->assertJsonPath('attributes.description', 'New Description')
43
->assertJsonPath('attributes.fqdn', 'new.example.com')
44
->assertJsonPath('attributes.scheme', 'https')
45
->assertJsonPath('attributes.memory', 100)
46
->assertJsonPath('attributes.memory_overallocate', 10)
47
->assertJsonPath('attributes.disk', 200)
48
->assertJsonPath('attributes.disk_overallocate', 20)
49
->assertJsonPath('attributes.daemon_sftp', 1101)
50
->assertJsonPath('attributes.daemon_listen', 1102);
51
52
$this->assertEquals($location->id, $node->refresh()->location_id);
53
}
54
}
55
56