## Summary - Fixes misleading “queued / running in background” message when Review Pack generation request reuses an existing ready pack (fingerprint dedupe). - Improves resilience of Filament/Livewire interactions by ensuring the Livewire intercept shim applies after Livewire initializes. - Aligns Review Pack operation notifications with Ops-UX patterns (queued + completed notifications) and removes the old ReviewPackStatusNotification. ## Key Changes - Review Pack generate action now: - Shows queued toast only when a new pack is actually created/queued. - Shows a “Review pack already available” success notification with a link when dedupe returns an existing pack. ## Tests - `vendor/bin/sail artisan test --compact tests/Feature/ReviewPack/ReviewPackGenerationTest.php` - `vendor/bin/sail artisan test --compact tests/Feature/ReviewPack/ReviewPackResourceTest.php` - `vendor/bin/sail artisan test --compact tests/Feature/LivewireInterceptShimTest.php` ## Notes - No global search behavior changes for ReviewPacks (still excluded). - Destructive actions remain confirmation-gated (`->requiresConfirmation()`). Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #133
164 lines
5.4 KiB
PHP
164 lines
5.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\AlertRuleResource;
|
|
use App\Models\AlertRule;
|
|
use App\Models\ReviewPack;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
Storage::fake('exports');
|
|
});
|
|
|
|
it('expires ready packs past retention and deletes their files', function (): void {
|
|
[$user, $tenant] = createUserWithTenant();
|
|
|
|
$filePath = 'review-packs/test-expired.zip';
|
|
Storage::disk('exports')->put($filePath, 'fake content');
|
|
|
|
$pack = ReviewPack::factory()->ready()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'file_path' => $filePath,
|
|
'expires_at' => now()->subDay(),
|
|
]);
|
|
|
|
$this->artisan('tenantpilot:review-pack:prune')
|
|
->assertSuccessful();
|
|
|
|
$pack->refresh();
|
|
expect($pack->status)->toBe(ReviewPack::STATUS_EXPIRED)
|
|
->and(Storage::disk('exports')->exists($filePath))->toBeFalse();
|
|
});
|
|
|
|
it('does not expire ready packs with future retention', function (): void {
|
|
[$user, $tenant] = createUserWithTenant();
|
|
|
|
$filePath = 'review-packs/test-future.zip';
|
|
Storage::disk('exports')->put($filePath, 'fake content');
|
|
|
|
$pack = ReviewPack::factory()->ready()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'file_path' => $filePath,
|
|
'expires_at' => now()->addDays(30),
|
|
]);
|
|
|
|
$this->artisan('tenantpilot:review-pack:prune')
|
|
->assertSuccessful();
|
|
|
|
$pack->refresh();
|
|
expect($pack->status)->toBe(ReviewPack::STATUS_READY)
|
|
->and(Storage::disk('exports')->exists($filePath))->toBeTrue();
|
|
});
|
|
|
|
it('hard-deletes expired packs past grace period', function (): void {
|
|
[$user, $tenant] = createUserWithTenant();
|
|
|
|
$graceDays = config('tenantpilot.review_pack.hard_delete_grace_days', 30);
|
|
|
|
$pack = ReviewPack::factory()->expired()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'updated_at' => now()->subDays($graceDays + 5),
|
|
]);
|
|
|
|
$this->artisan('tenantpilot:review-pack:prune --hard-delete')
|
|
->assertSuccessful();
|
|
|
|
expect(ReviewPack::query()->whereKey($pack->getKey())->exists())->toBeFalse();
|
|
});
|
|
|
|
it('keeps expired packs within grace period when hard-deleting', function (): void {
|
|
[$user, $tenant] = createUserWithTenant();
|
|
|
|
$pack = ReviewPack::factory()->expired()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'updated_at' => now()->subDays(5),
|
|
]);
|
|
|
|
$this->artisan('tenantpilot:review-pack:prune --hard-delete')
|
|
->assertSuccessful();
|
|
|
|
expect(ReviewPack::query()->whereKey($pack->getKey())->exists())->toBeTrue();
|
|
});
|
|
|
|
it('outputs correct counts', function (): void {
|
|
[$user, $tenant] = createUserWithTenant();
|
|
|
|
// 2 packs past retention → expired
|
|
ReviewPack::factory()->count(2)->ready()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'expires_at' => now()->subDays(3),
|
|
]);
|
|
|
|
$this->artisan('tenantpilot:review-pack:prune')
|
|
->expectsOutputToContain('2 pack(s) expired, 0 pack(s) hard-deleted')
|
|
->assertSuccessful();
|
|
});
|
|
|
|
it('outputs hard-delete counts when option is passed', function (): void {
|
|
[$user, $tenant] = createUserWithTenant();
|
|
|
|
$graceDays = config('tenantpilot.review_pack.hard_delete_grace_days', 30);
|
|
|
|
// 1 pack past retention → expired
|
|
ReviewPack::factory()->ready()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'expires_at' => now()->subDay(),
|
|
]);
|
|
|
|
// 1 expired pack past grace → hard-deleted
|
|
ReviewPack::factory()->expired()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'updated_at' => now()->subDays($graceDays + 10),
|
|
]);
|
|
|
|
$this->artisan('tenantpilot:review-pack:prune --hard-delete')
|
|
->expectsOutputToContain('1 pack(s) expired, 1 pack(s) hard-deleted')
|
|
->assertSuccessful();
|
|
});
|
|
|
|
it('does not hard-delete without the flag', function (): void {
|
|
[$user, $tenant] = createUserWithTenant();
|
|
|
|
$graceDays = config('tenantpilot.review_pack.hard_delete_grace_days', 30);
|
|
|
|
$pack = ReviewPack::factory()->expired()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'updated_at' => now()->subDays($graceDays + 10),
|
|
]);
|
|
|
|
$this->artisan('tenantpilot:review-pack:prune')
|
|
->assertSuccessful();
|
|
|
|
expect(ReviewPack::query()->whereKey($pack->getKey())->exists())->toBeTrue();
|
|
});
|
|
|
|
it('AlertRule form no longer shows sla_due option', function (): void {
|
|
$options = AlertRuleResource::eventTypeOptions();
|
|
|
|
expect($options)->not->toHaveKey(AlertRule::EVENT_SLA_DUE)
|
|
->and($options)->toHaveKey(AlertRule::EVENT_HIGH_DRIFT)
|
|
->and($options)->toHaveKey(AlertRule::EVENT_COMPARE_FAILED)
|
|
->and($options)->toHaveKey(AlertRule::EVENT_PERMISSION_MISSING)
|
|
->and($options)->toHaveKey(AlertRule::EVENT_ENTRA_ADMIN_ROLES_HIGH);
|
|
});
|