TenantAtlas/tests/Feature/PermissionPosture/PruneStoredReportsCommandTest.php
Ahmed Darrazi 222a7e0a97 feat(104): implement Provider Permission Posture
- T001-T014: Foundation - StoredReport model/migration, Finding resolved
  lifecycle, badge mappings (resolved status, permission_posture type),
  OperationCatalog + AlertRule constants
- T015-T022: US1 - PermissionPostureFindingGenerator with fingerprint-based
  idempotent upsert, severity from feature-impact count, auto-resolve on
  grant, auto-reopen on revoke, error findings (FR-015), stale finding
  cleanup; GeneratePermissionPostureFindingsJob dispatched from health check;
  PostureResult VO + PostureScoreCalculator
- T023-T026: US2+US4 - Stored report payload validation, temporal ordering,
  polymorphic reusability, score accuracy acceptance tests
- T027-T029: US3 - EvaluateAlertsJob.permissionMissingEvents() wired into
  alert pipeline, AlertRuleResource event type option, cooldown/dedupe tests
- T030-T034: Polish - PruneStoredReportsCommand with config retention,
  scheduled daily, end-to-end integration test, Pint clean

UI bug fixes found during testing:
- FindingResource: hide Diff section for non-drift findings
- TenantRequiredPermissions: fix re-run verification link
- tenant-required-permissions.blade.php: preserve details open state

70 tests (50 PermissionPosture + 20 FindingResolved/Badge/Alert), 216 assertions
2026-02-21 23:31:03 +01:00

62 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\StoredReport;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('deletes reports older than retention threshold', function (): void {
$old = StoredReport::factory()->create([
'created_at' => now()->subDays(100),
]);
$recent = StoredReport::factory()->create([
'created_at' => now()->subDays(10),
]);
$this->artisan('stored-reports:prune')
->assertSuccessful();
expect(StoredReport::query()->whereKey($old->getKey())->exists())->toBeFalse()
->and(StoredReport::query()->whereKey($recent->getKey())->exists())->toBeTrue();
});
it('preserves reports within retention threshold', function (): void {
$report = StoredReport::factory()->create([
'created_at' => now()->subDays(89),
]);
$this->artisan('stored-reports:prune')
->assertSuccessful();
expect(StoredReport::query()->whereKey($report->getKey())->exists())->toBeTrue();
});
it('custom --days flag overrides config default', function (): void {
$report30daysOld = StoredReport::factory()->create([
'created_at' => now()->subDays(35),
]);
$report10daysOld = StoredReport::factory()->create([
'created_at' => now()->subDays(10),
]);
$this->artisan('stored-reports:prune --days=30')
->assertSuccessful();
expect(StoredReport::query()->whereKey($report30daysOld->getKey())->exists())->toBeFalse()
->and(StoredReport::query()->whereKey($report10daysOld->getKey())->exists())->toBeTrue();
});
it('outputs the count of deleted records', function (): void {
StoredReport::factory()->count(3)->create([
'created_at' => now()->subDays(200),
]);
$this->artisan('stored-reports:prune')
->expectsOutputToContain('Deleted 3 stored report(s)')
->assertSuccessful();
});