Replaces the “Add Policies” picker with a modal table (search, pagination, multi-select). Adds filters: policy type, platform, last synced, ignored, has versions; “Select all” applies to the current filtered results. Improves identifiers shown (short external id), and fixes has-versions filtering behavior. Backup set items table: groups row actions (View policy / Remove) into an action group. Adds bulk action to remove multiple backup items at once. Updates/adds tests covering the picker table bulk add and backup items bulk remove. Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local> Reviewed-on: #21
98 lines
3.1 KiB
PHP
98 lines
3.1 KiB
PHP
<?php
|
|
|
|
use App\Livewire\BackupSetPolicyPickerTable;
|
|
use App\Models\BackupSet;
|
|
use App\Models\Policy;
|
|
use App\Models\PolicyVersion;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Services\Intune\BackupService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
use Mockery\MockInterface;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
test('policy picker table bulk adds selected policies to backup set', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$tenant->makeCurrent();
|
|
|
|
$user = User::factory()->create();
|
|
|
|
$backupSet = BackupSet::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'name' => 'Test backup',
|
|
]);
|
|
|
|
$policies = Policy::factory()->count(2)->create([
|
|
'tenant_id' => $tenant->id,
|
|
'ignored_at' => null,
|
|
'last_synced_at' => now(),
|
|
]);
|
|
|
|
$this->mock(BackupService::class, function (MockInterface $mock) use ($tenant, $backupSet, $policies, $user) {
|
|
$mock->shouldReceive('addPoliciesToSet')
|
|
->once()
|
|
->withArgs(function ($tenantArg, $backupSetArg, $policyIds, $actorEmail, $actorName, $includeAssignments, $includeScopeTags, $includeFoundations) use ($tenant, $backupSet, $policies, $user) {
|
|
expect($tenantArg->id)->toBe($tenant->id);
|
|
expect($backupSetArg->id)->toBe($backupSet->id);
|
|
expect($policyIds)->toBe($policies->pluck('id')->all());
|
|
expect($actorEmail)->toBe($user->email);
|
|
expect($actorName)->toBe($user->name);
|
|
expect($includeAssignments)->toBeTrue();
|
|
expect($includeScopeTags)->toBeTrue();
|
|
expect($includeFoundations)->toBeTrue();
|
|
|
|
return true;
|
|
});
|
|
});
|
|
|
|
Livewire::actingAs($user)
|
|
->test(BackupSetPolicyPickerTable::class, [
|
|
'backupSetId' => $backupSet->id,
|
|
])
|
|
->callTableBulkAction('add_selected_to_backup_set', $policies)
|
|
->assertHasNoTableBulkActionErrors();
|
|
});
|
|
|
|
test('policy picker table can filter by has versions', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$tenant->makeCurrent();
|
|
|
|
$user = User::factory()->create();
|
|
|
|
$backupSet = BackupSet::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'name' => 'Test backup',
|
|
]);
|
|
|
|
$withVersions = Policy::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'display_name' => 'With Versions',
|
|
'ignored_at' => null,
|
|
'last_synced_at' => now(),
|
|
]);
|
|
|
|
PolicyVersion::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'policy_id' => $withVersions->id,
|
|
'policy_type' => $withVersions->policy_type,
|
|
'platform' => $withVersions->platform,
|
|
]);
|
|
|
|
$withoutVersions = Policy::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'display_name' => 'Without Versions',
|
|
'ignored_at' => null,
|
|
'last_synced_at' => now(),
|
|
]);
|
|
|
|
Livewire::actingAs($user)
|
|
->test(BackupSetPolicyPickerTable::class, [
|
|
'backupSetId' => $backupSet->id,
|
|
])
|
|
->filterTable('has_versions', '1')
|
|
->assertSee('With Versions')
|
|
->assertDontSee('Without Versions');
|
|
});
|