210 lines
7.5 KiB
PHP
210 lines
7.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Directories\EloquentEmployeeDirectory;
|
|
use App\Models\Employee;
|
|
use Carbon\CarbonImmutable;
|
|
use Domain\Models\ValueObjects\Code;
|
|
use Domain\Models\ValueObjects\Matricule;
|
|
|
|
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' => 'E',
|
|
'site' => 'S',
|
|
'service' => 'S',
|
|
'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' => 'E',
|
|
'site' => 'S',
|
|
'service' => 'S',
|
|
'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' => 'E',
|
|
'site' => 'S',
|
|
'service' => 'S',
|
|
'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 = \App\Models\Customer::forceCreate([
|
|
'id' => \Ramsey\Uuid\Uuid::uuid7()->toString(),
|
|
'hashcode' => \Ramsey\Uuid\Uuid::uuid4()->toString(),
|
|
'email' => new \Domain\Models\ValueObjects\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' => 'E',
|
|
'site' => 'S',
|
|
'service' => 'S',
|
|
'created_at' => CarbonImmutable::now()->subDays(5),
|
|
'updated_at' => CarbonImmutable::now()->subDays(5),
|
|
]);
|
|
|
|
$customer2 = \App\Models\Customer::forceCreate([
|
|
'id' => \Ramsey\Uuid\Uuid::uuid7()->toString(),
|
|
'hashcode' => \Ramsey\Uuid\Uuid::uuid4()->toString(),
|
|
'email' => new \Domain\Models\ValueObjects\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' => 'E',
|
|
'site' => 'S',
|
|
'service' => 'S',
|
|
'created_at' => CarbonImmutable::now()->subDays(15),
|
|
'updated_at' => CarbonImmutable::now()->subDays(15),
|
|
]);
|
|
|
|
// Customer without employee
|
|
\App\Models\Customer::forceCreate([
|
|
'id' => \Ramsey\Uuid\Uuid::uuid7()->toString(),
|
|
'hashcode' => \Ramsey\Uuid\Uuid::uuid4()->toString(),
|
|
'email' => new \Domain\Models\ValueObjects\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 = \App\Models\Customer::forceCreate([
|
|
'id' => \Ramsey\Uuid\Uuid::uuid7()->toString(),
|
|
'hashcode' => \Ramsey\Uuid\Uuid::uuid4()->toString(),
|
|
'email' => new \Domain\Models\ValueObjects\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' => 'E',
|
|
'site' => 'S',
|
|
'service' => 'S',
|
|
'created_at' => CarbonImmutable::now(),
|
|
'updated_at' => CarbonImmutable::now(),
|
|
]);
|
|
|
|
$customer2 = \App\Models\Customer::forceCreate([
|
|
'id' => \Ramsey\Uuid\Uuid::uuid7()->toString(),
|
|
'hashcode' => \Ramsey\Uuid\Uuid::uuid4()->toString(),
|
|
'email' => new \Domain\Models\ValueObjects\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' => 'E',
|
|
'site' => 'S',
|
|
'service' => 'S',
|
|
'created_at' => CarbonImmutable::now(),
|
|
'updated_at' => CarbonImmutable::now(),
|
|
]);
|
|
|
|
// WHEN
|
|
$count = $directory->countActiveEmployees();
|
|
|
|
// THEN
|
|
expect($count)->toBeGreaterThanOrEqual(1);
|
|
});
|
|
});
|