shouldReceive('check')->once()->andReturn(true); $request = new ConfirmOrderRequest($authService); // WHEN $request->initialize(); // THEN expect($request->authorize())->toBeTrue(); }); it('does not authorize when user is not logged in', function () { // GIVEN $authService = \Mockery::mock(AppCustomerAuthService::class); $authService->shouldReceive('check')->once()->andReturn(false); $request = new ConfirmOrderRequest($authService); // WHEN $request->initialize(); // THEN expect($request->authorize())->toBeFalse(); }); it('has required rules for cgv acceptance', function () { // GIVEN $authService = \Mockery::mock(AppCustomerAuthService::class); $request = new ConfirmOrderRequest($authService); // WHEN $rules = $request->rules(); // THEN expect($rules)->toHaveKey('ok_cgv') ->and($rules['ok_cgv'])->toContain('accepted'); }); it('maps to PlacePendingOrderInput', function () { // GIVEN $shopperId = new ShopperId(Uuid::uuid7()); $customer = \Mockery::mock(Customer::class); $customer->shouldReceive('getId')->once()->andReturn($shopperId); $authService = \Mockery::mock(AppCustomerAuthService::class); $authService->shouldReceive('getCustomerAsMandatory')->once()->andReturn($customer); $request = new ConfirmOrderRequest($authService); $request->initialize(); // WHEN $input = $request->toPlacePendingOrderInput(); // THEN expect($input)->toBeInstanceOf(PlacePendingOrderInput::class) ->and($input->shopperId)->toBe($shopperId); }); });