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
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace Tests\Feature;
use App\Models\Tenant;
use App\Models\User;
use App\Support\TenantContext;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class TenantIsolationTest extends TestCase
{
use RefreshDatabase;
public function test_user_queries_are_scoped_to_current_tenant(): void
{
$tenantA = Tenant::factory()->create();
$tenantB = Tenant::factory()->create();
User::factory()->for($tenantA)->create();
User::factory()->for($tenantB)->create();
app(TenantContext::class)->set($tenantA->id);
$this->assertCount(1, User::all());
$this->assertTrue(User::first()->tenant->is($tenantA));
}
public function test_tenant_id_is_assigned_from_context_on_create(): void
{
$tenant = Tenant::factory()->create();
app(TenantContext::class)->set($tenant->id);
$user = User::factory()->create(['tenant_id' => null]);
$this->assertSame($tenant->id, $user->tenant_id);
}
}