Skip to content

Commit

Permalink
Cover Seeing payment method instructions behat scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMilek committed Jun 15, 2023
1 parent aba91d8 commit 3c6002b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
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
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

0 comments on commit 3c6002b

Please sign in to comment.