Skip to content

Commit 806e7fa

Browse files
Add E2E tests for refund select form
1 parent 3f8bf2b commit 806e7fa

File tree

3 files changed

+199
-2
lines changed

3 files changed

+199
-2
lines changed

src/Refunding/Provider/TpayAwareRefundPaymentMethodsProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,3 @@ private function getLastCompletedPayment(OrderInterface $order): ?PaymentInterfa
4848
return $order->getLastPayment(PaymentInterface::STATE_COMPLETED);
4949
}
5050
}
51-
52-
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Admin\Order\Refunds;
6+
7+
use Facebook\WebDriver\WebDriverBy;
8+
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\E2ETestCase;
9+
use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Account\LoginAdminUserTrait;
10+
use Webmozart\Assert\Assert;
11+
12+
final class TpayRedirectVisibilityOnRefundsPageTest extends E2ETestCase
13+
{
14+
use LoginAdminUserTrait;
15+
16+
protected function setUp(): void
17+
{
18+
parent::setUp();
19+
20+
$this->loadFixtures(['admin/refund_methods.yaml']);
21+
22+
$this->loginAdminUser('rich@example.com', 'sylius');
23+
}
24+
25+
public function test_it_hides_tpay_redirect_when_no_transaction_id(): void
26+
{
27+
$this->client->request('GET', '/admin/orders/000000030/refunds');
28+
29+
$paymentMethods = $this->getRefundPaymentMethods();
30+
31+
self::assertStringNotContainsString('Tpay', implode(' ', $paymentMethods));
32+
}
33+
34+
public function test_it_shows_tpay_redirect_when_transaction_id_present(): void
35+
{
36+
$this->client->request('GET', '/admin/orders/000000031/refunds');
37+
38+
$paymentMethods = $this->getRefundPaymentMethods();
39+
40+
self::assertStringContainsString('Tpay', implode(' ', $paymentMethods));
41+
}
42+
43+
/** @return array<string> */
44+
private function getRefundPaymentMethods(): array
45+
{
46+
$select = $this->client->findElement(WebDriverBy::id('payment-methods'));
47+
Assert::notNull($select);
48+
49+
$options = $select->findElements(WebDriverBy::cssSelector('option'));
50+
51+
return array_map(fn($option): string => trim($option->getText()), $options);
52+
}
53+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
include:
2+
- ../common/channel.yaml
3+
- ../common/country.yaml
4+
- ../common/customer.yaml
5+
- ../common/payment_method.yaml
6+
- ../common/shipping_category.yaml
7+
- ../common/shipping_method.yaml
8+
- ../common/tax_category.yaml
9+
- ../common/admin.yaml
10+
11+
Sylius\Component\Core\Model\Product:
12+
product_refund_wo_tx:
13+
fallbackLocale: en_US
14+
currentLocale: en
15+
code: 'MUG_REFUND_WO_TX'
16+
translations:
17+
- '@product_refund_wo_tx_translation'
18+
product_refund_w_tx:
19+
fallbackLocale: en_US
20+
currentLocale: en
21+
code: 'MUG_REFUND_W_TX'
22+
translations:
23+
- '@product_refund_w_tx_translation'
24+
25+
Sylius\Component\Core\Model\ProductTranslation:
26+
product_refund_wo_tx_translation:
27+
name: 'Mug Refund WO TX'
28+
slug: 'mug-refund-wo-tx'
29+
locale: 'en_US'
30+
translatable: '@product_refund_wo_tx'
31+
product_refund_w_tx_translation:
32+
name: 'Mug Refund W TX'
33+
slug: 'mug-refund-w-tx'
34+
locale: 'en_US'
35+
translatable: '@product_refund_w_tx'
36+
37+
Sylius\Component\Core\Model\ProductVariant:
38+
product_variant_refund_wo_tx:
39+
code: 'MUG_REFUND_WO_TX_V'
40+
product: '@product_refund_wo_tx'
41+
channelPricings:
42+
channel_web: '@product_variant_refund_wo_tx_pricing'
43+
enabled: true
44+
tracked: true
45+
onHold: 0
46+
onHand: 10
47+
product_variant_refund_w_tx:
48+
code: 'MUG_REFUND_W_TX_V'
49+
product: '@product_refund_w_tx'
50+
channelPricings:
51+
channel_web: '@product_variant_refund_w_tx_pricing'
52+
enabled: true
53+
tracked: true
54+
onHold: 0
55+
onHand: 10
56+
57+
Sylius\Component\Core\Model\ChannelPricing:
58+
product_variant_refund_wo_tx_pricing:
59+
channelCode: 'WEB'
60+
price: 2000
61+
product_variant_refund_w_tx_pricing:
62+
channelCode: 'WEB'
63+
price: 2000
64+
65+
Sylius\Component\Core\Model\Address:
66+
address_refund_wo_tx:
67+
firstName: 'Tony'
68+
lastName: 'Doe'
69+
street: 'Green Avenue 1'
70+
countryCode: 'US'
71+
city: 'New York'
72+
postcode: '00001'
73+
address_refund_w_tx:
74+
firstName: 'Tony'
75+
lastName: 'Doe'
76+
street: 'Green Avenue 2'
77+
countryCode: 'US'
78+
city: 'New York'
79+
postcode: '00002'
80+
81+
TestApp\Entity\Order:
82+
order_refund_wo_tx:
83+
number: '000000030'
84+
tokenValue: 'tokenValue30'
85+
channel: '@channel_web'
86+
currencyCode: 'USD'
87+
localeCode: 'en_US'
88+
customerWithAuthorization: '@customer_tony'
89+
state: 'fulfilled'
90+
checkoutState: 'completed'
91+
paymentState: 'paid'
92+
shippingState: 'shipped'
93+
shippingAddress: '@address_refund_wo_tx'
94+
billingAddress: '@address_refund_wo_tx'
95+
__calls:
96+
- addItem: ['@order_item_refund_wo_tx']
97+
order_refund_w_tx:
98+
number: '000000031'
99+
tokenValue: 'tokenValue31'
100+
channel: '@channel_web'
101+
currencyCode: 'USD'
102+
localeCode: 'en_US'
103+
customerWithAuthorization: '@customer_tony'
104+
state: 'fulfilled'
105+
checkoutState: 'completed'
106+
paymentState: 'paid'
107+
shippingState: 'shipped'
108+
shippingAddress: '@address_refund_w_tx'
109+
billingAddress: '@address_refund_w_tx'
110+
__calls:
111+
- addItem: ['@order_item_refund_w_tx']
112+
113+
Sylius\Component\Core\Model\OrderItem:
114+
order_item_refund_wo_tx:
115+
variant: '@product_variant_refund_wo_tx'
116+
unitPrice: 2000
117+
order_item_refund_w_tx:
118+
variant: '@product_variant_refund_w_tx'
119+
unitPrice: 2000
120+
121+
Sylius\Component\Core\Model\OrderItemUnit:
122+
order_item_unit_refund_wo_tx:
123+
__construct: ['@order_item_refund_wo_tx']
124+
order_item_unit_refund_w_tx:
125+
__construct: ['@order_item_refund_w_tx']
126+
127+
Sylius\Component\Core\Model\Payment:
128+
payment_refund_wo_tx:
129+
method: '@tpay'
130+
order: '@order_refund_wo_tx'
131+
currency_code: 'USD'
132+
amount: 2000
133+
state: completed
134+
details:
135+
tpay: { }
136+
payment_refund_w_tx:
137+
method: '@tpay'
138+
order: '@order_refund_w_tx'
139+
currency_code: 'USD'
140+
amount: 2000
141+
state: completed
142+
details:
143+
tpay:
144+
transaction_id: 'foo'
145+
146+

0 commit comments

Comments
 (0)