Move the primary allocation when it is removed from a server

This commit is contained in:
dualfroz committed 2026-10-10 11:52:35 +02:00
1 parent 72779c7ea6
commit ddaef93768
6 files changed
+82 -4

No files matched your search

+40
View File
@@ -3,6 +3,7 @@
use App\Enums\RolePermissionModels;
use App\Filament\Admin\Resources\Servers\Pages\CreateServer;
use App\Filament\Admin\Resources\Servers\Pages\EditServer;
use App\Filament\Admin\Resources\Servers\RelationManagers\AllocationsRelationManager;
use App\Models\Allocation;
use App\Models\Egg;
use App\Models\Node;
@@ -88,6 +89,45 @@ it('can delete a server', function () {
$this->assertDatabaseMissing('servers', ['id' => $server->id]);
});
it('moves the primary allocation when it is removed from a server', function () {
$server = createServerModel();
$primary = $server->allocation;
$other = Allocation::factory()->forServer($server)->create();
livewire(AllocationsRelationManager::class, ['ownerRecord' => $server, 'pageClass' => EditServer::class])
->callAction(TestAction::make('dissociate')->table($primary));
expect($primary->refresh()->server_id)->toBeNull()
->and($server->refresh()->allocation_id)->toBe($other->id);
});
it('clears the primary allocation when the last allocation is removed from a server', function () {
$server = createServerModel();
$primary = $server->allocation;
livewire(AllocationsRelationManager::class, ['ownerRecord' => $server, 'pageClass' => EditServer::class])
->callAction(TestAction::make('dissociate')->table($primary));
$server->refresh();
expect($server->allocation_id)->toBeNull()
->and(json_encode($server->getAllocationMappings()))->toBe('{"":[]}');
});
it('moves the primary allocation when it is removed from a server in bulk', function () {
$server = createServerModel();
$primary = $server->allocation;
[$removed, $kept] = Allocation::factory()->count(2)->forServer($server)->create();
livewire(AllocationsRelationManager::class, ['ownerRecord' => $server, 'pageClass' => EditServer::class])
->selectTableRecords([$primary->id, $removed->id])
->callAction(TestAction::make('dissociate')->table()->bulk());
expect($primary->refresh()->server_id)->toBeNull()
->and($removed->refresh()->server_id)->toBeNull()
->and($server->refresh()->allocation_id)->toBe($kept->id);
});
it('non root admin without permission cannot create servers', function () {
$role = Role::factory()->create(['name' => 'Egg Viewer', 'guard_name' => 'web']);
// Egg permission is on purpose, we check the wrong permissions.