Skip to content

Commit

Permalink
Add missing E2E tests for PBL with channel ID specified
Browse files Browse the repository at this point in the history
  • Loading branch information
coldic3 committed Nov 18, 2024
1 parent c9bae13 commit ae7124c
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 19 deletions.
1 change: 1 addition & 0 deletions assets/admin/js/test_payment_method_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function convertTpayChannelIdInputIntoSelect(channels) {
if (tpayChannelIdFormType.tagName.toLowerCase() === 'input' && tpayChannelIdFormType.type === 'text') {
const select = document.createElement('select');
select.name = tpayChannelIdFormType.name;
select.id = tpayChannelIdFormType.id;
select.className = tpayChannelIdFormType.className;
tpayChannelIdFormType.replaceWith(select);
tpayChannelIdFormType = select;
Expand Down
46 changes: 46 additions & 0 deletions tests/E2E/Admin/PaymentMethod/TestPaymentMethodConnectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Admin\PaymentMethod;

use Facebook\WebDriver\WebDriverBy;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\E2ETestCase;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Account\LoginAdminUserTrait;

final class TestPaymentMethodConnectionTest extends E2ETestCase
{
use LoginAdminUserTrait;

protected function setUp(): void
{
parent::setUp();

$this->loadFixtures(['admin/payment_methods.yaml']);

$this->loginAdminUser('[email protected]', 'sylius');
}

public function test_it_checks_if_payment_method_connection(): void
{
$this->client->request('GET', '/admin/payment-methods/new/tpay');

$this->client
->findElement(WebDriverBy::id('sylius_payment_method_gatewayConfig_config_client_id'))
->sendKeys(getenv('TPAY_CLIENT_ID'))
;
$this->client
->findElement(WebDriverBy::id('sylius_payment_method_gatewayConfig_config_client_secret'))
->sendKeys(getenv('TPAY_CLIENT_SECRET'))
;
$this->client
->findElement(WebDriverBy::id('sylius_payment_method_gatewayConfig_config_production_mode'))
->sendKeys('No')
;
$this->client->findElement(WebDriverBy::id('test-connection-button'))->click();
$this->client->waitForElementToContain('#test-connection-message', 'Connection test successful. Channels loaded.');
$channelSelector = $this->client->findElement(WebDriverBy::id('sylius_payment_method_gatewayConfig_config_tpay_channel_id'));

$this->assertSame('select', $channelSelector->getTagName());
}
}
19 changes: 19 additions & 0 deletions tests/E2E/Helper/Account/LoginAdminUserTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Account;

use Symfony\Component\Panther\Client;

/**
* @property Client $client
*/
trait LoginAdminUserTrait
{
protected function loginAdminUser(string $email, string $password): void
{
$this->client->request('GET', '/admin/login');
$this->client->submitForm('Login', ['_username' => $email, '_password' => $password]);
}
}
5 changes: 5 additions & 0 deletions tests/E2E/Resources/fixtures/admin/payment_methods.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include:
- ../common/channel.yaml
- ../common/country.yaml
- ../common/payment_method.yaml
- ../common/admin.yaml
8 changes: 8 additions & 0 deletions tests/E2E/Resources/fixtures/common/admin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Sylius\Component\Core\Model\AdminUser:
admin_user_rich:
plainPassword: sylius
roles: [ROLE_ADMINISTRATION_ACCESS]
enabled: true
email: "rich\\@example.com"
username: rich
localeCode: en
24 changes: 23 additions & 1 deletion tests/E2E/Resources/fixtures/common/payment_method.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ Sylius\Component\Core\Model\PaymentMethod:
translations:
- '@tpay_pbl_payment_method_translation'
channels: [ '@channel_web' ]
tpay_pbl_one_channel:
code: 'tpay_pbl_one_channel'
enabled: true
gatewayConfig: '@gateway_tpay_pbl_one_channel'
translations:
- '@tpay_pbl_one_channel_payment_method_translation'
channels: [ '@channel_web' ]
tpay_visa_mobile:
code: 'tpay_visa_mobile'
enabled: true
Expand Down Expand Up @@ -88,6 +95,16 @@ Sylius\Bundle\PayumBundle\Model\GatewayConfig:
type: 'pay_by_link'
production_mode: false
encrypted: true
gateway_tpay_pbl_one_channel:
gatewayName: 'tpay'
factoryName: 'tpay'
config:
client_id: 'encrypted_<getenv("TPAY_CLIENT_ID")>'
client_secret: 'encrypted_<getenv("TPAY_CLIENT_SECRET")>'
tpay_channel_id: '1'
type: 'pay_by_link'
production_mode: false
encrypted: true
gateway_tpay_visa_mobile:
gatewayName: 'tpay'
factoryName: 'tpay'
Expand Down Expand Up @@ -120,10 +137,15 @@ Sylius\Component\Payment\Model\PaymentMethodTranslation:
description: '<paragraph(2)>'
translatable: '@tpay_google_pay'
tpay_pbl_payment_method_translation:
name: 'Bank (Tpay)'
name: 'Choose bank (Tpay)'
locale: 'en_US'
description: '<paragraph(2)>'
translatable: '@tpay_pbl'
tpay_pbl_one_channel_payment_method_translation:
name: 'One Bank (Tpay)'
locale: 'en_US'
description: '<paragraph(2)>'
translatable: '@tpay_pbl_one_channel'
tpay_visa_mobile_payment_method_translation:
name: 'Visa mobile (Tpay)'
locale: 'en_US'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace E2E\Checkout;
namespace Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Shop\Checkout;

use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\E2ETestCase;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Account\LoginShopUserTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

declare(strict_types=1);

namespace E2E\Checkout;
namespace Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Shop\Checkout;

use Facebook\WebDriver\Exception\NoSuchElementException;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\E2ETestCase;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Account\LoginShopUserTrait;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Order\CartTrait;
Expand Down
48 changes: 48 additions & 0 deletions tests/E2E/Shop/Checkout/TpayPayByLinkCheckoutTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Shop\Checkout;

use Facebook\WebDriver\WebDriverBy;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\E2ETestCase;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Account\LoginShopUserTrait;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Order\CartTrait;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Order\TpayTrait;

final class TpayPayByLinkCheckoutTest extends E2ETestCase
{
use CartTrait;
use TpayTrait;
use LoginShopUserTrait;

private const FORM_ID = 'sylius_checkout_complete';

protected function setUp(): void
{
parent::setUp();

$this->loadFixtures(['addressed_cart.yaml']);

$this->loginShopUser('[email protected]', 'sylius');
$this->showSelectingShippingMethodStep();
$this->processWithDefaultShippingMethod();
}

public function test_it_completes_the_checkout_using_pay_by_link_channel_selection(): void
{
$this->processWithPaymentMethod('tpay_pbl');
$this->client->findElement(WebDriverBy::xpath("//div[@data-bank-id='1']"))->click();
$this->placeOrder();

$this->assertPageTitleContains('Thank you!');
}

public function test_it_completes_the_checkout_using_pay_by_link_channel_preselected(): void
{
$this->processWithPaymentMethod('tpay_pbl_one_channel');
$this->placeOrder();

$this->assertPageTitleContains('Thank you!');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Checkout;
namespace Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Shop\Checkout;

use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\E2ETestCase;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Account\LoginShopUserTrait;
Expand All @@ -17,8 +17,6 @@ final class TpayPaymentCheckoutTest extends E2ETestCase

private const FORM_ID = 'sylius_checkout_complete';

private const CARD_NUMBER = '4012 0010 3714 1112';

protected function setUp(): void
{
parent::setUp();
Expand All @@ -39,15 +37,6 @@ public function test_it_completes_the_checkout(): void
$this->assertPageTitleContains('Thank you!');
}

public function test_it_completes_the_checkout_using_credit_card(): void
{
$this->processWithPaymentMethod('tpay_card');
$this->fillCardData(self::FORM_ID, self::CARD_NUMBER, '123', '01', '2029');
$this->placeOrder();

$this->assertPageTitleContains('Waiting for payment | Web Channel');
}

public function test_it_completes_the_checkout_using_blik(): void
{
$this->processWithPaymentMethod('tpay_blik');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Checkout;
namespace Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Shop\Checkout;

use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\E2ETestCase;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Account\LoginShopUserTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Order;
namespace Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Shop\Order;

use Facebook\WebDriver\WebDriverBy;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\E2ETestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace E2E\RetryPayment;
namespace Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Shop\RetryPayment;

use Tests\CommerceWeavers\SyliusTpayPlugin\Api\Utils\OrderPlacerTrait;
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\E2ETestCase;
Expand Down

0 comments on commit ae7124c

Please sign in to comment.