148 lines
5.5 KiB
PHP
148 lines
5.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\ProviderConnectionResource;
|
|
use App\Filament\Resources\ProviderConnectionResource\Pages\ListProviderConnections;
|
|
use App\Models\ProviderConnection;
|
|
use App\Support\Providers\ProviderConsentStatus;
|
|
use App\Support\Providers\ProviderVerificationStatus;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('promotes consent and verification to the default-visible provider connection list axes', 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' => 'Contoso',
|
|
'provider' => 'microsoft',
|
|
'is_default' => true,
|
|
'consent_status' => ProviderConsentStatus::Granted->value,
|
|
'verification_status' => ProviderVerificationStatus::Degraded->value,
|
|
'status' => 'connected',
|
|
'health_status' => 'ok',
|
|
]);
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$component = Livewire::actingAs($user)
|
|
->test(ListProviderConnections::class)
|
|
->assertCanSeeTableRecords([$connection]);
|
|
|
|
$table = $component->instance()->getTable();
|
|
$visibleColumnNames = collect($table->getVisibleColumns())
|
|
->map(fn ($column): string => $column->getName())
|
|
->values()
|
|
->all();
|
|
|
|
expect($visibleColumnNames)->toContain('consent_status', 'verification_status')
|
|
->and($visibleColumnNames)->not->toContain('status')
|
|
->and($visibleColumnNames)->not->toContain('health_status')
|
|
->and($table->getColumn('status')?->isToggledHiddenByDefault())->toBeTrue()
|
|
->and($table->getColumn('health_status')?->isToggledHiddenByDefault())->toBeTrue();
|
|
});
|
|
|
|
it('separates current state from diagnostics on the provider connection view page', 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' => 'Truthful Connection',
|
|
'provider' => 'microsoft',
|
|
'is_default' => true,
|
|
'consent_status' => ProviderConsentStatus::Granted->value,
|
|
'verification_status' => ProviderVerificationStatus::Degraded->value,
|
|
'status' => 'connected',
|
|
'health_status' => 'ok',
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->get(ProviderConnectionResource::getUrl('view', ['record' => $connection], tenant: $tenant))
|
|
->assertOk()
|
|
->assertSeeInOrder([
|
|
'Current state',
|
|
'Consent',
|
|
'Granted',
|
|
'Verification',
|
|
'Degraded',
|
|
'Diagnostics',
|
|
'Legacy status',
|
|
'Connected',
|
|
'Legacy health',
|
|
'OK',
|
|
]);
|
|
});
|
|
|
|
it('shows current consent and verification context before diagnostics on the provider connection edit page', 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' => 'Editable Truthful Connection',
|
|
'provider' => 'microsoft',
|
|
'is_default' => true,
|
|
'consent_status' => ProviderConsentStatus::Granted->value,
|
|
'verification_status' => ProviderVerificationStatus::Blocked->value,
|
|
'status' => 'connected',
|
|
'health_status' => 'ok',
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->get(ProviderConnectionResource::getUrl('edit', ['record' => $connection], tenant: $tenant))
|
|
->assertOk()
|
|
->assertSeeInOrder([
|
|
'Current state',
|
|
'Consent',
|
|
'Granted',
|
|
'Verification',
|
|
'Blocked',
|
|
'Diagnostics',
|
|
'Legacy status',
|
|
'Connected',
|
|
'Legacy health',
|
|
'OK',
|
|
]);
|
|
});
|
|
|
|
it('does not treat consented but unverified connections as ready across provider surfaces', 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' => 'Unknown Verification Connection',
|
|
'provider' => 'microsoft',
|
|
'is_default' => true,
|
|
'consent_status' => ProviderConsentStatus::Granted->value,
|
|
'verification_status' => ProviderVerificationStatus::Unknown->value,
|
|
'status' => 'connected',
|
|
'health_status' => 'ok',
|
|
]);
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::actingAs($user)
|
|
->test(ListProviderConnections::class)
|
|
->assertCanSeeTableRecords([$connection])
|
|
->assertSee('Granted')
|
|
->assertSee('Unknown')
|
|
->assertDontSee('Ready');
|
|
|
|
$this->get(ProviderConnectionResource::getUrl('view', ['record' => $connection], tenant: $tenant))
|
|
->assertOk()
|
|
->assertSee('Granted')
|
|
->assertSee('Unknown')
|
|
->assertDontSee('Ready');
|
|
});
|