TenantAtlas/tests/Unit/Settings/FindingsSlaDaysSettingTest.php
ahmido 7ac53f4cc4 feat(111): findings workflow + SLA settings (#135)
Implements spec 111 (Findings workflow + SLA) and fixes Workspace findings SLA settings UX/validation.

Key changes:
- Findings workflow service + SLA policy and alerting.
- Workspace settings: allow partial SLA overrides without auto-filling unset severities in the UI; effective values still resolve via defaults.
- New migrations, jobs, command, UI/resource updates, and comprehensive test coverage.

Tests:
- `vendor/bin/sail artisan test --compact` (1779 passed, 8 skipped).

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #135
2026-02-25 01:48:01 +00:00

76 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
use App\Support\Settings\SettingsRegistry;
use Illuminate\Support\Facades\Validator;
it('registers findings sla_days with defaults', function (): void {
$definition = app(SettingsRegistry::class)->require('findings', 'sla_days');
expect($definition->type)->toBe('json')
->and($definition->systemDefault)->toBe([
'critical' => 3,
'high' => 7,
'medium' => 14,
'low' => 30,
]);
});
it('validates findings sla_days values and normalizes them', function (): void {
$definition = app(SettingsRegistry::class)->require('findings', 'sla_days');
$valid = [
'medium' => '14',
'critical' => '3',
'low' => 30,
'high' => 7,
];
$validator = Validator::make(
['value' => $valid],
['value' => $definition->rules],
);
expect($validator->fails())->toBeFalse();
expect($definition->normalize($validator->validated()['value']))->toBe([
'critical' => 3,
'high' => 7,
'medium' => 14,
'low' => 30,
]);
});
it('rejects malformed findings sla_days values', function (): void {
$definition = app(SettingsRegistry::class)->require('findings', 'sla_days');
$invalidValue = Validator::make(
['value' => ['critical' => 0, 'high' => 7, 'medium' => 14, 'low' => 30]],
['value' => $definition->rules],
);
$unknownSeverity = Validator::make(
['value' => ['critical' => 3, 'high' => 7, 'medium' => 14, 'low' => 30, 'urgent' => 1]],
['value' => $definition->rules],
);
expect($invalidValue->fails())->toBeTrue()
->and($unknownSeverity->fails())->toBeTrue();
});
it('allows partial findings sla_days and stores only provided keys', function (): void {
$definition = app(SettingsRegistry::class)->require('findings', 'sla_days');
$partial = ['critical' => 2];
$validator = Validator::make(
['value' => $partial],
['value' => $definition->rules],
);
expect($validator->fails())->toBeFalse();
expect($definition->normalize($validator->validated()['value']))->toBe([
'critical' => 2,
]);
});