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); }); });