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']); } public function test_an_existing_installation_can_upgrade_its_recorded_initial_admin_once(): void { $legacyOwner = User::factory()->create(['isSuperAdmin' => false, 'passwordHash' => password_hash('password123', PASSWORD_BCRYPT)]); ApplicationInstallation::create([ 'id' => 'singleton', 'status' => 'INSTALLED', 'installedAt' => now(), 'initialAdminUserId' => $legacyOwner->id, ]); $this->post('/manager/sign-in', [ 'email' => $legacyOwner->email, 'password' => 'password123', ])->assertRedirect(route('manager.dashboard')); $this->assertDatabaseHas('User', ['id' => $legacyOwner->id, 'isSuperAdmin' => 1]); } }