Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Api][Checkout][Order] Add tests for accessing order right after completing checkout #11715

Merged
merged 1 commit into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ Feature: Accessing order right after completing checkout

Background:
Given the store operates on a single channel in "United States"
And there is a user "[email protected]" identified by "password123"
And the store allows paying "Cash on delivery"
And the store has a product "PHP T-Shirt" priced at "$19.99"
And the store allows paying "Cash on delivery"
And the store ships everywhere for free
And there is a user "[email protected]"
And I am logged in as "[email protected]"

@ui
@ui @api
Scenario: Being able to access my order right after completing checkout
Given I added product "PHP T-Shirt" to the cart
And I have proceeded selecting "Cash on delivery" payment method
And I specified the billing address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
And I proceeded with "Free" shipping method and "Cash on delivery" payment
When I confirm my order
Then I should be able to access this order's details
6 changes: 6 additions & 0 deletions src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function iProceededWithShippingMethod(ShippingMethodInterface $shippingMe

/**
* @When I proceed with :shippingMethod shipping method and :paymentMethod payment
* @Given I proceeded with :shippingMethod shipping method and :paymentMethod payment
*/
public function iProceedOrderWithShippingMethodAndPayment(
ShippingMethodInterface $shippingMethod,
Expand Down Expand Up @@ -192,6 +193,11 @@ public function iConfirmMyOrder(): void
'notes' => $notes,
], \JSON_THROW_ON_ERROR)
);

$this->sharedStorage->set(
'order_number',
$this->responseChecker->getValue($this->client->getResponse(), 'number')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the number not null here? I guess that it should be because the order number is assigned after checkout

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number is already available here:
Screenshot 2020-08-04 at 14 44 26

);
}

/**
Expand Down
62 changes: 62 additions & 0 deletions src/Sylius/Behat/Context/Api/Shop/OrderContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Behat\Context\Api\Shop;

use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\OrderCheckoutStates;
use Symfony\Component\HttpFoundation\Response;
use Webmozart\Assert\Assert;

final class OrderContext implements Context
{
/** @var ApiClientInterface */
private $client;

/** @var ResponseCheckerInterface */
private $responseChecker;

/** @var SharedStorageInterface */
private $sharedStorage;

public function __construct(
ApiClientInterface $client,
ResponseCheckerInterface $responseChecker,
SharedStorageInterface $sharedStorage
) {
$this->client = $client;
$this->responseChecker = $responseChecker;
$this->sharedStorage = $sharedStorage;
}

/**
* @Then I should be able to access this order's details
*/
public function iShouldBeAbleToAccessThisOrderDetails(): void
{
$response = $this->client->show($this->sharedStorage->get('cart_token'));

Assert::same($response->getStatusCode(), Response::HTTP_OK);
Assert::same(
$this->responseChecker->getValue($this->client->getLastResponse(), 'checkoutState'),
OrderCheckoutStates::STATE_COMPLETED
);
Assert::same(
$this->sharedStorage->get('order_number'),
$this->responseChecker->getValue($this->client->getLastResponse(), 'number')
);
}
}
1 change: 1 addition & 0 deletions src/Sylius/Behat/Context/Ui/Shop/CheckoutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function iProceedSelectingPaymentMethod($paymentMethodName)

/**
* @Given I have proceeded order with :shippingMethodName shipping method and :paymentMethodName payment
* @Given I proceeded with :shippingMethodName shipping method and :paymentMethodName payment
* @When I proceed with :shippingMethodName shipping method and :paymentMethodName payment
*/
public function iProceedOrderWithShippingMethodAndPayment($shippingMethodName, $paymentMethodName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,11 @@
<service id="sylius.behat.context.api.shop.registration" class="Sylius\Behat\Context\Api\Shop\RegistrationContext">
<argument type="service" id="test.client" />
</service>

<service id="sylius.behat.context.api.shop.order" class="Sylius\Behat\Context\Api\Shop\OrderContext">
<argument type="service" id="sylius.behat.api_platform_client.order" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="sylius.behat.shared_storage" />
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ default:
- 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.admin.managing_orders
- sylius.behat.context.api.shop.checkout
- sylius.behat.context.api.shop.login
- sylius.behat.context.api.shop.order

filters:
tags: "@checkout && @api"