fix(infra): align since filter in InMemoryEmployeeDirectory with Eloquent adapter (LSP)
This commit is contained in:
parent
ed7ce3ec32
commit
98356465d5
2 changed files with 68 additions and 2 deletions
|
|
@ -91,8 +91,12 @@ final class InMemoryEmployeeDirectory implements EmployeeDirectory
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($filter->since !== null && $employee->startDate < $filter->since) {
|
||||
return false;
|
||||
if ($filter->since !== null) {
|
||||
$createdAtMatches = $employee->createdAt >= $filter->since;
|
||||
$updatedAtMatches = $employee->updatedAt !== null && $employee->updatedAt >= $filter->since;
|
||||
if (! $createdAtMatches && ! $updatedAtMatches) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -94,6 +94,68 @@ describe('InMemoryEmployeeDirectory Unit Tests', function (): void {
|
|||
->and($result->getItems()[0]->publicEmployeeNumber->value)->toBe('00000001');
|
||||
});
|
||||
|
||||
it('filters employees by since date comparing against createdAt and updatedAt', function (): void {
|
||||
// GIVEN
|
||||
$directory = new InMemoryEmployeeDirectory();
|
||||
|
||||
$emp1 = new Employee(
|
||||
publicEmployeeNumber: new ArcadiaEmployeeId('00000001'),
|
||||
lastName: 'ALICE',
|
||||
firstName: 'A',
|
||||
startDate: new \DateTimeImmutable('2023-01-01'),
|
||||
endDate: null,
|
||||
plannedEndDate: null,
|
||||
establishment: new EstablishmentCode('EST01'),
|
||||
site: new SiteId('SITEO'),
|
||||
service: new ServiceId('097'),
|
||||
createdAt: new \DateTimeImmutable('2024-01-01'),
|
||||
updatedAt: null,
|
||||
);
|
||||
|
||||
$emp2 = new Employee(
|
||||
publicEmployeeNumber: new ArcadiaEmployeeId('00000002'),
|
||||
lastName: 'BOB',
|
||||
firstName: 'B',
|
||||
startDate: new \DateTimeImmutable('2023-01-01'),
|
||||
endDate: null,
|
||||
plannedEndDate: null,
|
||||
establishment: new EstablishmentCode('EST01'),
|
||||
site: new SiteId('SITEO'),
|
||||
service: new ServiceId('097'),
|
||||
createdAt: new \DateTimeImmutable('2023-01-01'),
|
||||
updatedAt: new \DateTimeImmutable('2024-02-01'),
|
||||
);
|
||||
|
||||
$emp3 = new Employee(
|
||||
publicEmployeeNumber: new ArcadiaEmployeeId('00000003'),
|
||||
lastName: 'CHARLIE',
|
||||
firstName: 'C',
|
||||
startDate: new \DateTimeImmutable('2024-06-01'),
|
||||
endDate: null,
|
||||
plannedEndDate: null,
|
||||
establishment: new EstablishmentCode('EST01'),
|
||||
site: new SiteId('SITEO'),
|
||||
service: new ServiceId('097'),
|
||||
createdAt: new \DateTimeImmutable('2023-01-01'),
|
||||
updatedAt: new \DateTimeImmutable('2023-06-01'),
|
||||
);
|
||||
|
||||
$directory->add($emp1, $emp2, $emp3);
|
||||
|
||||
$pagination = Pagination::ofPage(1, 10);
|
||||
$sorter = new EmployeeSorter(EmployeeSortColumn::arcadiaId, \SortDirection::Ascending);
|
||||
$filter = new EmployeeFilter(since: new \DateTimeImmutable('2024-01-01'));
|
||||
|
||||
// WHEN
|
||||
$result = $directory->findAll($pagination, $sorter, $filter);
|
||||
|
||||
// THEN
|
||||
expect($result->getTotal())->toBe(2)
|
||||
->and($result->getItems())->toHaveCount(2)
|
||||
->and($result->getItems()[0]->publicEmployeeNumber->value)->toBe('00000001')
|
||||
->and($result->getItems()[1]->publicEmployeeNumber->value)->toBe('00000002');
|
||||
});
|
||||
|
||||
it('clears all stored employees', function (): void {
|
||||
// GIVEN
|
||||
$directory = new InMemoryEmployeeDirectory();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue