Skip to content

Commit 895adb6

Browse files
authored
Ensure that a node description can be set, add additional test coverage (#5457)
1 parent 0917e60 commit 895adb6

File tree

5 files changed

+60
-10
lines changed

5 files changed

+60
-10
lines changed

app/Http/Requests/Api/Application/Nodes/StoreNodeRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function rules(?array $rules = null): array
2020
return collect($rules ?? Node::getRules())->only([
2121
'public',
2222
'name',
23+
'description',
2324
'location_id',
2425
'fqdn',
2526
'scheme',

app/Models/Node.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Node extends Model
8484
*/
8585
protected $fillable = [
8686
'public', 'name', 'location_id',
87-
'fqdn', 'scheme', 'behind_proxy',
87+
'description', 'fqdn', 'scheme', 'behind_proxy',
8888
'memory', 'memory_overallocate', 'disk',
8989
'disk_overallocate', 'upload_size', 'daemonBase',
9090
'daemonSFTP', 'daemonListen',

database/Factories/LocationFactory.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33
namespace Database\Factories;
44

55
use Illuminate\Support\Str;
6-
use Pterodactyl\Models\Location;
76
use Illuminate\Database\Eloquent\Factories\Factory;
87

8+
/**
9+
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\Pterodactyl\Models\Location>
10+
*/
911
class LocationFactory extends Factory
1012
{
11-
/**
12-
* The name of the factory's corresponding model.
13-
*
14-
* @var string
15-
*/
16-
protected $model = Location::class;
17-
1813
/**
1914
* Define the model's default state.
2015
*/

routes/api-application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
Route::get('/{node:id}/configuration', Application\Nodes\NodeConfigurationController::class);
3939

4040
Route::post('/', [Application\Nodes\NodeController::class, 'store']);
41-
Route::patch('/{node:id}', [Application\Nodes\NodeController::class, 'update']);
41+
Route::patch('/{node:id}', [Application\Nodes\NodeController::class, 'update'])->name('api.application.nodes.update');
4242

4343
Route::delete('/{node:id}', [Application\Nodes\NodeController::class, 'delete']);
4444

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

0 commit comments

Comments
 (0)