ldc-arcadia-api/tests/Unit/Application/Security/ValueObjects/Entities/ClientIdTest.php

45 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace Tests\Unit\Application\Security\ValueObjects\Entities;
use Application\Security\Models\ValueObjects\Entities\ClientId;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Shared\Helpers\Exceptions\InvalidUuidException;
covers(ClientId::class);
describe('ClientId Value Object Instantiation', function (): void {
it('accepts valid UUIDv7 identifier', function (): void {
// GIVEN
$uuid7 = Uuid::uuid7();
// WHEN
$clientId = new ClientId($uuid7);
// THEN
expect($clientId->identifier)->toBe($uuid7)
->and($clientId->value)->toBe($uuid7->toString())
->and($clientId->toDateTime())->toBeInstanceOf(\DateTimeInterface::class)
->and($clientId->toDateTime()->getTimestamp())->toBeLessThanOrEqual(time());
});
});
describe('ClientId Value Object Validation Rules', function (): void {
it('throws InvalidUuidException when given a non-v7 UUID identifier', function (UuidInterface $nonV7Uuid): void {
// GIVEN
$input = $nonV7Uuid;
// WHEN
$execution = fn () => new ClientId($input);
// THEN
expect($execution)->toThrow(InvalidUuidException::class);
})->with([
fn () => Uuid::uuid4(),
fn () => Uuid::uuid1(),
]);
});