TenantAtlas/tests/Unit/InventoryLinkTest.php
ahmido 361e301f67 feat/042-inventory-dependencies-graph (#49)
Ordering + limit-only Test für created_at DESC in DependencyExtractionFeatureTest.php
UI Test für masked Identifier (ID: 123456…) + Guest-Access blocked in InventoryItemDependenciesTest.php
Quickstart ergänzt um manuellen <2s Check in quickstart.md
pr-gate Checkbox-Format normalisiert (kein leading space) in pr-gate.md

Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local>
Reviewed-on: #49
2026-01-10 00:20:14 +00:00

53 lines
1.5 KiB
PHP

<?php
use App\Models\InventoryLink;
use App\Models\Tenant;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
uses(RefreshDatabase::class);
it('enforces unique constraint on inventory_links', function () {
$tenant = Tenant::factory()->create();
$data = [
'tenant_id' => $tenant->getKey(),
'source_type' => 'inventory_item',
'source_id' => (string) Str::uuid(),
'target_type' => 'foundation_object',
'target_id' => (string) Str::uuid(),
'relationship_type' => 'assigned_to',
'metadata' => ['last_known_name' => 'X'],
];
InventoryLink::query()->create($data);
expect(function () use ($data) {
InventoryLink::query()->create($data);
})->toThrow(QueryException::class);
});
it('scopes edges by tenant at query level', function () {
$tenantA = Tenant::factory()->create();
$tenantB = Tenant::factory()->create();
$sourceId = (string) Str::uuid();
InventoryLink::factory()->create([
'tenant_id' => $tenantA->getKey(),
'source_id' => $sourceId,
]);
InventoryLink::factory()->create([
'tenant_id' => $tenantB->getKey(),
'source_id' => $sourceId,
]);
$edgesA = InventoryLink::query()->where('tenant_id', $tenantA->getKey())->get();
$edgesB = InventoryLink::query()->where('tenant_id', $tenantB->getKey())->get();
expect($edgesA->count())->toBe(1);
expect($edgesB->count())->toBe(1);
});