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(UuidHelper::v7()), 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(UuidHelper::v7()), '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( new ShopperId(UuidHelper::v7()), 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(UuidHelper::v7()), '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(UuidHelper::v7()), 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(UuidHelper::v7()), '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(UuidHelper::v7()), 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(UuidHelper::v7()), '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(UuidHelper::v7()); $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(UuidHelper::v7()); $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(UuidHelper::v7()), '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(UuidHelper::v7()); $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(UuidHelper::v7()); $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(); }); });