Implements the Settings foundation workspace controls. Includes: - Settings foundation UI/controls scoped to workspace context - Related onboarding/consent flow adjustments as included in branch history Testing: - `vendor/bin/sail artisan test --compact --no-ansi --filter=SettingsFoundation` Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #119
105 lines
3.6 KiB
PHP
105 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Pages\Settings\WorkspaceSettings;
|
|
use App\Models\AuditLog;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use App\Models\WorkspaceMembership;
|
|
use App\Models\WorkspaceSetting;
|
|
use App\Services\Settings\SettingsResolver;
|
|
use App\Services\Settings\SettingsWriter;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Livewire\Livewire;
|
|
|
|
it('allows workspace managers to save and reset the workspace retention default', function (): void {
|
|
$workspace = Workspace::factory()->create();
|
|
$user = User::factory()->create();
|
|
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'user_id' => (int) $user->getKey(),
|
|
'role' => 'manager',
|
|
]);
|
|
|
|
session()->put(WorkspaceContext::SESSION_KEY, (int) $workspace->getKey());
|
|
|
|
$this->actingAs($user)
|
|
->get(WorkspaceSettings::getUrl(panel: 'admin'))
|
|
->assertSuccessful();
|
|
|
|
$component = Livewire::actingAs($user)
|
|
->test(WorkspaceSettings::class)
|
|
->assertSet('data.backup_retention_keep_last_default', 30)
|
|
->set('data.backup_retention_keep_last_default', 55)
|
|
->callAction('save')
|
|
->assertHasNoErrors()
|
|
->assertSet('data.backup_retention_keep_last_default', 55);
|
|
|
|
expect(WorkspaceSetting::query()
|
|
->where('workspace_id', (int) $workspace->getKey())
|
|
->where('domain', 'backup')
|
|
->where('key', 'retention_keep_last_default')
|
|
->exists())->toBeTrue();
|
|
|
|
expect(app(SettingsResolver::class)->resolveValue($workspace, 'backup', 'retention_keep_last_default'))
|
|
->toBe(55);
|
|
|
|
$component
|
|
->callAction('reset')
|
|
->assertHasNoErrors()
|
|
->assertSet('data.backup_retention_keep_last_default', 30);
|
|
|
|
expect(WorkspaceSetting::query()
|
|
->where('workspace_id', (int) $workspace->getKey())
|
|
->where('domain', 'backup')
|
|
->where('key', 'retention_keep_last_default')
|
|
->exists())->toBeFalse();
|
|
|
|
expect(app(SettingsResolver::class)->resolveValue($workspace, 'backup', 'retention_keep_last_default'))
|
|
->toBe(30);
|
|
});
|
|
|
|
it('rejects unknown setting keys and does not persist or audit changes', function (): void {
|
|
$workspace = Workspace::factory()->create();
|
|
$user = User::factory()->create();
|
|
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'user_id' => (int) $user->getKey(),
|
|
'role' => 'manager',
|
|
]);
|
|
|
|
$writer = app(SettingsWriter::class);
|
|
|
|
expect(fn () => $writer->updateWorkspaceSetting($user, $workspace, 'backup', 'unknown_setting_key', 25))
|
|
->toThrow(ValidationException::class);
|
|
|
|
expect(WorkspaceSetting::query()->count())->toBe(0);
|
|
expect(AuditLog::query()->count())->toBe(0);
|
|
});
|
|
|
|
it('rejects invalid setting values and does not persist or audit changes', function (): void {
|
|
$workspace = Workspace::factory()->create();
|
|
$user = User::factory()->create();
|
|
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'user_id' => (int) $user->getKey(),
|
|
'role' => 'manager',
|
|
]);
|
|
|
|
$writer = app(SettingsWriter::class);
|
|
|
|
expect(fn () => $writer->updateWorkspaceSetting($user, $workspace, 'backup', 'retention_keep_last_default', 'not-an-integer'))
|
|
->toThrow(ValidationException::class);
|
|
|
|
expect(fn () => $writer->updateWorkspaceSetting($user, $workspace, 'backup', 'retention_keep_last_default', 0))
|
|
->toThrow(ValidationException::class);
|
|
|
|
expect(WorkspaceSetting::query()->count())->toBe(0);
|
|
expect(AuditLog::query()->count())->toBe(0);
|
|
});
|