- 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
138 lines
4.3 KiB
PHP
138 lines
4.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\Entities;
|
|
|
|
use Carbon\CarbonImmutable;
|
|
use Domain\Models\Entities\Shopper;
|
|
use Domain\Models\ValueObjects\Email;
|
|
use Domain\Models\ValueObjects\Entities\ShopperId;
|
|
use Domain\Models\ValueObjects\Matricule;
|
|
use Domain\Models\ValueObjects\ShopperEstablishmentCode;
|
|
use Domain\Models\ValueObjects\ShopperServiceCode;
|
|
use Domain\Models\ValueObjects\ShopperSiteCode;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
describe('Shopper', function (): void {
|
|
it('can instantiate correctly and check active status (active)', function (): void {
|
|
// GIVEN
|
|
$id = new ShopperId(Uuid::uuid7());
|
|
$email = new Email('test@example.com');
|
|
$matricule = new Matricule('1234567');
|
|
$startDate = CarbonImmutable::now()->subDay();
|
|
$endDate = null;
|
|
$etablissement = new ShopperEstablishmentCode('ETAB01');
|
|
$site = new ShopperSiteCode('SITE');
|
|
$service = new ShopperServiceCode('101');
|
|
|
|
// WHEN
|
|
$entity = new Shopper(
|
|
$id,
|
|
$email,
|
|
$matricule,
|
|
'Nom',
|
|
'Prenom',
|
|
$startDate,
|
|
$endDate,
|
|
$etablissement,
|
|
$site,
|
|
$service
|
|
);
|
|
|
|
// THEN
|
|
expect($entity->id())->toBe($id)
|
|
->and($entity->email)->toBe($email)
|
|
->and($entity->matricule)->toBe($matricule)
|
|
->and($entity->nom)->toBe('Nom')
|
|
->and($entity->prenom)->toBe('Prenom')
|
|
->and($entity->startDate)->toBe($startDate)
|
|
->and($entity->endDate)->toBeNull()
|
|
->and($entity->etablissement)->toBe($etablissement)
|
|
->and($entity->site)->toBe($site)
|
|
->and($entity->service)->toBe($service)
|
|
->and($entity->isActive())->toBeTrue();
|
|
});
|
|
|
|
it('is inactive when endDate is in the past', function (): void {
|
|
// GIVEN
|
|
$endDate = CarbonImmutable::now()->subDay();
|
|
|
|
// WHEN
|
|
$entity = new Shopper(
|
|
new ShopperId(Uuid::uuid7()),
|
|
new Email('test@example.com'),
|
|
new Matricule('1234567'),
|
|
'Nom',
|
|
'Prenom',
|
|
CarbonImmutable::now()->subDays(2),
|
|
$endDate,
|
|
new ShopperEstablishmentCode('ETAB01'),
|
|
new ShopperSiteCode('SITE'),
|
|
new ShopperServiceCode('101')
|
|
);
|
|
|
|
// THEN
|
|
expect($entity->isActive())->toBeFalse();
|
|
});
|
|
|
|
it('is active when endDate is in the future', function (): void {
|
|
// GIVEN
|
|
$endDate = CarbonImmutable::now()->addDay();
|
|
|
|
// WHEN
|
|
$entity = new Shopper(
|
|
new ShopperId(Uuid::uuid7()),
|
|
new Email('test@example.com'),
|
|
new Matricule('1234567'),
|
|
'Nom',
|
|
'Prenom',
|
|
CarbonImmutable::now()->subDays(2),
|
|
$endDate,
|
|
new ShopperEstablishmentCode('ETAB01'),
|
|
new ShopperSiteCode('SITE'),
|
|
new ShopperServiceCode('101')
|
|
);
|
|
|
|
// THEN
|
|
expect($entity->isActive())->toBeTrue();
|
|
});
|
|
|
|
it('throws exception if nom is empty', function (): void {
|
|
// WHEN
|
|
$action = fn () => new Shopper(
|
|
new ShopperId(Uuid::uuid7()),
|
|
new Email('test@example.com'),
|
|
new Matricule('1234567'),
|
|
'',
|
|
'Prenom',
|
|
CarbonImmutable::now()->subDays(2),
|
|
null,
|
|
new ShopperEstablishmentCode('ETAB01'),
|
|
new ShopperSiteCode('SITE'),
|
|
new ShopperServiceCode('101')
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'nom cannot be empty');
|
|
});
|
|
|
|
it('throws exception if prenom is empty', function (): void {
|
|
// WHEN
|
|
$action = fn () => new Shopper(
|
|
new ShopperId(Uuid::uuid7()),
|
|
new Email('test@example.com'),
|
|
new Matricule('1234567'),
|
|
'Nom',
|
|
'',
|
|
CarbonImmutable::now()->subDays(2),
|
|
null,
|
|
new ShopperEstablishmentCode('ETAB01'),
|
|
new ShopperSiteCode('SITE'),
|
|
new ShopperServiceCode('101')
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'prenom cannot be empty');
|
|
});
|
|
});
|