ldc-arcadia-api/tests/Integration/Infra/Database/Models/ApiClientModelTest.php

36 lines
1.1 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace Tests\Integration\Infra\Database\Models;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Infra\Database\Models\ApiClient;
use Ramsey\Uuid\Uuid;
use Tests\TestCase;
covers(ApiClient::class);
uses(TestCase::class, RefreshDatabase::class);
describe('ApiClient Eloquent Model & Factory', function (): void {
it('creates and persists an ApiClient record with created_at automatically derived from UUIDv7', function (): void {
// GIVEN
$expectedDate = new \DateTimeImmutable('2026-08-21 08:30:00 UTC');
$uuid7 = Uuid::uuid7($expectedDate)->toString();
// WHEN
$client = ApiClient::factory()->create([
'id' => $uuid7,
]);
$retrieved = ApiClient::query()->find($client->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-21 08:30:00');
});
});