ldc-cocotte/tests/Integration/WithApp/Directories/EloquentEmployeeDirectoryTest.php
Jérémy Munsch 3b3997d547
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees)
- Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue)
- Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts
- Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs
- Remove legacy and dead CSV employee import/export code
- Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation
- Add comprehensive Pest unit, integration, and feature test coverage
2026-10-27 09:58:44 +01:00

213 lines
7.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Directories\EloquentEmployeeDirectory;
use App\Models\Customer;
use App\Models\Employee;
use Carbon\CarbonImmutable;
use Domain\Models\ValueObjects\Code;
use Domain\Models\ValueObjects\Email;
use Domain\Models\ValueObjects\Matricule;
use Ramsey\Uuid\Uuid;
describe('EloquentEmployeeDirectory', function () {
it('finds an employee by id', function () {
// GIVEN
$directory = new EloquentEmployeeDirectory();
$employee = Employee::forceCreate([
'id' => 100,
'customer_id' => null,
'matricule' => new Matricule('1000100'),
'code' => new Code('C1111115'),
'nom' => 'Doe',
'prenom' => 'John',
'etablissement' => 'ETAB',
'site' => 'SITE',
'service' => '101',
'created_at' => CarbonImmutable::now(),
'updated_at' => CarbonImmutable::now(),
]);
// WHEN
$result = $directory->find(100);
// THEN
expect($result)->not->toBeNull();
expect($result->id)->toBe($employee->id);
});
it('returns null if employee not found', function () {
// GIVEN
$directory = new EloquentEmployeeDirectory();
// WHEN
$result = $directory->find(9999);
// THEN
expect($result)->toBeNull();
});
it('gets the number of salaries in date range', function () {
// GIVEN
$directory = new EloquentEmployeeDirectory();
Employee::forceCreate([
'id' => 101,
'customer_id' => null,
'matricule' => new Matricule('1000101'),
'code' => new Code('C1111116'),
'nom' => 'Doe',
'prenom' => 'John',
'etablissement' => 'ETAB',
'site' => 'SITE',
'service' => '101',
'created_at' => CarbonImmutable::now()->subDays(5),
'updated_at' => CarbonImmutable::now()->subDays(5),
]);
Employee::forceCreate([
'id' => 102,
'customer_id' => null,
'matricule' => new Matricule('1000102'),
'code' => new Code('C1111117'),
'nom' => 'Doe',
'prenom' => 'John',
'etablissement' => 'ETAB',
'site' => 'SITE',
'service' => '101',
'created_at' => CarbonImmutable::now()->subDays(15),
'updated_at' => CarbonImmutable::now()->subDays(15),
]);
// WHEN
$start = CarbonImmutable::now()->subDays(10);
$end = CarbonImmutable::now();
$count = $directory->countActiveEmployeesWithin($start, $end);
// THEN
expect($count)->toBeGreaterThanOrEqual(1);
});
it('gets the number of registered active salaries in date range', function () {
// GIVEN
$directory = new EloquentEmployeeDirectory();
$customer1 = Customer::forceCreate([
'id' => Uuid::uuid7()->toString(),
'hashcode' => Uuid::uuid4()->toString(),
'email' => new Email('test1_emp@example.com'),
'created_at' => CarbonImmutable::now()->subDays(5),
]);
Employee::forceCreate([
'id' => 103,
'customer_id' => $customer1->id,
'matricule' => new Matricule('1000103'),
'code' => new Code('C1111118'),
'nom' => 'Doe',
'prenom' => 'John',
'etablissement' => 'ETAB',
'site' => 'SITE',
'service' => '101',
'created_at' => CarbonImmutable::now()->subDays(5),
'updated_at' => CarbonImmutable::now()->subDays(5),
]);
$customer2 = Customer::forceCreate([
'id' => Uuid::uuid7()->toString(),
'hashcode' => Uuid::uuid4()->toString(),
'email' => new Email('test2_emp@example.com'),
'created_at' => CarbonImmutable::now()->subDays(15),
]);
Employee::forceCreate([
'id' => 104,
'customer_id' => $customer2->id,
'matricule' => new Matricule('1000104'),
'code' => new Code('C1111119'),
'nom' => 'Doe',
'prenom' => 'John',
'etablissement' => 'ETAB',
'site' => 'SITE',
'service' => '101',
'created_at' => CarbonImmutable::now()->subDays(15),
'updated_at' => CarbonImmutable::now()->subDays(15),
]);
// Customer without employee
Customer::forceCreate([
'id' => Uuid::uuid7()->toString(),
'hashcode' => Uuid::uuid4()->toString(),
'email' => new Email('test3_emp@example.com'),
'created_at' => CarbonImmutable::now()->subDays(5),
]);
// WHEN
$start = CarbonImmutable::now()->subDays(10);
$end = CarbonImmutable::now();
$count = $directory->countActiveRegisteredEmployeesWithin($start, $end);
// THEN
expect($count)->toBeGreaterThanOrEqual(1);
});
it('gets total registered active salaries', function () {
// GIVEN
$directory = new EloquentEmployeeDirectory();
$customer1 = Customer::forceCreate([
'id' => Uuid::uuid7()->toString(),
'hashcode' => Uuid::uuid4()->toString(),
'email' => new Email('test1t_emp@example.com'),
]);
Employee::forceCreate([
'id' => 105,
'customer_id' => $customer1->id,
'matricule' => new Matricule('1000105'),
'code' => new Code('C111111A'),
'nom' => 'Doe',
'prenom' => 'John',
'etablissement' => 'ETAB',
'site' => 'SITE',
'service' => '101',
'created_at' => CarbonImmutable::now(),
'updated_at' => CarbonImmutable::now(),
]);
$customer2 = Customer::forceCreate([
'id' => Uuid::uuid7()->toString(),
'hashcode' => Uuid::uuid4()->toString(),
'email' => new Email('test2t_emp@example.com'),
]);
// no employee for customer2
// WHEN
$count = $directory->countActiveRegisteredEmployees();
// THEN
expect($count)->toBeGreaterThanOrEqual(1);
});
it('gets total active employees', function () {
// GIVEN
$directory = new EloquentEmployeeDirectory();
Employee::forceCreate([
'id' => 106,
'customer_id' => null,
'matricule' => new Matricule('1000106'),
'code' => new Code('C1111121'),
'nom' => 'Doe',
'prenom' => 'John',
'etablissement' => 'ETAB',
'site' => 'SITE',
'service' => '101',
'created_at' => CarbonImmutable::now(),
'updated_at' => CarbonImmutable::now(),
]);
// WHEN
$count = $directory->countActiveEmployees();
// THEN
expect($count)->toBeGreaterThanOrEqual(1);
});
});