88 lines
3 KiB
PHP
88 lines
3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Application\Security\Usecases\GetSecurityAuditLogs;
|
|
|
|
use Application\Security\Models\Entities\SecurityAuditLogEntry;
|
|
use Application\Security\Models\ValueObjects\Entities\SecurityAuditLogDetails;
|
|
use Application\Security\Models\ValueObjects\Entities\SecurityAuditLogEntryId;
|
|
use Application\Security\Usecases\GetSecurityAuditLogs\Input;
|
|
use Application\Security\Usecases\GetSecurityAuditLogs\Output;
|
|
use Ramsey\Uuid\Uuid;
|
|
use Shared\DDD\Usecase\Input as BaseInput;
|
|
use Shared\DDD\Usecase\Output as BaseOutput;
|
|
|
|
covers(
|
|
Input::class,
|
|
Output::class,
|
|
);
|
|
|
|
describe('GetSecurityAuditLogs DTOs', function (): void {
|
|
it('creates Input with required and optional filters', function (): void {
|
|
// GIVEN
|
|
$since = new \DateTimeImmutable('2026-01-01 00:00:00');
|
|
$to = new \DateTimeImmutable('2026-01-31 23:59:59');
|
|
$client = 'arcadia_id_' . str_repeat('a', 32);
|
|
$eventType = 'client.status_changed';
|
|
|
|
// WHEN
|
|
$input = new Input(
|
|
since: $since,
|
|
to: $to,
|
|
client: $client,
|
|
eventType: $eventType,
|
|
);
|
|
|
|
// THEN
|
|
expect($input)->toBeInstanceOf(BaseInput::class)
|
|
->and($input->since)->toBe($since)
|
|
->and($input->to)->toBe($to)
|
|
->and($input->client)->toBe($client)
|
|
->and($input->eventType)->toBe($eventType);
|
|
});
|
|
|
|
it('creates Output with entries and provides count', function (): void {
|
|
// GIVEN
|
|
$since = new \DateTimeImmutable('2026-01-01 00:00:00');
|
|
$to = new \DateTimeImmutable('2026-01-31 23:59:59');
|
|
|
|
$entry1 = new SecurityAuditLogEntry(
|
|
id: new SecurityAuditLogEntryId(Uuid::uuid7()),
|
|
clientId: Uuid::uuid7(),
|
|
clientIdentifier: 'arcadia_id_' . str_repeat('a', 32),
|
|
eventType: 'client.secret_rotated',
|
|
details: new SecurityAuditLogDetails([]),
|
|
);
|
|
$entry2 = new SecurityAuditLogEntry(
|
|
id: new SecurityAuditLogEntryId(Uuid::uuid7()),
|
|
clientId: Uuid::uuid7(),
|
|
clientIdentifier: 'arcadia_id_' . str_repeat('b', 32),
|
|
eventType: 'client.status_changed',
|
|
details: new SecurityAuditLogDetails(['is_active' => 'true']),
|
|
);
|
|
|
|
// WHEN
|
|
$output = new Output($since, $to, $entry1, $entry2);
|
|
|
|
// THEN
|
|
expect($output)->toBeInstanceOf(BaseOutput::class)
|
|
->and($output->since)->toBe($since)
|
|
->and($output->to)->toBe($to)
|
|
->and($output->entries)->toBe([$entry1, $entry2])
|
|
->and($output->count())->toBe(2);
|
|
});
|
|
|
|
it('creates empty Output when no entries are passed', function (): void {
|
|
// GIVEN
|
|
$since = new \DateTimeImmutable('2026-01-01 00:00:00');
|
|
$to = new \DateTimeImmutable('2026-01-31 23:59:59');
|
|
|
|
// WHEN
|
|
$output = new Output($since, $to);
|
|
|
|
// THEN
|
|
expect($output->entries)->toBeEmpty()
|
|
->and($output->count())->toBe(0);
|
|
});
|
|
});
|