TenantAtlas/apps/platform/tests/Feature/Filament/TenantDiagnosticsRepairsTest.php
ahmido 38523814c2 fix: restore full-suite green signals across platform workflows (#351)
## Summary
- restore broad full-suite green-signal coverage across platform governance, operations, onboarding, dashboard/productization, and customer review flows
- align related platform tests and supporting behavior with the current expected state for this restoration pass
- update the spec-candidates queue as part of the same suite-restoration sweep

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Browser/Dashboard/TenantDashboardProductizationSmokeTest.php tests/Browser/Reviews/CustomerReviewWorkspaceSmokeTest.php tests/Browser/Spec194GovernanceFrictionSmokeTest.php tests/Browser/Spec265DecisionRegisterSmokeTest.php`

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #351
2026-05-12 18:50:40 +00:00

121 lines
4.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Pages\TenantDiagnostics;
use App\Models\AuditLog;
use App\Models\ManagedEnvironmentMembership;
use App\Support\Audit\AuditActionId;
use App\Support\Rbac\UiTooltips;
use Filament\Actions\Action;
use Filament\Facades\Filament;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Livewire\Livewire;
uses(RefreshDatabase::class);
describe('ManagedEnvironment diagnostics repairs', function () {
it('hides repair actions when no defect is present', function () {
[$owner, $tenant] = createUserWithTenant(role: 'owner');
$this->actingAs($owner);
Filament::setTenant($tenant, true);
Livewire::test(TenantDiagnostics::class)
->assertSee('All good')
->assertActionHidden('bootstrapOwner')
->assertActionHidden('mergeDuplicateMemberships');
});
it('keeps owner bootstrap hidden because workspace roles own role recovery', function () {
[$manager, $tenant] = createUserWithTenant(role: 'manager');
$this->actingAs($manager);
Filament::setTenant($tenant, true);
expect(ManagedEnvironmentMembership::query()
->where('managed_environment_id', (int) $tenant->getKey())
->where('role', 'owner')
->count())->toBe(0);
Livewire::test(TenantDiagnostics::class)
->assertDontSee('Missing owner')
->assertActionHidden('bootstrapOwner');
});
it('shows duplicate-scope repair as disabled for readonly members', function () {
[$readonly, $tenant] = createUserWithTenant(role: 'readonly');
$this->actingAs($readonly);
Filament::setTenant($tenant, true);
Schema::table('managed_environment_memberships', function (Blueprint $table): void {
$table->dropUnique(['managed_environment_id', 'user_id']);
});
ManagedEnvironmentMembership::query()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'user_id' => (int) $readonly->getKey(),
'role' => 'readonly',
'source' => 'manual',
'created_by_user_id' => (int) $readonly->getKey(),
]);
Livewire::test(TenantDiagnostics::class)
->assertActionVisible('mergeDuplicateMemberships')
->assertActionDisabled('mergeDuplicateMemberships')
->assertActionExists('mergeDuplicateMemberships', function (Action $action): bool {
return $action->getTooltip() === UiTooltips::INSUFFICIENT_PERMISSION;
});
});
it('merges duplicate memberships for the current user (diagnostics repair)', function () {
[$owner, $tenant] = createUserWithTenant(role: 'owner');
$this->actingAs($owner);
Filament::setTenant($tenant, true);
// Intentionally create a broken state by temporarily dropping the current uniqueness enforcement.
Schema::table('managed_environment_memberships', function (Blueprint $table): void {
$table->dropUnique(['managed_environment_id', 'user_id']);
});
ManagedEnvironmentMembership::query()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'user_id' => (int) $owner->getKey(),
'role' => 'readonly',
'source' => 'manual',
'created_by_user_id' => (int) $owner->getKey(),
]);
expect(ManagedEnvironmentMembership::query()
->where('managed_environment_id', (int) $tenant->getKey())
->where('user_id', (int) $owner->getKey())
->count())->toBeGreaterThan(1);
Livewire::test(TenantDiagnostics::class)
->assertActionVisible('mergeDuplicateMemberships')
->assertActionEnabled('mergeDuplicateMemberships')
->mountAction('mergeDuplicateMemberships')
->callMountedAction()
->assertSuccessful();
expect(ManagedEnvironmentMembership::query()
->where('managed_environment_id', (int) $tenant->getKey())
->where('user_id', (int) $owner->getKey())
->count())->toBe(1);
expect(AuditLog::query()
->where('managed_environment_id', (int) $tenant->getKey())
->where('action', AuditActionId::TenantMembershipDuplicatesMerged->value)
->exists())->toBeTrue();
});
});