Initial commit device-management
tests / ci (push) Has been cancelled

This commit is contained in:
Wian Drs
2026-08-25 09:42:00 +07:00
commit 1e80be180e
1159 changed files with 149545 additions and 0 deletions
+84
View File
@@ -0,0 +1,84 @@
<?php
namespace Tests\Feature;
use App\Models\User;
use App\Services\TenantProvisioningService;
use Database\Seeders\RolePermissionSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\TestCase;
class DashboardTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->seed(RolePermissionSeeder::class);
}
public function test_guests_are_redirected_to_the_login_page()
{
$response = $this->get(route('dashboard'));
$response->assertRedirect(route('login'));
}
public function test_authenticated_users_can_visit_the_dashboard()
{
$user = User::factory()->create();
$this->actingAs($user);
$response = $this->get(route('dashboard'));
$response->assertOk();
}
public function test_master_admin_receives_platform_dashboard(): void
{
$admin = User::factory()->create(['is_platform_admin' => true]);
$this->actingAs($admin)->get(route('dashboard'))
->assertInertia(fn (Assert $page) => $page
->component('dashboard')
->where('role', 'MASTER ADMIN')
->where('tenant', null)
->has('stats.tenants')
->has('stats.activeLicenses'));
}
public function test_tenant_admin_receives_tenant_admin_dashboard(): void
{
[$tenant, $admin] = $this->tenantWithAdmin();
$this->actingAs($admin)->get(route('dashboard'))
->assertInertia(fn (Assert $page) => $page
->where('role', 'TENANT ADMIN')
->where('tenant.id', $tenant->id)
->where('stats.users', 1));
}
public function test_tenant_user_receives_tenant_user_dashboard(): void
{
[$tenant, $admin] = $this->tenantWithAdmin();
setPermissionsTeamId($tenant->id);
$user = User::factory()->for($tenant)->create();
$user->assignRole('TENANT USER');
$this->actingAs($user)->get(route('dashboard'))
->assertInertia(fn (Assert $page) => $page
->where('role', 'TENANT USER')
->where('tenant.id', $tenant->id)
->where('stats.canAddDevice', true));
}
private function tenantWithAdmin(): array
{
$tenant = app(TenantProvisioningService::class)->createWithOwner([
'name' => 'Tenant A', 'slug' => 'tenant-a', 'owner_name' => 'Admin Tenant',
'owner_email' => 'admin@tenant.test', 'owner_password' => 'Strong!Password123',
]);
return [$tenant, User::withoutGlobalScope('tenant')->where('tenant_id', $tenant->id)->firstOrFail()];
}
}