53 lines
1.8 KiB
PHP
53 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\ApplicationInstallation;
|
|
use App\Models\Business;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class InstallationTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_a_clean_database_creates_only_a_platform_super_admin(): void
|
|
{
|
|
$this->get('/install')->assertOk()->assertSee('Create the platform administrator');
|
|
|
|
$response = $this->post('/install', [
|
|
'adminName' => 'Platform Admin',
|
|
'adminEmail' => 'admin@example.test',
|
|
'password' => 'password123',
|
|
'password_confirmation' => 'password123',
|
|
]);
|
|
|
|
$response->assertRedirect(route('manager.dashboard'));
|
|
$this->assertDatabaseHas('ApplicationInstallation', [
|
|
'id' => 'singleton',
|
|
'status' => 'INSTALLED',
|
|
'primaryBusinessId' => null,
|
|
]);
|
|
$this->assertDatabaseHas('User', ['email' => 'admin@example.test', 'isSuperAdmin' => 1]);
|
|
$this->assertSame(0, Business::count());
|
|
$this->get('/install')->assertRedirect(route('manager.dashboard'));
|
|
$this->assertSame(1, ApplicationInstallation::count());
|
|
}
|
|
|
|
public function test_installation_cannot_be_repeated(): void
|
|
{
|
|
$admin = User::factory()->create(['isSuperAdmin' => true]);
|
|
ApplicationInstallation::create(['id' => 'singleton', 'status' => 'INSTALLED', 'installedAt' => now(), 'initialAdminUserId' => $admin->id]);
|
|
|
|
$this->post('/install', [
|
|
'adminName' => 'Another Admin',
|
|
'adminEmail' => 'another@example.test',
|
|
'password' => 'password123',
|
|
'password_confirmation' => 'password123',
|
|
])->assertRedirect(route('manager.login'));
|
|
|
|
$this->assertDatabaseMissing('User', ['email' => 'another@example.test']);
|
|
}
|
|
}
|