feat(server): add dedicated server creation flow

This commit is contained in:
Andras Bacsai
2026-07-08 12:20:56 +02:00
parent 18f0f7f6be
commit 7236cb8228
31 changed files with 1158 additions and 352 deletions
@@ -1,7 +1,10 @@
<?php
use App\Http\Middleware\PreventRequestsDuringMaintenance;
use App\Livewire\Server\Create as ServerCreate;
use App\Livewire\Server\Index as ServerIndex;
use App\Livewire\Server\Navbar as ServerNavbar;
use App\Models\CloudProviderToken;
use App\Models\InstanceSettings;
use App\Models\Server;
use App\Models\Team;
@@ -132,6 +135,144 @@ test('member cannot create server', function () {
expect(auth()->user()->can('create', Server::class))->toBeFalse();
});
test('admin can access new server page', function () {
$this->actingAs($this->admin);
session(['currentTeam' => $this->team]);
$this->get(route('server.create'))
->assertSuccessful()
->assertSee('New Server')
->assertSeeLivewire(ServerCreate::class);
});
test('new server chooser lists providers before rendering a creation form', function () {
$this->actingAs($this->admin);
session(['currentTeam' => $this->team]);
Livewire::test(ServerCreate::class)
->assertSee('Hetzner')
->assertSee('Vultr')
->assertSee('DigitalOcean')
->assertSee('Manual')
->assertDontSee('>Select<', false)
->assertDontSee('Continue')
->assertSee(route('server.create.type', ['type' => 'hetzner']))
->assertSee(route('server.create.type', ['type' => 'vultr']))
->assertSee(route('server.create.type', ['type' => 'digital-ocean']))
->assertSee(route('server.create.type', ['type' => 'manual']))
->assertDontSee('Add Server by IP Address');
});
test('new server chooser uses compact mobile provider cards', function () {
$this->actingAs($this->admin);
session(['currentTeam' => $this->team]);
Livewire::test(ServerCreate::class)
->assertSee('mx-auto flex w-full max-w-7xl flex-col', false)
->assertSee('sm:grid', false)
->assertSee('sm:grid-cols-2', false)
->assertSee('xl:grid-cols-4', false)
->assertSee('gap-3 sm:gap-6', false)
->assertSee('dark:hover:border-warning', false)
->assertSee('focus-visible:border-coollabs', false)
->assertSee('aria-label="Choose Hetzner"', false)
->assertSee('p-3 sm:p-6', false)
->assertDontSee('sm:min-h-80', false)
->assertSee('size-9 sm:size-14', false)
->assertDontSee('size-9 sm:size-14 w-14 h-14', false)
->assertSee('hidden sm:block', false)
->assertDontSee('>Select<', false)
->assertDontSee('<button', false);
});
test('new server provider pages render the selected creation flow', function (string $type, string $heading) {
$this->actingAs($this->admin);
session(['currentTeam' => $this->team]);
$response = $this->get(route('server.create.type', ['type' => $type]))
->assertSuccessful()
->assertSee($heading)
->assertDontSee('<h1>New Server</h1>', false)
->assertDontSee('Choose how to add your server');
$response->assertSeeInOrder([$heading, 'Back']);
})->with([
['hetzner', 'Hetzner'],
['vultr', 'Vultr'],
['digital-ocean', 'DigitalOcean'],
['manual', 'Manual'],
]);
test('new server provider pages do not show the new token action in the header', function (string $type, string $heading) {
$this->actingAs($this->admin);
session(['currentTeam' => $this->team]);
$response = $this->get(route('server.create.type', ['type' => $type]))
->assertSuccessful()
->assertDontSee('+ New Token')
->assertDontSee('+ Add New Token');
$response->assertSeeInOrder([$heading, 'Back']);
})->with([
['hetzner', 'Hetzner'],
['vultr', 'Vultr'],
['digital-ocean', 'DigitalOcean'],
]);
test('new server provider pages show the new token action in the header when tokens exist', function (string $type, string $provider, string $heading, string $modalTitle) {
$this->actingAs($this->admin);
session(['currentTeam' => $this->team]);
CloudProviderToken::factory()->create([
'team_id' => $this->team->id,
'provider' => $provider,
]);
$response = $this->get(route('server.create.type', ['type' => $type]))
->assertSuccessful()
->assertSee($modalTitle);
$response->assertSeeInOrder([$heading, 'Back', '+ New Token']);
})->with([
['hetzner', 'hetzner', 'Hetzner', 'Add Hetzner Token'],
['vultr', 'vultr', 'Vultr', 'Add Vultr Token'],
['digital-ocean', 'digitalocean', 'DigitalOcean', 'Add DigitalOcean Token'],
]);
test('new server manual page does not show the new token action', function () {
$this->actingAs($this->admin);
session(['currentTeam' => $this->team]);
$this->get(route('server.create.type', ['type' => 'manual']))
->assertSuccessful()
->assertSee('Manual')
->assertDontSee('+ New Token');
});
test('member cannot access new server page', function () {
$this->actingAs($this->member);
session(['currentTeam' => $this->team]);
$this->get(route('server.create'))
->assertForbidden();
});
test('server index links admins to new server page', function () {
$this->actingAs($this->admin);
session(['currentTeam' => $this->team]);
Livewire::test(ServerIndex::class)
->assertSee(route('server.create'));
});
test('server index does not link members to new server page', function () {
$this->actingAs($this->member);
session(['currentTeam' => $this->team]);
Livewire::test(ServerIndex::class)
->assertDontSee(route('server.create'));
});
// --- Cross-team isolation ---
test('user from different team cannot view server', function () {