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

Cover Seeing payment method instructions behat API scenario #15092

Merged
merged 1 commit into from
Jun 15, 2023
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
@@ -1,5 +1,5 @@
@paying_for_order
Feature: Seeing payment method instructions on thank you page
Feature: Seeing payment method instructions after checkout
In order to know how to pay for my order
As a Customer
I want to be informed about payment instructions for chosen payment method
Expand All @@ -11,11 +11,10 @@ Feature: Seeing payment method instructions on thank you page
And the store has a payment method "Offline" with a code "OFFLINE"
And it has instructions "Account number: 0000 1111 2222 3333"

@ui
Scenario: Being informed about payment instructions on thank you page
@ui @api
Scenario: Being informed about payment instructions
Given I am a logged in customer
And I have product "PHP T-Shirt" in the cart
When I proceed selecting "Offline" payment method
And I confirm my order
Then I should see the thank you page
And I should be informed with "Offline" payment method instructions
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
And I should be informed with "Offline" payment method instructions
Then I should be informed with "Offline" payment method instructions

32 changes: 32 additions & 0 deletions src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,38 @@ public function iShouldBeOnTheCheckoutCompleteStep(): void
);
}

/**
* @Then I should be informed with :paymentMethod payment method instructions
*/
public function iShouldBeInformedWithPaymentMethodInstructions(PaymentMethodInterface $paymentMethod): void
{
$response = $this->client->getLastResponse();
$payments = $this->responseChecker->getValue($response, 'payments');

Assert::notEmpty($payments, 'No payments found in response.');
$paymentMethodIri = $this->iriConverter->getIriFromItem($paymentMethod);
foreach ($payments as $payment) {
if ($payment['method'] !== $paymentMethodIri) {
continue;
}

$customRequest = $this->requestFactory->custom($payment['method'], HTTPRequest::METHOD_GET);
$paymentMethodResponse = $this->client->executeCustomRequest($customRequest);
Assert::same(
$this->responseChecker->getValue(
$paymentMethodResponse,
'instructions',
),
$paymentMethod->getInstructions(),
sprintf('Payment method instructions should be equal to %s', $paymentMethod->getInstructions()),
);

return;
}

throw new \Exception(sprintf('Payment method %s not found in response.', $paymentMethod->getName()));
}

/**
* @Then I should not be able to confirm order because products do not fit :shippingMethod requirements
*/
Expand Down
Loading