Skip to content

Commit

Permalink
add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
SirDomin committed Jun 23, 2021
1 parent 483fe79 commit 3cb78c1
Showing 1 changed file with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use SM\Factory\FactoryInterface;
use SM\StateMachine\StateMachineInterface;
use Sylius\Bundle\ApiBundle\Command\Checkout\ChooseShippingMethod;
use Sylius\Bundle\ApiBundle\Exception\OrderCannotBeShippedWithoutAddressing;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\ShipmentInterface;
use Sylius\Component\Core\Model\ShippingMethodInterface;
Expand Down Expand Up @@ -55,7 +57,8 @@ function it_assigns_choosen_shipping_method_to_specified_shipment(
OrderInterface $cart,
ShippingMethodInterface $shippingMethod,
ShipmentInterface $shipment,
StateMachineInterface $stateMachine
StateMachineInterface $stateMachine,
AddressInterface $shippingAddress
): void {
$chooseShippingMethod = new ChooseShippingMethod('DHL_SHIPPING_METHOD');
$chooseShippingMethod->setOrderTokenValue('ORDERTOKEN');
Expand All @@ -68,6 +71,8 @@ function it_assigns_choosen_shipping_method_to_specified_shipment(

$shippingMethodRepository->findOneBy(['code' => 'DHL_SHIPPING_METHOD'])->willReturn($shippingMethod);

$cart->getShippingAddress()->willReturn($shippingAddress);

$cart->getShipments()->willReturn(new ArrayCollection([$shipment->getWrappedObject()]));

$cart->getId()->willReturn('111');
Expand All @@ -91,7 +96,8 @@ function it_throws_an_exception_if_shipping_method_is_not_eligible(
OrderInterface $cart,
ShippingMethodInterface $shippingMethod,
ShipmentInterface $shipment,
StateMachineInterface $stateMachine
StateMachineInterface $stateMachine,
AddressInterface $shippingAddress
): void {
$chooseShippingMethod = new ChooseShippingMethod('DHL_SHIPPING_METHOD');
$chooseShippingMethod->setOrderTokenValue('ORDERTOKEN');
Expand All @@ -104,6 +110,8 @@ function it_throws_an_exception_if_shipping_method_is_not_eligible(

$shippingMethodRepository->findOneBy(['code' => 'DHL_SHIPPING_METHOD'])->willReturn($shippingMethod);

$cart->getShippingAddress()->willReturn($shippingAddress);

$cart->getShipments()->willReturn(new ArrayCollection([$shipment->getWrappedObject()]));

$cart->getId()->willReturn('111');
Expand Down Expand Up @@ -144,13 +152,17 @@ function it_throws_an_exception_if_order_cannot_have_shipping_selected(
FactoryInterface $stateMachineFactory,
OrderInterface $cart,
StateMachineInterface $stateMachine,
ShipmentInterface $shipment
ShipmentInterface $shipment,
AddressInterface $shippingAddress
): void {
$chooseShippingMethod = new ChooseShippingMethod('DHL_SHIPPING_METHOD');
$chooseShippingMethod->setOrderTokenValue('ORDERTOKEN');

$orderRepository->findOneBy(['tokenValue' => 'ORDERTOKEN'])->willReturn($cart);
$shippingMethodRepository->findOneBy(['code' => 'DHL_SHIPPING_METHOD'])->willReturn(null);

$cart->getShippingAddress()->willReturn($shippingAddress);

$stateMachineFactory->get($cart, OrderCheckoutTransitions::GRAPH)->willReturn($stateMachine);
$stateMachine->can('select_shipping')->willReturn(false);

Expand All @@ -169,14 +181,17 @@ function it_throws_an_exception_if_shipping_method_with_given_code_has_not_been_
FactoryInterface $stateMachineFactory,
OrderInterface $cart,
StateMachineInterface $stateMachine,
ShipmentInterface $shipment
ShipmentInterface $shipment,
AddressInterface $shippingAddress
): void {
$chooseShippingMethod = new ChooseShippingMethod('DHL_SHIPPING_METHOD');
$chooseShippingMethod->setOrderTokenValue('ORDERTOKEN');
$chooseShippingMethod->setSubresourceId('123');

$orderRepository->findOneBy(['tokenValue' => 'ORDERTOKEN'])->willReturn($cart);

$cart->getShippingAddress()->willReturn($shippingAddress);

$stateMachineFactory->get($cart, OrderCheckoutTransitions::GRAPH)->willReturn($stateMachine);
$stateMachine->can('select_shipping')->willReturn(true);

Expand All @@ -198,7 +213,8 @@ function it_throws_an_exception_if_ordered_shipment_has_not_been_found(
FactoryInterface $stateMachineFactory,
OrderInterface $cart,
ShippingMethodInterface $shippingMethod,
StateMachineInterface $stateMachine
StateMachineInterface $stateMachine,
AddressInterface $shippingAddress
): void {
$chooseShippingMethod = new ChooseShippingMethod('DHL_SHIPPING_METHOD');
$chooseShippingMethod->setOrderTokenValue('ORDERTOKEN');
Expand All @@ -211,6 +227,8 @@ function it_throws_an_exception_if_ordered_shipment_has_not_been_found(

$shippingMethodRepository->findOneBy(['code' => 'DHL_SHIPPING_METHOD'])->willReturn($shippingMethod);

$cart->getShippingAddress()->willReturn($shippingAddress);

$cart->getId()->willReturn('111');

$shipmentRepository->findOneByOrderId('123', '111')->willReturn(null);
Expand All @@ -222,4 +240,38 @@ function it_throws_an_exception_if_ordered_shipment_has_not_been_found(
->during('__invoke', [$chooseShippingMethod])
;
}

function it_throws_an_exception_if_cart_doesnt_have_address(
OrderRepositoryInterface $orderRepository,
ShippingMethodRepositoryInterface $shippingMethodRepository,
ShipmentRepositoryInterface $shipmentRepository,
FactoryInterface $stateMachineFactory,
OrderInterface $cart,
ShippingMethodInterface $shippingMethod,
StateMachineInterface $stateMachine
): void {
$chooseShippingMethod = new ChooseShippingMethod('DHL_SHIPPING_METHOD');
$chooseShippingMethod->setOrderTokenValue('ORDERTOKEN');
$chooseShippingMethod->setSubresourceId('123');

$orderRepository->findOneBy(['tokenValue' => 'ORDERTOKEN'])->willReturn($cart);

$stateMachineFactory->get($cart, OrderCheckoutTransitions::GRAPH)->willReturn($stateMachine);
$stateMachine->can('select_shipping')->willReturn(true);

$shippingMethodRepository->findOneBy(['code' => 'DHL_SHIPPING_METHOD'])->willReturn($shippingMethod);

$cart->getShippingAddress()->willReturn(null);

$cart->getId()->willReturn('111');

$shipmentRepository->findOneByOrderId('123', '111')->shouldNotBeCalled();

$stateMachine->apply('select_shipping')->shouldNotBeCalled();

$this
->shouldThrow(OrderCannotBeShippedWithoutAddressing::class)
->during('__invoke', [$chooseShippingMethod])
;
}
}

0 comments on commit 3cb78c1

Please sign in to comment.