29 files changed
+876
-89
No files matched your search
@@ -3,6 +3,8 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\ApplicationInstallation;
|
||||
use App\Models\Business;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -10,25 +12,41 @@ class InstallationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_a_clean_database_can_be_installed_once(): void
|
||||
public function test_a_clean_database_creates_only_a_platform_super_admin(): void
|
||||
{
|
||||
$this->get('/install')->assertOk()->assertSee('Create your business');
|
||||
$this->get('/install')->assertOk()->assertSee('Create the platform administrator');
|
||||
|
||||
$response = $this->post('/install', [
|
||||
'businessName' => 'Installed Shop',
|
||||
'slug' => 'installed-shop',
|
||||
'domain' => 'localhost',
|
||||
'adminName' => 'First Owner',
|
||||
'adminEmail' => 'first-owner@example.test',
|
||||
'adminName' => 'Platform Admin',
|
||||
'adminEmail' => 'admin@example.test',
|
||||
'password' => 'password123',
|
||||
'password_confirmation' => 'password123',
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('install'));
|
||||
$this->assertDatabaseHas('ApplicationInstallation', ['id' => 'singleton', 'status' => 'INSTALLED']);
|
||||
$this->assertDatabaseHas('Business', ['slug' => 'installed-shop']);
|
||||
$this->assertDatabaseHas('User', ['email' => 'first-owner@example.test']);
|
||||
$this->get('/install')->assertRedirect(route('public.home'));
|
||||
$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']);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user