From 9c28cf2903eaeeaf2e45689c60901d83a4802288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Thu, 20 Aug 2026 12:08:15 +0200 Subject: [PATCH] refactor(database): add timestamps to ApiClient and Employee models Updated ApiClient and Employee models to include created_at and updated_at fields for better tracking of records. --- database/seeders/ApiClientSeeder.php | 13 ++++++++----- .../Repositories/ApiClientRepository.php | 2 ++ src/Infra/Database/Models/ApiClient.php | 8 ++++---- src/Infra/Database/Models/Employee.php | 2 ++ tests/Feature/Api/V1/VerifyHmacSignatureTest.php | 10 +++++----- .../Console/Commands/ListClientsCommandTest.php | 6 +++--- .../RegenerateClientSecretCommandTest.php | 10 +++++----- .../Commands/ToggleClientStatusCommandTest.php | 16 ++++++++-------- .../Repositories/ApiClientRepositoryTest.php | 10 +++++----- 9 files changed, 42 insertions(+), 35 deletions(-) diff --git a/database/seeders/ApiClientSeeder.php b/database/seeders/ApiClientSeeder.php index a6e3107..c7e872e 100644 --- a/database/seeders/ApiClientSeeder.php +++ b/database/seeders/ApiClientSeeder.php @@ -15,15 +15,18 @@ final class ApiClientSeeder extends Seeder { /** @var array{id: string, name: string, identifier: string, secret: string} $devClient */ $devClient = Config::array('auth.hmac.dev_client'); + $now = now(); ApiClient::query()->updateOrCreate( ['identifier' => $devClient['identifier']], [ - 'id' => $devClient['id'], - 'name' => $devClient['name'], - 'slug' => Str::slug($devClient['name']), - 'secret' => $devClient['secret'], - 'is_active' => true, + 'id' => $devClient['id'], + 'name' => $devClient['name'], + 'slug' => Str::slug($devClient['name']), + 'secret' => $devClient['secret'], + 'is_active' => true, + 'created_at' => $now, + 'updated_at' => $now, ] ); diff --git a/src/Infra/Adapters/Repositories/ApiClientRepository.php b/src/Infra/Adapters/Repositories/ApiClientRepository.php index c146490..ba189b8 100644 --- a/src/Infra/Adapters/Repositories/ApiClientRepository.php +++ b/src/Infra/Adapters/Repositories/ApiClientRepository.php @@ -29,6 +29,8 @@ final class ApiClientRepository implements ClientDirectory, ClientRepository 'identifier' => $client->identifier, 'secret' => $client->secret, 'is_active' => $client->isActive, + 'created_at' => $client->createdAt, + 'updated_at' => $client->updatedAt, ] ); } diff --git a/src/Infra/Database/Models/ApiClient.php b/src/Infra/Database/Models/ApiClient.php index 6edcaea..81917f8 100644 --- a/src/Infra/Database/Models/ApiClient.php +++ b/src/Infra/Database/Models/ApiClient.php @@ -18,9 +18,9 @@ use Infra\Casts\UuidCast; * @property \Ramsey\Uuid\UuidInterface $id * @property \Application\Security\Models\ValueObjects\ClientName $name * @property string $slug - * @property \Application\Security\Models\ValueObjects\ClientIdentifier $identifier - * @property \Application\Security\Models\ValueObjects\ClientSecret $secret - * @property bool $is_active + * @property \Application\Security\Models\ValueObjects\ClientIdentifier $identifier ENCRYPTED, Unique identifier that should not change + * @property \Application\Security\Models\ValueObjects\ClientSecret $secret ENCRYPTED, api secret that can be regenerated + * @property bool $is_active Defines if the client can be used in order to gain access to the system * @property \Illuminate\Support\Carbon $created_at * @property \Illuminate\Support\Carbon $updated_at * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications @@ -44,7 +44,7 @@ final class ApiClient extends Authenticatable protected $table = 'api_clients'; - public $timestamps = true; + public $timestamps = false; /** @var list */ protected $fillable = [ diff --git a/src/Infra/Database/Models/Employee.php b/src/Infra/Database/Models/Employee.php index 142f1db..7474c84 100644 --- a/src/Infra/Database/Models/Employee.php +++ b/src/Infra/Database/Models/Employee.php @@ -62,6 +62,8 @@ final class Employee extends Model 'establishment', 'site', 'service', + 'created_at', + 'updated_at', ]; /** @return array */ diff --git a/tests/Feature/Api/V1/VerifyHmacSignatureTest.php b/tests/Feature/Api/V1/VerifyHmacSignatureTest.php index a5c7e84..0854843 100644 --- a/tests/Feature/Api/V1/VerifyHmacSignatureTest.php +++ b/tests/Feature/Api/V1/VerifyHmacSignatureTest.php @@ -192,7 +192,7 @@ describe('VerifyHmacSignature Middleware Feature Tests', function (): void { $identifier = 'arcadia_id_' . str_repeat('a', 32); $secret = 'arcadia_sec_' . str_repeat('b', 86); - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => Uuid::uuid7()->toString(), 'name' => 'Inactive Client', 'slug' => 'test-' . uniqid(), @@ -228,7 +228,7 @@ describe('VerifyHmacSignature Middleware Feature Tests', function (): void { $identifier = 'arcadia_id_' . str_repeat('a', 32); $secret = 'arcadia_sec_' . str_repeat('b', 86); - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => Uuid::uuid7()->toString(), 'name' => 'Active Client', 'slug' => 'test-' . uniqid(), @@ -266,7 +266,7 @@ describe('VerifyHmacSignature Middleware Feature Tests', function (): void { $identifier = 'arcadia_id_' . str_repeat('a', 32); $secret = 'arcadia_sec_' . str_repeat('b', 86); - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => Uuid::uuid7()->toString(), 'name' => 'Active Client', 'slug' => 'test-' . uniqid(), @@ -303,7 +303,7 @@ describe('VerifyHmacSignature Middleware Feature Tests', function (): void { $identifier = 'arcadia_id_' . str_repeat('a', 32); $secret = 'arcadia_sec_' . str_repeat('b', 86); - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => Uuid::uuid7()->toString(), 'name' => 'Valid API Client', 'slug' => 'test-' . uniqid(), @@ -337,7 +337,7 @@ describe('VerifyHmacSignature Middleware Feature Tests', function (): void { $identifier = 'arcadia_id_' . str_repeat('a', 32); $secret = 'arcadia_sec_' . str_repeat('b', 86); - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => Uuid::uuid7()->toString(), 'name' => 'Valid API Client', 'slug' => 'test-' . uniqid(), diff --git a/tests/Feature/Console/Commands/ListClientsCommandTest.php b/tests/Feature/Console/Commands/ListClientsCommandTest.php index 9b1ce58..1b142a3 100644 --- a/tests/Feature/Console/Commands/ListClientsCommandTest.php +++ b/tests/Feature/Console/Commands/ListClientsCommandTest.php @@ -28,7 +28,7 @@ describe('ListClientsCommand', function (): void { /** @var \Tests\TestCase $this */ ApiClient::query()->delete(); - $client1 = ApiClient::query()->create([ + $client1 = ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Production Gateway', 'slug' => 'test-' . uniqid(), @@ -37,7 +37,7 @@ describe('ListClientsCommand', function (): void { 'is_active' => true, ]); - $client2 = ApiClient::query()->create([ + $client2 = ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Backup Gateway', 'slug' => 'test-' . uniqid(), @@ -78,7 +78,7 @@ describe('ListClientsCommand', function (): void { ApiClient::query()->delete(); for ($i = 1; $i <= 3; $i++) { - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => "Client {$i}", 'slug' => 'test-' . uniqid(), diff --git a/tests/Feature/Console/Commands/RegenerateClientSecretCommandTest.php b/tests/Feature/Console/Commands/RegenerateClientSecretCommandTest.php index c216a75..63672a6 100644 --- a/tests/Feature/Console/Commands/RegenerateClientSecretCommandTest.php +++ b/tests/Feature/Console/Commands/RegenerateClientSecretCommandTest.php @@ -42,7 +42,7 @@ describe('RegenerateClientSecretCommand', function (): void { $identifier = 'arcadia_id_' . str_repeat('a', 32); $oldSecret = 'arcadia_sec_' . str_repeat('1', 86); - $client = ApiClient::query()->create([ + $client = ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Production Gateway', 'slug' => 'production-gateway', @@ -70,7 +70,7 @@ describe('RegenerateClientSecretCommand', function (): void { $identifier = 'arcadia_id_' . str_repeat('b', 32); $oldSecret = 'arcadia_sec_' . str_repeat('2', 86); - $client = ApiClient::query()->create([ + $client = ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Staging Gateway', 'slug' => 'staging-gateway', @@ -96,7 +96,7 @@ describe('RegenerateClientSecretCommand', function (): void { $identifier = 'arcadia_id_' . str_repeat('d', 32); $oldSecret = 'arcadia_sec_' . str_repeat('3', 86); - $client = ApiClient::query()->create([ + $client = ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Searchable Client', 'slug' => 'searchable-client', @@ -125,7 +125,7 @@ describe('RegenerateClientSecretCommand', function (): void { /** @var \Tests\TestCase $this */ ApiClient::query()->delete(); - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Alpha Client', 'slug' => 'alpha-client', @@ -134,7 +134,7 @@ describe('RegenerateClientSecretCommand', function (): void { 'is_active' => true, ]); - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Beta Client', 'slug' => 'beta-client', diff --git a/tests/Feature/Console/Commands/ToggleClientStatusCommandTest.php b/tests/Feature/Console/Commands/ToggleClientStatusCommandTest.php index 8127baa..6e1647e 100644 --- a/tests/Feature/Console/Commands/ToggleClientStatusCommandTest.php +++ b/tests/Feature/Console/Commands/ToggleClientStatusCommandTest.php @@ -39,7 +39,7 @@ describe('ToggleClientStatusCommand', function (): void { it('toggles an active client to inactive when no status argument is passed', function (): void { // GIVEN /** @var \Tests\TestCase $this */ - $client = ApiClient::query()->create([ + $client = ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Production Gateway', 'slug' => 'test-' . uniqid(), @@ -61,7 +61,7 @@ describe('ToggleClientStatusCommand', function (): void { it('toggles an inactive client to active when no status argument is passed', function (): void { // GIVEN /** @var \Tests\TestCase $this */ - $client = ApiClient::query()->create([ + $client = ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Backup Gateway', 'slug' => 'test-' . uniqid(), @@ -83,7 +83,7 @@ describe('ToggleClientStatusCommand', function (): void { it('activates an inactive client when activate status is passed', function (): void { // GIVEN /** @var \Tests\TestCase $this */ - $client = ApiClient::query()->create([ + $client = ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Special Gateway', 'slug' => 'test-' . uniqid(), @@ -105,7 +105,7 @@ describe('ToggleClientStatusCommand', function (): void { it('deactivates an active client when deactivate status is passed', function (): void { // GIVEN /** @var \Tests\TestCase $this */ - $client = ApiClient::query()->create([ + $client = ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Special Gateway', 'slug' => 'test-' . uniqid(), @@ -128,7 +128,7 @@ describe('ToggleClientStatusCommand', function (): void { // GIVEN /** @var \Tests\TestCase $this */ $identifier = 'arcadia_id_' . str_repeat('z', 32); - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Some Gateway', 'slug' => 'test-' . uniqid(), @@ -148,7 +148,7 @@ describe('ToggleClientStatusCommand', function (): void { // GIVEN /** @var \Tests\TestCase $this */ $identifier = 'arcadia_id_' . str_repeat('k', 32); - $client = ApiClient::query()->create([ + $client = ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Interactive Gateway', 'slug' => 'interactive-gateway', @@ -176,7 +176,7 @@ describe('ToggleClientStatusCommand', function (): void { /** @var \Tests\TestCase $this */ ApiClient::query()->delete(); - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Production Gateway', 'slug' => 'test-' . uniqid(), @@ -185,7 +185,7 @@ describe('ToggleClientStatusCommand', function (): void { 'is_active' => true, ]); - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => (string) Uuid::uuid7(), 'name' => 'Backup Gateway', 'slug' => 'test-' . uniqid(), diff --git a/tests/Integration/Infra/Adapters/Repositories/ApiClientRepositoryTest.php b/tests/Integration/Infra/Adapters/Repositories/ApiClientRepositoryTest.php index 9b23e68..93cf883 100644 --- a/tests/Integration/Infra/Adapters/Repositories/ApiClientRepositoryTest.php +++ b/tests/Integration/Infra/Adapters/Repositories/ApiClientRepositoryTest.php @@ -64,7 +64,7 @@ describe('ApiClientRepository Integration Tests', function (): void { $oldSecret = 'arcadia_sec_' . str_repeat('1', 86); $newSecret = 'arcadia_sec_' . str_repeat('2', 86); - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => $rawId, 'name' => 'Initial Client', 'slug' => 'initial-client', @@ -102,7 +102,7 @@ describe('ApiClientRepository Integration Tests', function (): void { $identifier = 'arcadia_id_' . str_repeat('a', 32); $secret = 'arcadia_sec_' . str_repeat('b', 86); - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => $rawId, 'name' => 'Existing Client', 'slug' => 'existing-client', @@ -130,7 +130,7 @@ describe('ApiClientRepository Integration Tests', function (): void { $identifier = 'arcadia_id_' . str_repeat('a', 32); $secret = 'arcadia_sec_' . str_repeat('b', 86); - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => $rawId, 'name' => 'Searchable Client', 'slug' => 'searchable-client', @@ -158,7 +158,7 @@ describe('ApiClientRepository Integration Tests', function (): void { $identifier = 'arcadia_id_' . str_repeat('a', 32); $secret = 'arcadia_sec_' . str_repeat('b', 86); - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => $rawId, 'name' => 'Client to Delete', 'slug' => 'client-to-delete', @@ -209,7 +209,7 @@ describe('ApiClientRepository Integration Tests', function (): void { $repository = new ApiClientRepository(); for ($i = 1; $i <= 5; $i++) { - ApiClient::query()->create([ + ApiClient::factory()->create([ 'id' => Uuid::uuid7()->toString(), 'name' => "Client $i", 'slug' => "client-$i",