ldc-boutique-cnc-sable/tests/Unit/App/Casts/OrderEmployeeCastTest.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

123 lines
3.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Casts\OrderEmployeeCast;
use Domain\Models\ValueObjects\Matricule;
use Domain\Models\ValueObjects\OrderEmployee;
use Illuminate\Database\Eloquent\Model;
it('gets null when value is null', function () {
// GIVEN
$cast = new OrderEmployeeCast();
$model = \Mockery::mock(Model::class);
// WHEN
$employee = $cast->get($model, 'employee', null, []);
// THEN
expect($employee)->toBeNull();
});
it('throws exception when getting invalid value type', function () {
// GIVEN
$cast = new OrderEmployeeCast();
$model = \Mockery::mock(Model::class);
// WHEN
$cast->get($model, 'employee', 123, []);
// THEN
})->throws(
\InvalidArgumentException::class,
'The value must be a string.'
);
use Domain\Models\ValueObjects\ShopperEstablishmentCode;
use Domain\Models\ValueObjects\ShopperServiceCode;
use Domain\Models\ValueObjects\ShopperSiteCode;
it('gets an order employee from json string', function () {
// GIVEN
$cast = new OrderEmployeeCast();
$model = \Mockery::mock(Model::class);
$json = json_encode([
'matricule' => '1234567',
'firstname' => 'John',
'lastname' => 'Doe',
'facility' => 'FAC01',
'site' => 'SITE',
'service' => '101',
]);
// WHEN
$employee = $cast->get($model, 'employee', $json, []);
// THEN
expect($employee)->toBeInstanceOf(OrderEmployee::class)
->and($employee->matricule)->toBeInstanceOf(Matricule::class)
->and($employee->matricule->value)->toBe('1234567')
->and($employee->firstname)->toBe('John')
->and($employee->lastname)->toBe('Doe')
->and($employee->facility)->toBeInstanceOf(ShopperEstablishmentCode::class)
->and($employee->facility->value)->toBe('FAC01')
->and($employee->site)->toBeInstanceOf(ShopperSiteCode::class)
->and($employee->site->value)->toBe('SITE')
->and($employee->service)->toBeInstanceOf(ShopperServiceCode::class)
->and($employee->service->value)->toBe('101');
});
it('sets null when value is null', function () {
// GIVEN
$cast = new OrderEmployeeCast();
$model = \Mockery::mock(Model::class);
// WHEN
$value = $cast->set($model, 'employee', null, []);
// THEN
expect($value)->toBeNull();
});
it('throws exception when setting invalid type', function () {
// GIVEN
$cast = new OrderEmployeeCast();
$model = \Mockery::mock(Model::class);
// WHEN
$cast->set($model, 'employee', 'invalid', []);
// THEN
})->throws(
\InvalidArgumentException::class,
'The given value is not an instance of OrderEmployee.'
);
it('sets an order employee', function () {
// GIVEN
$cast = new OrderEmployeeCast();
$model = \Mockery::mock(Model::class);
$employee = new OrderEmployee(
matricule: new Matricule('1234567'),
firstname: 'John',
lastname: 'Doe',
facility: new ShopperEstablishmentCode('FAC01'),
site: new ShopperSiteCode('SITE'),
service: new ShopperServiceCode('101')
);
// WHEN
$value = $cast->set($model, 'employee', $employee, []);
// THEN
expect($value)->toBeJson()
->and(json_decode($value, true))->toMatchArray([
'matricule' => '1234567',
'firstname' => 'John',
'lastname' => 'Doe',
'facility' => 'FAC01',
'site' => 'SITE',
'service' => '101',
]);
});