TenantAtlas/apps/platform/tests/Feature/Filament/InventoryItemDependencyEdgesTableTest.php
ahmido e64bae9cfc feat: cut over tenant core to managed environments (#335)
## Summary
- replace the legacy Tenant and TenantMembership core models with ManagedEnvironment and ManagedEnvironmentMembership
- propagate the managed environment naming and key changes across Filament resources, pages, controllers, jobs, models, and supporting runtime paths
- add feature 279 spec artifacts and focused managed-environment test coverage for model behavior, route binding, panel context, authorization, and legacy guardrails

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/ManagedEnvironment/LegacyTenantCoreGuardTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentAuthorizationTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentPanelContextTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentRouteBindingTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentContextResolverTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentModelTest.php`
- `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`

## Notes
- branch pushed from commit `1123b122`
- browser smoke test file was added but not run in this pass

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #335
2026-05-07 06:38:14 +00:00

132 lines
4.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Livewire\InventoryItemDependencyEdgesTable;
use App\Models\InventoryItem;
use App\Models\InventoryLink;
use App\Models\ManagedEnvironment;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Livewire\Livewire;
uses(RefreshDatabase::class);
function dependencyEdgesTableComponent(User $user, ManagedEnvironment $tenant, InventoryItem $item)
{
$tenant->makeCurrent();
Filament::setTenant($tenant, true);
test()->actingAs($user);
return Livewire::actingAs($user)->test(InventoryItemDependencyEdgesTable::class, [
'inventoryItemId' => (int) $item->getKey(),
]);
}
it('renders dependency rows through native table filters and preserves missing-target hints', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$item = InventoryItem::factory()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'external_id' => (string) Str::uuid(),
]);
$assigned = InventoryLink::factory()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'source_type' => 'inventory_item',
'source_id' => $item->external_id,
'target_type' => 'missing',
'target_id' => null,
'relationship_type' => 'assigned_to',
'metadata' => [
'last_known_name' => 'Assigned Target',
'raw_ref' => ['example' => 'assigned'],
],
]);
$scoped = InventoryLink::factory()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'source_type' => 'inventory_item',
'source_id' => $item->external_id,
'target_type' => 'missing',
'target_id' => null,
'relationship_type' => 'scoped_by',
'metadata' => [
'last_known_name' => 'Scoped Target',
'raw_ref' => ['example' => 'scoped'],
],
]);
$inbound = InventoryLink::factory()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'source_type' => 'inventory_item',
'source_id' => (string) Str::uuid(),
'target_type' => 'inventory_item',
'target_id' => $item->external_id,
'relationship_type' => 'depends_on',
]);
$component = dependencyEdgesTableComponent($user, $tenant, $item)
->assertTableFilterExists('direction')
->assertTableFilterExists('relationship_type')
->assertCanSeeTableRecords([
(string) $assigned->getKey(),
(string) $scoped->getKey(),
(string) $inbound->getKey(),
])
->assertSee('Assigned Target')
->assertSee('Scoped Target')
->assertSee('Missing');
$component
->filterTable('direction', 'outbound')
->assertCanSeeTableRecords([
(string) $assigned->getKey(),
(string) $scoped->getKey(),
])
->assertCanNotSeeTableRecords([(string) $inbound->getKey()])
->removeTableFilters()
->filterTable('direction', 'inbound')
->assertCanSeeTableRecords([(string) $inbound->getKey()])
->assertCanNotSeeTableRecords([
(string) $assigned->getKey(),
(string) $scoped->getKey(),
])
->removeTableFilters()
->filterTable('relationship_type', 'scoped_by')
->assertCanSeeTableRecords([(string) $scoped->getKey()])
->assertCanNotSeeTableRecords([
(string) $assigned->getKey(),
(string) $inbound->getKey(),
])
->removeTableFilters()
->filterTable('direction', 'outbound')
->filterTable('relationship_type', 'depends_on')
->assertCountTableRecords(0)
->assertSee('No dependencies found');
});
it('returns deny-as-not-found when mounted for an item outside the current tenant scope', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$foreignItem = InventoryItem::factory()->create([
'managed_environment_id' => (int) ManagedEnvironment::factory()->create()->getKey(),
'external_id' => (string) Str::uuid(),
]);
$tenant->makeCurrent();
Filament::setTenant($tenant, true);
$this->actingAs($user);
$component = Livewire::actingAs($user)->test(InventoryItemDependencyEdgesTable::class, [
'inventoryItemId' => (int) $foreignItem->getKey(),
]);
$component->assertSee('Not Found');
expect($component->instance())->toBeNull();
});