- 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
278 lines
9.6 KiB
PHP
278 lines
9.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Services;
|
|
|
|
use Carbon\CarbonImmutable;
|
|
use Domain\Models\Entities\Shop;
|
|
use Domain\Models\Entities\Shopper;
|
|
use Domain\Models\ValueObjects\Email;
|
|
use Domain\Models\ValueObjects\Entities\ShopId;
|
|
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 Domain\Ports\Repositories\ShopperRepository;
|
|
use Domain\Ports\Repositories\ShopRepository;
|
|
use Domain\Services\ShopperService;
|
|
use Mockery;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
describe('ShopperService', function (): void {
|
|
|
|
it('gets shopper for id', function (): void {
|
|
// GIVEN
|
|
$shopRepo = Mockery::mock(ShopRepository::class);
|
|
$shopperRepo = Mockery::mock(ShopperRepository::class);
|
|
$service = new ShopperService($shopRepo, $shopperRepo);
|
|
|
|
$id = new ShopperId(Uuid::uuid7());
|
|
$shopper = new Shopper(
|
|
$id,
|
|
new Email('test@test.com'),
|
|
new Matricule('1234567'),
|
|
'Nom',
|
|
'Prenom',
|
|
CarbonImmutable::now()->subDay(),
|
|
null,
|
|
new ShopperEstablishmentCode('ETAB01'),
|
|
new ShopperSiteCode('SITEA'),
|
|
new ShopperServiceCode('101')
|
|
);
|
|
$shopperRepo->shouldReceive('find')->once()->with($id)->andReturn($shopper);
|
|
|
|
// WHEN
|
|
$result = $service->getShopperFor($id);
|
|
|
|
// THEN
|
|
expect($result)->toBe($shopper);
|
|
});
|
|
|
|
it('resolves shop for employee based on exception shop', function (): void {
|
|
// GIVEN
|
|
$shopRepo = Mockery::mock(ShopRepository::class);
|
|
$shopperRepo = Mockery::mock(ShopperRepository::class);
|
|
$service = new ShopperService($shopRepo, $shopperRepo);
|
|
|
|
$shopper = new Shopper(
|
|
new ShopperId(Uuid::uuid7()),
|
|
new Email('test@test.com'),
|
|
new Matricule('1234567'),
|
|
'Nom',
|
|
'Prenom',
|
|
CarbonImmutable::now()->subDay(),
|
|
null,
|
|
new ShopperEstablishmentCode('ETAB01'),
|
|
new ShopperSiteCode('SITEA'),
|
|
new ShopperServiceCode('101')
|
|
);
|
|
|
|
$shop = new Shop(
|
|
new ShopId(Uuid::uuid7()),
|
|
'Shop',
|
|
'Addr',
|
|
'00000',
|
|
'City'
|
|
);
|
|
$shopRepo->shouldReceive('findExceptionShopFor')->once()->with($shopper->matricule)->andReturn($shop);
|
|
|
|
// WHEN
|
|
$result = $service->resolveShopForEmployee($shopper);
|
|
|
|
// THEN
|
|
expect($result)->toBe($shop);
|
|
});
|
|
|
|
it('resolves shop for employee based on site and service', function (): void {
|
|
// GIVEN
|
|
$shopRepo = Mockery::mock(ShopRepository::class);
|
|
$shopperRepo = Mockery::mock(ShopperRepository::class);
|
|
$service = new ShopperService($shopRepo, $shopperRepo);
|
|
|
|
$shopper = new Shopper(
|
|
isset($id) ? $id : new ShopperId(Uuid::uuid7()),
|
|
new Email('test@test.com'),
|
|
new Matricule('1234567'),
|
|
'Nom',
|
|
'Prenom',
|
|
CarbonImmutable::now()->subDay(),
|
|
null,
|
|
new ShopperEstablishmentCode('ETAB01'),
|
|
new ShopperSiteCode('SITEA'),
|
|
new ShopperServiceCode('101')
|
|
);
|
|
|
|
$shop = new Shop(new ShopId(Uuid::uuid7()), 'Shop', 'Addr', '00000', 'City');
|
|
$shopRepo->shouldReceive('findExceptionShopFor')->once()->with($shopper->matricule)->andReturn(null);
|
|
$shopRepo->shouldReceive('findShopForSiteAndService')->once()->with($shopper->site, $shopper->service)->andReturn($shop);
|
|
|
|
// WHEN
|
|
$result = $service->resolveShopForEmployee($shopper);
|
|
|
|
// THEN
|
|
expect($result)->toBe($shop);
|
|
});
|
|
|
|
it('resolves shop for employee based on site only', function (): void {
|
|
// GIVEN
|
|
$shopRepo = Mockery::mock(ShopRepository::class);
|
|
$shopperRepo = Mockery::mock(ShopperRepository::class);
|
|
$service = new ShopperService($shopRepo, $shopperRepo);
|
|
|
|
$shopper = new Shopper(
|
|
new ShopperId(Uuid::uuid7()),
|
|
new Email('test@test.com'),
|
|
new Matricule('1234567'),
|
|
'Nom',
|
|
'Prenom',
|
|
CarbonImmutable::now()->subDay(),
|
|
null,
|
|
new ShopperEstablishmentCode('ETAB01'),
|
|
new ShopperSiteCode('SITEA'),
|
|
new ShopperServiceCode('101')
|
|
);
|
|
|
|
$shop = new Shop(new ShopId(Uuid::uuid7()), 'Shop', 'Addr', '00000', 'City');
|
|
$shopRepo->shouldReceive('findExceptionShopFor')->once()->with($shopper->matricule)->andReturn(null);
|
|
$shopRepo->shouldReceive('findShopForSiteAndService')->once()->with($shopper->site, $shopper->service)->andReturn(null);
|
|
$shopRepo->shouldReceive('findShopForSiteAndService')->once()->with($shopper->site, null)->andReturn($shop);
|
|
|
|
// WHEN
|
|
$result = $service->resolveShopForEmployee($shopper);
|
|
|
|
// THEN
|
|
expect($result)->toBe($shop);
|
|
});
|
|
|
|
it('resolves shop for employee using default fallback', function (): void {
|
|
// GIVEN
|
|
$shopRepo = Mockery::mock(ShopRepository::class);
|
|
$shopperRepo = Mockery::mock(ShopperRepository::class);
|
|
$service = new ShopperService($shopRepo, $shopperRepo);
|
|
|
|
$shopper = new Shopper(
|
|
new ShopperId(Uuid::uuid7()),
|
|
new Email('test@test.com'),
|
|
new Matricule('1234567'),
|
|
'Nom',
|
|
'Prenom',
|
|
CarbonImmutable::now()->subDay(),
|
|
null,
|
|
new ShopperEstablishmentCode('ETAB01'),
|
|
new ShopperSiteCode('SITEA'),
|
|
new ShopperServiceCode('101')
|
|
);
|
|
|
|
$shop = new Shop(new ShopId(Uuid::uuid7()), 'Shop', 'Addr', '00000', 'City');
|
|
$shopRepo->shouldReceive('findExceptionShopFor')->once()->with($shopper->matricule)->andReturn(null);
|
|
$shopRepo->shouldReceive('findShopForSiteAndService')->once()->with($shopper->site, $shopper->service)->andReturn(null);
|
|
$shopRepo->shouldReceive('findShopForSiteAndService')->once()->with($shopper->site, null)->andReturn(null);
|
|
$shopRepo->shouldReceive('getDefaultShop')->once()->andReturn($shop);
|
|
|
|
// WHEN
|
|
$result = $service->resolveShopForEmployee($shopper);
|
|
|
|
// THEN
|
|
expect($result)->toBe($shop);
|
|
});
|
|
|
|
it('returns null when shopper is not found for id', function (): void {
|
|
// GIVEN
|
|
$shopRepo = Mockery::mock(ShopRepository::class);
|
|
$shopperRepo = Mockery::mock(ShopperRepository::class);
|
|
$service = new ShopperService($shopRepo, $shopperRepo);
|
|
|
|
$id = new ShopperId(Uuid::uuid7());
|
|
$shopperRepo->shouldReceive('find')->once()->with($id)->andReturn(null);
|
|
|
|
// WHEN
|
|
$result = $service->getShopFor($id);
|
|
|
|
// THEN
|
|
expect($result)->toBeNull();
|
|
});
|
|
|
|
it('gets shop when shopper is found for id', function (): void {
|
|
// GIVEN
|
|
$shopRepo = Mockery::mock(ShopRepository::class);
|
|
$shopperRepo = Mockery::mock(ShopperRepository::class);
|
|
$service = new ShopperService($shopRepo, $shopperRepo);
|
|
|
|
$id = new ShopperId(Uuid::uuid7());
|
|
$shopper = new Shopper(
|
|
$id,
|
|
new Email('test@test.com'),
|
|
new Matricule('1234567'),
|
|
'Nom',
|
|
'Prenom',
|
|
CarbonImmutable::now()->subDay(),
|
|
null,
|
|
new ShopperEstablishmentCode('ETAB01'),
|
|
new ShopperSiteCode('SITEA'),
|
|
new ShopperServiceCode('101')
|
|
);
|
|
|
|
$shop = new Shop(
|
|
new ShopId(Uuid::uuid7()),
|
|
'Shop',
|
|
'Addr',
|
|
'00000',
|
|
'City'
|
|
);
|
|
$shopperRepo->shouldReceive('find')->once()->with($id)->andReturn($shopper);
|
|
$shopRepo->shouldReceive('findExceptionShopFor')->once()->with($shopper->matricule)->andReturn($shop);
|
|
|
|
// WHEN
|
|
$result = $service->getShopFor($id);
|
|
|
|
// THEN
|
|
expect($result)->toBe($shop);
|
|
});
|
|
|
|
it('returns false when customer not found checking app pass orders', function (): void {
|
|
// GIVEN
|
|
$shopRepo = Mockery::mock(ShopRepository::class);
|
|
$shopperRepo = Mockery::mock(ShopperRepository::class);
|
|
$service = new ShopperService($shopRepo, $shopperRepo);
|
|
|
|
$id = new ShopperId(Uuid::uuid7());
|
|
$shopperRepo->shouldReceive('find')->once()->with($id)->andReturn(null);
|
|
|
|
// WHEN
|
|
$result = $service->canCustomerPassOrdersApp($id);
|
|
|
|
// THEN
|
|
expect($result)->toBeFalse();
|
|
});
|
|
|
|
it('returns customer active status for pass orders app', function (): void {
|
|
// GIVEN
|
|
$shopRepo = Mockery::mock(ShopRepository::class);
|
|
$shopperRepo = Mockery::mock(ShopperRepository::class);
|
|
$service = new ShopperService($shopRepo, $shopperRepo);
|
|
|
|
$id = new ShopperId(Uuid::uuid7());
|
|
$shopper = new Shopper(
|
|
$id,
|
|
new Email('test@test.com'),
|
|
new Matricule('1234567'),
|
|
'Nom',
|
|
'Prenom',
|
|
CarbonImmutable::now()->subDay(),
|
|
null,
|
|
new ShopperEstablishmentCode('ETAB01'),
|
|
new ShopperSiteCode('SITEA'),
|
|
new ShopperServiceCode('101')
|
|
);
|
|
|
|
$shopperRepo->shouldReceive('find')->once()->with($id)->andReturn($shopper);
|
|
|
|
// WHEN
|
|
$result = $service->canCustomerPassOrdersApp($id);
|
|
|
|
// THEN
|
|
expect($result)->toBeTrue();
|
|
});
|
|
});
|