From 4fd36910dcab8ff9e83180ca2dfdc87f70279268 Mon Sep 17 00:00:00 2001 From: Tomanhez Date: Tue, 29 Sep 2020 13:54:07 +0200 Subject: [PATCH 1/3] Add tests --- .../viewing_order.feature | 4 +- .../Behat/Context/Api/Shop/OrderContext.php | 50 +++++++++++++++++++ .../config/suites/api/account/customer.yml | 11 ++++ .../Commands/Checkout/AddressOrder.xml | 9 ++-- ...hodHandler.xml => ChoosePaymentMethod.xml} | 0 ...odHandler.xml => ChooseShippingMethod.xml} | 0 6 files changed, 69 insertions(+), 5 deletions(-) rename src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/{ChoosePaymentMethodHandler.xml => ChoosePaymentMethod.xml} (100%) rename src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/{ChooseShippingMethodHandler.xml => ChooseShippingMethod.xml} (100%) diff --git a/features/account/customer_account/viewing_orders_history/viewing_order.feature b/features/account/customer_account/viewing_orders_history/viewing_order.feature index 3019c41fc7b..c3afd1b394a 100644 --- a/features/account/customer_account/viewing_orders_history/viewing_order.feature +++ b/features/account/customer_account/viewing_orders_history/viewing_order.feature @@ -16,10 +16,10 @@ Feature: Viewing details of an order And for the billing address of "Mazikeen Lilim" in the "Pacific Coast Hwy", "90806" "Los Angeles", "United States" And I chose "Free" shipping method with "Cash on Delivery" payment - @ui + @ui @api Scenario: Viewing basic information about an order When I view the summary of the order "#00000666" - And it should has number "#00000666" + Then it should has number "#00000666" And I should see "Lucifer Morningstar", "Seaside Fwy", "90802", "Los Angeles", "United States" as shipping address And I should see "Mazikeen Lilim", "Pacific Coast Hwy", "90806", "Los Angeles", "United States" as billing address And I should see "$39.00" as order's total diff --git a/src/Sylius/Behat/Context/Api/Shop/OrderContext.php b/src/Sylius/Behat/Context/Api/Shop/OrderContext.php index 2dd35d21e62..0ebad80ab86 100644 --- a/src/Sylius/Behat/Context/Api/Shop/OrderContext.php +++ b/src/Sylius/Behat/Context/Api/Shop/OrderContext.php @@ -19,7 +19,10 @@ use Sylius\Behat\Client\ResponseCheckerInterface; use Sylius\Behat\Service\Converter\AdminToShopIriConverterInterface; use Sylius\Behat\Service\SharedStorageInterface; +use Sylius\Component\Addressing\Model\CountryInterface; use Sylius\Component\Core\Formatter\StringInflector; +use Sylius\Component\Core\Model\AddressInterface; +use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Core\Model\PromotionInterface; use Sylius\Component\Core\OrderCheckoutStates; @@ -63,6 +66,14 @@ public function __construct( $this->sharedStorage = $sharedStorage; } + /** + * @When I view the summary of the order :order + */ + public function iSeeTheOrder(OrderInterface $order): void + { + $this->client->show($order->getTokenValue()); + } + /** * @Then I should be able to access this order's details */ @@ -81,6 +92,45 @@ public function iShouldBeAbleToAccessThisOrderDetails(): void ); } + /** + * @Then it should has number :orderNumber + */ + public function itShouldHasNumber(string $orderNumber): void + { + Assert::same($this->responseChecker->getValue($this->client->getLastResponse(), 'number'), $orderNumber); + } + + /** + * @Then I should see :customerName, :street, :postcode, :city, :country as :addressType address + */ + public function iShouldSeeAsShippingAddress( + string $customerName, + string $street, + string $postcode, + string $city, + CountryInterface $country, + string $addressType + ): void { + $address = $this->responseChecker->getValue($this->client->getLastResponse(), ($addressType . 'Address')); + + $names = explode(' ', $customerName); + + Assert::same($address['firstName'], $names[0]); + Assert::same($address['lastName'], $names[1]); + Assert::same($address['street'], $street); + Assert::same($address['postcode'], $postcode); + Assert::same($address['city'], $city); + Assert::same($address['countryCode'], $country->getCode()); + } + + /** + * @Then /^I should see ("[^"]+") as order's total$/ + */ + public function iShouldSeeAsOrderSTotal(int $total): void + { + Assert::same($this->responseChecker->getValue($this->client->getLastResponse(), 'total'), $total); + } + /** * @Then :promotionName should be applied to my order * @Then :promotionName should be applied to my order shipping diff --git a/src/Sylius/Behat/Resources/config/suites/api/account/customer.yml b/src/Sylius/Behat/Resources/config/suites/api/account/customer.yml index 8a4313af8bd..ea1950b566d 100644 --- a/src/Sylius/Behat/Resources/config/suites/api/account/customer.yml +++ b/src/Sylius/Behat/Resources/config/suites/api/account/customer.yml @@ -7,17 +7,28 @@ default: contexts: - sylius.behat.context.hook.doctrine_orm + - sylius.behat.context.transform.address - sylius.behat.context.transform.country - sylius.behat.context.transform.customer + - sylius.behat.context.transform.lexical + - sylius.behat.context.transform.order + - sylius.behat.context.transform.payment + - sylius.behat.context.transform.product + - sylius.behat.context.transform.shipping_method - sylius.behat.context.transform.user - sylius.behat.context.setup.channel - sylius.behat.context.setup.currency - sylius.behat.context.setup.customer + - sylius.behat.context.setup.order + - sylius.behat.context.setup.payment + - sylius.behat.context.setup.product + - sylius.behat.context.setup.shipping - sylius.behat.context.setup.shop_api_security - sylius.behat.context.setup.user - sylius.behat.context.api.shop.account + - sylius.behat.context.api.shop.order filters: tags: "@customer_account && @api" diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/AddressOrder.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/AddressOrder.xml index d5c0f8430ec..99d64240b9c 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/AddressOrder.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/AddressOrder.xml @@ -17,13 +17,16 @@ > - cart:address + cart:address + checkout:read - cart:address + cart:address + checkout:read - cart:address + cart:address + checkout:read diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/ChoosePaymentMethodHandler.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/ChoosePaymentMethod.xml similarity index 100% rename from src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/ChoosePaymentMethodHandler.xml rename to src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/ChoosePaymentMethod.xml diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/ChooseShippingMethodHandler.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/ChooseShippingMethod.xml similarity index 100% rename from src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/ChooseShippingMethodHandler.xml rename to src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/ChooseShippingMethod.xml From fca432cb438fc396ea1234225262d72f939011b9 Mon Sep 17 00:00:00 2001 From: Tomanhez Date: Tue, 29 Sep 2020 13:54:53 +0200 Subject: [PATCH 2/3] Add shop order address api configuration --- .../config/api_resources/Address.xml | 43 +++++++++++++++++++ .../Resources/config/api_resources/Order.xml | 2 + .../config/serialization/Address.xml | 7 +++ .../Commands/Checkout/AddressOrder.xml | 3 -- .../Resources/config/serialization/Order.xml | 2 + 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Address.xml diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Address.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Address.xml new file mode 100644 index 00000000000..3fccab9f874 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Address.xml @@ -0,0 +1,43 @@ + + + + + + + + + address:read + + + + + + + + GET + /shop/address/{id} + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Order.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Order.xml index 2076484e499..c93fcb343f4 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Order.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Order.xml @@ -284,5 +284,7 @@ + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Address.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Address.xml index b8604d35729..f57c815a8e8 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Address.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Address.xml @@ -19,30 +19,37 @@ cart:address checkout:read + order:read cart:address checkout:read + order:read cart:address checkout:read + order:read cart:address checkout:read + order:read cart:address checkout:read + order:read cart:address checkout:read + order:read cart:address checkout:read + order:read diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/AddressOrder.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/AddressOrder.xml index 99d64240b9c..6a88bcbf2c5 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/AddressOrder.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Checkout/AddressOrder.xml @@ -18,15 +18,12 @@ cart:address - checkout:read cart:address - checkout:read cart:address - checkout:read diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Order.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Order.xml index 8f724eadd1a..2d921f1a0c4 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Order.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Order.xml @@ -96,10 +96,12 @@ checkout:read + order:read checkout:read + order:read From fa7069fbd5a345006522e3e9a6b7bbc97c0c6e3a Mon Sep 17 00:00:00 2001 From: Tomanhez Date: Tue, 29 Sep 2020 14:09:36 +0200 Subject: [PATCH 3/3] Fixes for tests and config --- .../viewing_order.feature | 4 +- .../Behat/Context/Api/Shop/OrderContext.php | 9 ++-- .../Behat/Context/Ui/Shop/AccountContext.php | 6 ++- .../config/api_resources/Address.xml | 43 ------------------- 4 files changed, 10 insertions(+), 52 deletions(-) delete mode 100644 src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Address.xml diff --git a/features/account/customer_account/viewing_orders_history/viewing_order.feature b/features/account/customer_account/viewing_orders_history/viewing_order.feature index c3afd1b394a..25cdcd13c2c 100644 --- a/features/account/customer_account/viewing_orders_history/viewing_order.feature +++ b/features/account/customer_account/viewing_orders_history/viewing_order.feature @@ -18,8 +18,8 @@ Feature: Viewing details of an order @ui @api Scenario: Viewing basic information about an order - When I view the summary of the order "#00000666" - Then it should has number "#00000666" + When I view the summary of my order "#00000666" + Then it should have the number "#00000666" And I should see "Lucifer Morningstar", "Seaside Fwy", "90802", "Los Angeles", "United States" as shipping address And I should see "Mazikeen Lilim", "Pacific Coast Hwy", "90806", "Los Angeles", "United States" as billing address And I should see "$39.00" as order's total diff --git a/src/Sylius/Behat/Context/Api/Shop/OrderContext.php b/src/Sylius/Behat/Context/Api/Shop/OrderContext.php index 0ebad80ab86..b5132c91ca4 100644 --- a/src/Sylius/Behat/Context/Api/Shop/OrderContext.php +++ b/src/Sylius/Behat/Context/Api/Shop/OrderContext.php @@ -21,7 +21,6 @@ use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Addressing\Model\CountryInterface; use Sylius\Component\Core\Formatter\StringInflector; -use Sylius\Component\Core\Model\AddressInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Core\Model\PromotionInterface; @@ -67,9 +66,9 @@ public function __construct( } /** - * @When I view the summary of the order :order + * @When I view the summary of my order :order */ - public function iSeeTheOrder(OrderInterface $order): void + public function iViewTheSummaryOfMyOrder(OrderInterface $order): void { $this->client->show($order->getTokenValue()); } @@ -93,9 +92,9 @@ public function iShouldBeAbleToAccessThisOrderDetails(): void } /** - * @Then it should has number :orderNumber + * @Then it should have the number :orderNumber */ - public function itShouldHasNumber(string $orderNumber): void + public function itShouldHaveTheNumber(string $orderNumber): void { Assert::same($this->responseChecker->getValue($this->client->getLastResponse(), 'number'), $orderNumber); } diff --git a/src/Sylius/Behat/Context/Ui/Shop/AccountContext.php b/src/Sylius/Behat/Context/Ui/Shop/AccountContext.php index f4c444717b6..1c11269a6e4 100644 --- a/src/Sylius/Behat/Context/Ui/Shop/AccountContext.php +++ b/src/Sylius/Behat/Context/Ui/Shop/AccountContext.php @@ -280,8 +280,9 @@ public function thisOrderShouldHaveNumber(OrderInterface $order) /** * @When I view the summary of the order :order + * @When I view the summary of my order :order */ - public function iViewTheSummaryOfTheOrder(OrderInterface $order) + public function iViewTheSummaryOfTheOrder(OrderInterface $order): void { $this->orderShowPage->open(['number' => $order->getNumber()]); } @@ -297,8 +298,9 @@ public function iViewingTheSummaryOfMyLastOrder() /** * @Then it should has number :orderNumber + * @Then it should have the number :orderNumber */ - public function itShouldHasNumber($orderNumber) + public function itShouldHasNumber(string $orderNumber): void { Assert::same($this->orderShowPage->getNumber(), $orderNumber); } diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Address.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Address.xml deleted file mode 100644 index 3fccab9f874..00000000000 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Address.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - address:read - - - - - - - - GET - /shop/address/{id} - - - - - - - - - - - - -