Cover Seeing payment method instructions behat scenario

This commit is contained in:
TheMilek 2023-06-12 11:54:01 +02:00
parent aba91d8c1d
commit 3c6002b63f
No known key found for this signature in database
GPG key ID: 2E44205E7374692F
2 changed files with 35 additions and 4 deletions

View file

@ -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
@ -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

View file

@ -553,6 +553,38 @@ final class CheckoutContext implements Context
);
}
/**
* @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
*/