57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\InventoryItemResource;
|
|
use App\Models\InventoryItem;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
|
|
describe('Inventory item resource authorization', function () {
|
|
it('is not visible for non-members', function () {
|
|
$user = User::factory()->create();
|
|
$tenant = Tenant::factory()->create();
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
|
|
expect(InventoryItemResource::canViewAny())->toBeFalse();
|
|
});
|
|
|
|
it('is visible for readonly members', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'readonly');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
|
|
expect(InventoryItemResource::canViewAny())->toBeTrue();
|
|
});
|
|
|
|
it('prevents viewing inventory items from other tenants', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$otherTenant = Tenant::factory()->create();
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
|
|
$record = InventoryItem::factory()->create([
|
|
'tenant_id' => $otherTenant->getKey(),
|
|
]);
|
|
|
|
expect(InventoryItemResource::canView($record))->toBeFalse();
|
|
});
|
|
|
|
it('allows viewing inventory items from the current tenant', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'readonly');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
|
|
$record = InventoryItem::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
]);
|
|
|
|
expect(InventoryItemResource::canView($record))->toBeTrue();
|
|
});
|
|
});
|