TenantAtlas/apps/platform/tests/Feature/ProviderConnections/ProviderConnectionNeutralitySpec238Test.php
ahmido 110245a9ec
Some checks are pending
Main Confidence / confidence (push) Waiting to run
feat: neutralize provider connection target-scope surfaces (#274)
## Summary
- add a shared provider target-scope descriptor, normalizer, identity-context metadata, and surface-summary layer
- update provider connection list, detail, create, edit, and onboarding surfaces to use neutral target-scope vocabulary while keeping Microsoft identity contextual
- align provider connection audit and resolver output with the neutral target-scope contract and add focused guard/unit/feature coverage for regressions

## Validation
- browser smoke: opened the tenant-scoped provider connection list, drilled into detail, and verified the edit/create surfaces in local admin context

## Notes
- this PR comes from the session branch created for the active feature work
- no additional runtime or persistence layer was introduced in this slice

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #274
2026-04-25 09:07:40 +00:00

115 lines
4.9 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Resources\ProviderConnectionResource;
use App\Filament\Resources\ProviderConnectionResource\Pages\CreateProviderConnection;
use App\Filament\Resources\ProviderConnectionResource\Pages\ListProviderConnections;
use App\Models\ProviderConnection;
use App\Services\Providers\ProviderConnectionResolver;
use Filament\Facades\Filament;
use Livewire\Livewire;
it('renders create and edit flows with neutral target-scope labels', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner', ensureDefaultMicrosoftProviderConnection: false);
$connection = ProviderConnection::factory()->create([
'workspace_id' => (int) $tenant->workspace_id,
'tenant_id' => (int) $tenant->getKey(),
'display_name' => 'Neutral connection',
'entra_tenant_id' => '44444444-4444-4444-4444-444444444444',
]);
$this->actingAs($user)
->get(ProviderConnectionResource::getUrl('create', ['tenant_id' => $tenant->external_id], panel: 'admin'))
->assertOk()
->assertSee('Target scope ID')
->assertSee('Target scope')
->assertDontSee('Entra tenant ID');
$this->actingAs($user)
->get(ProviderConnectionResource::getUrl('edit', ['record' => $connection, 'tenant_id' => $tenant->external_id], panel: 'admin'))
->assertOk()
->assertSee('Target scope ID')
->assertSee('Target scope')
->assertDontSee('Entra tenant ID');
});
it('keeps list and detail surfaces default-visible around provider target scope consent and verification', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner', ensureDefaultMicrosoftProviderConnection: false);
$connection = ProviderConnection::factory()->create([
'workspace_id' => (int) $tenant->workspace_id,
'tenant_id' => (int) $tenant->getKey(),
'display_name' => 'Scope-visible connection',
'entra_tenant_id' => '55555555-5555-5555-5555-555555555555',
'consent_status' => 'granted',
'verification_status' => 'healthy',
]);
$tenant->makeCurrent();
Filament::setTenant($tenant, true);
$component = Livewire::actingAs($user)->test(ListProviderConnections::class);
$table = $component->instance()->getTable();
$visibleColumnNames = collect($table->getVisibleColumns())
->map(fn ($column): string => $column->getName())
->values()
->all();
expect($visibleColumnNames)->toContain('provider', 'target_scope', 'consent_status', 'verification_status')
->and($visibleColumnNames)->not->toContain('entra_tenant_id')
->and($table->getColumn('target_scope')?->getLabel())->toBe('Target scope')
->and($table->getColumn('entra_tenant_id')?->getLabel())->toBe('Microsoft tenant ID');
$this->actingAs($user)
->get(ProviderConnectionResource::getUrl('view', ['record' => $connection, 'tenant_id' => $tenant->external_id], panel: 'admin'))
->assertOk()
->assertSee('Target scope')
->assertSee('Provider identity details')
->assertSee('Microsoft tenant ID')
->assertSee('Consent')
->assertSee('Verification')
->assertDontSee('Entra tenant ID');
});
it('uses neutral validation attributes when the create flow misses target-scope context', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner', ensureDefaultMicrosoftProviderConnection: false);
$this->actingAs($user);
$tenant->makeCurrent();
Filament::setTenant($tenant, true);
Livewire::actingAs($user)
->test(CreateProviderConnection::class)
->fillForm([
'display_name' => 'Missing target scope',
'entra_tenant_id' => '',
'is_default' => true,
])
->call('create')
->assertHasFormErrors(['entra_tenant_id' => 'required']);
});
it('blocks unsupported provider target-scope combinations before provider execution', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner', ensureDefaultMicrosoftProviderConnection: false);
$connection = ProviderConnection::factory()->consentGranted()->create([
'workspace_id' => (int) $tenant->workspace_id,
'tenant_id' => (int) $tenant->getKey(),
'provider' => 'contoso',
'display_name' => 'Unsupported provider connection',
'entra_tenant_id' => '66666666-6666-6666-6666-666666666666',
'is_enabled' => true,
]);
$resolution = app(ProviderConnectionResolver::class)
->validateConnection($tenant, 'contoso', $connection->fresh(['tenant']));
expect($user)->not->toBeNull()
->and($resolution->resolved)->toBeFalse()
->and($resolution->reasonCode)->toBe('provider_binding_unsupported')
->and($resolution->extensionReasonCode)->toBe('ext.connection_scope_unsupported')
->and($resolution->message)->toBe('This provider and target-scope combination is not supported.');
});