41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Tests\Integration\Infra\Database\Models;
|
||
|
|
|
||
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
|
|
use Infra\Database\Models\ClientAuditLog;
|
||
|
|
use Ramsey\Uuid\Uuid;
|
||
|
|
use Tests\TestCase;
|
||
|
|
|
||
|
|
covers(ClientAuditLog::class);
|
||
|
|
|
||
|
|
uses(TestCase::class, RefreshDatabase::class);
|
||
|
|
|
||
|
|
describe('ClientAuditLog Eloquent Model', function (): void {
|
||
|
|
it('creates and persists a ClientAuditLog record with computed created_at from UUIDv7', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$expectedDate = new \DateTimeImmutable('2026-08-20 14:15:00 UTC');
|
||
|
|
$uuid7 = Uuid::uuid7($expectedDate)->toString();
|
||
|
|
$clientId = Uuid::uuid7()->toString();
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$log = ClientAuditLog::query()->create([
|
||
|
|
'id' => $uuid7,
|
||
|
|
'client_id' => $clientId,
|
||
|
|
'client_identifier' => 'arcadia_id_' . str_repeat('a', 32),
|
||
|
|
'event_type' => 'client_secret_generated',
|
||
|
|
'details' => null,
|
||
|
|
]);
|
||
|
|
|
||
|
|
$retrieved = ClientAuditLog::query()->find($log->id);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($retrieved)->not->toBeNull()
|
||
|
|
->and($retrieved?->id->toString())->toBe($uuid7)
|
||
|
|
->and($retrieved?->created_at)->toBeInstanceOf(\DateTimeImmutable::class)
|
||
|
|
->and($retrieved?->created_at?->format('Y-m-d H:i:s'))->toBe('2026-08-20 14:15:00');
|
||
|
|
});
|
||
|
|
});
|