Skip to content

Commit ca8c7c5

Browse files
committed
Add e2e tests for transactions
1 parent 0480672 commit ca8c7c5

19 files changed

+1442
-1
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ tests/playwright/test-results
1616
!/build/.yarn/sdks
1717
!/build/.yarn/versions
1818

19+
# Playwright
20+
node_modules/
21+
/test-results/
22+
/playwright-report/
23+
/blob-report/
24+
/playwright/.cache/

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"devDependencies": {
3-
"@wordpress/scripts": "^29.0.0"
3+
"@playwright/test": "^1.53.0",
4+
"@types/node": "^24.0.0",
5+
"@wordpress/scripts": "^29.0.0",
6+
"dotenv": "^16.5.0"
47
},
58
"scripts": {
69
"build": "wp-scripts build",

playwright.config.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
import * as dotenv from 'dotenv';
8+
import * as path from 'path';
9+
dotenv.config({ path: path.resolve(__dirname, '.env') });
10+
11+
/**
12+
* See https://playwright.dev/docs/test-configuration.
13+
*/
14+
export default defineConfig({
15+
testDir: './tests',
16+
fullyParallel: true,
17+
forbidOnly: !!process.env.CI,
18+
retries: process.env.CI ? 2 : 0,
19+
workers: process.env.CI ? 1 : undefined,
20+
reporter: 'html',
21+
use: {
22+
baseURL: process.env.TESTSITE_URL,
23+
trace: 'on-first-retry',
24+
},
25+
26+
projects: [
27+
{
28+
name: 'matrix',
29+
use: { ...devices['Desktop Chrome'] },
30+
testMatch: '**/payment-gateway-matrix.spec.ts',
31+
},
32+
33+
/*{
34+
name: 'firefox',
35+
use: { ...devices['Desktop Firefox'] },
36+
},
37+
38+
{
39+
name: 'webkit',
40+
use: { ...devices['Desktop Safari'] },
41+
},*/
42+
43+
/* Test against mobile viewports. */
44+
// {
45+
// name: 'Mobile Chrome',
46+
// use: { ...devices['Pixel 5'] },
47+
// },
48+
// {
49+
// name: 'Mobile Safari',
50+
// use: { ...devices['iPhone 12'] },
51+
// },
52+
53+
/* Test against branded browsers. */
54+
// {
55+
// name: 'Microsoft Edge',
56+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
57+
// },
58+
// {
59+
// name: 'Google Chrome',
60+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
61+
// },
62+
],
63+
64+
/* Run your local dev server before starting the tests */
65+
// webServer: {
66+
// command: 'npm run start',
67+
// url: 'http://localhost:3000',
68+
// reuseExistingServer: !process.env.CI,
69+
// },
70+
});

tests/fixtures/checkout-types.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Represents the configuration for a checkout type
3+
*/
4+
export interface CheckoutType {
5+
id: string;
6+
name: string;
7+
url: string;
8+
isBlockCheckout: boolean;
9+
}
10+
11+
/**
12+
* Available checkout types in WooCommerce
13+
*/
14+
export const CHECKOUT_TYPES: Record<string, CheckoutType> = {
15+
// Standard WooCommerce checkout
16+
CLASSIC: {
17+
id: 'classic',
18+
name: 'Classic Checkout',
19+
url: '/checkout/',
20+
isBlockCheckout: false
21+
},
22+
23+
// WooCommerce Blocks checkout
24+
BLOCK: {
25+
id: 'block',
26+
name: 'Block Checkout',
27+
url: '/checkout-block/',
28+
isBlockCheckout: true
29+
},
30+
31+
// Pay for Order page (for failed payment recovery)
32+
PAY_FOR_ORDER: {
33+
id: 'pay_for_order',
34+
name: 'Pay for Order',
35+
url: '/checkout/order-pay/',
36+
isBlockCheckout: false
37+
}
38+
};

tests/fixtures/payment-methods.ts

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/**
2+
* Represents the configuration for a payment method
3+
*/
4+
export interface PaymentMethod {
5+
id: string;
6+
name: string;
7+
className: string; // CSS class used to identify the method
8+
isApplicableToSubscription: boolean;
9+
paymentProcessFunction: string; // Name of the function to process this payment
10+
isHostedPayment: boolean; // Whether payment happens on external page
11+
countriesSupported: string[]; // ISO country codes where this method is available
12+
selector: {
13+
classic: string;
14+
block: string;
15+
};
16+
presetCredentials: string;
17+
}
18+
19+
/**
20+
* Available payment methods in the MONEI gateway
21+
*/
22+
export const PAYMENT_METHODS: Record<string, PaymentMethod> = {
23+
// Credit Card (with Component)
24+
CREDIT_CARD_SUCCESS: {
25+
id: 'monei',
26+
name: 'Credit Card',
27+
className: 'wc-monei-credit-card-payment-method',
28+
isApplicableToSubscription: true,
29+
paymentProcessFunction: 'processCreditCardPayment',
30+
isHostedPayment: false,
31+
countriesSupported: ['ES', 'PT', 'FR', 'DE', 'IT', 'UK'], // Example countries
32+
selector: {
33+
classic: 'input[name="payment_method"][value="monei"]',
34+
block: '.wc-block-components-radio-control__input[value="monei"]'
35+
},
36+
presetCredentials: 'success'
37+
},
38+
39+
// Credit Card (with Redirect/Hosted)
40+
CREDIT_CARD_HOSTED: {
41+
id: 'monei',
42+
name: 'Credit Card (Hosted)',
43+
className: 'wc-monei-credit-card-hosted-payment-method',
44+
isApplicableToSubscription: true,
45+
paymentProcessFunction: 'processCreditCardHostedPayment',
46+
isHostedPayment: true,
47+
countriesSupported: ['ES', 'PT', 'FR', 'DE', 'IT', 'UK'], // Example countries
48+
selector: {
49+
classic: 'input[name="payment_method"][value="monei"]',
50+
block: '.wc-block-components-radio-control__input[value="monei"]'
51+
},
52+
presetCredentials: 'success'
53+
},
54+
55+
// Bizum
56+
BIZUM: {
57+
id: 'monei_bizum',
58+
name: 'Bizum',
59+
className: 'wc-monei-bizum-payment-method',
60+
isApplicableToSubscription: false,
61+
paymentProcessFunction: 'processBizumPayment',
62+
isHostedPayment: true,
63+
countriesSupported: ['ES'],
64+
selector: {
65+
classic: 'input[name="payment_method"][value="monei_bizum"]',
66+
block: '.wc-block-components-radio-control__input[value="monei_bizum"]'
67+
},
68+
presetCredentials: 'success'
69+
},
70+
71+
// PayPal
72+
PAYPAL: {
73+
id: 'monei_paypal',
74+
name: 'PayPal',
75+
className: 'wc-monei-paypal-payment-method',
76+
isApplicableToSubscription: true,
77+
paymentProcessFunction: 'processPayPalPayment',
78+
isHostedPayment: true,
79+
countriesSupported: ['ES', 'PT', 'FR', 'DE', 'IT', 'UK', 'US'], // Example countries
80+
selector: {
81+
classic: 'input[name="payment_method"][value="monei_paypal"]',
82+
block: '.wc-block-components-radio-control__input[value="monei_paypal"]'
83+
},
84+
presetCredentials: 'success'
85+
},
86+
87+
// Apple Pay
88+
APPLE_PAY: {
89+
id: 'monei_apple_pay',
90+
name: 'Apple Pay',
91+
className: 'wc-monei-apple-pay-payment-method',
92+
isApplicableToSubscription: true,
93+
paymentProcessFunction: 'processApplePayPayment',
94+
isHostedPayment: false,
95+
countriesSupported: ['ES', 'PT', 'FR', 'DE', 'IT', 'UK', 'US'], // Example countries
96+
selector: {
97+
classic: 'input[name="payment_method"][value="monei_apple_pay"]',
98+
block: '.wc-block-components-radio-control__input[value="monei_apple_pay"]'
99+
},
100+
presetCredentials: 'success'
101+
},
102+
103+
// Google Pay
104+
GOOGLE_PAY: {
105+
id: 'monei_google_pay',
106+
name: 'Google Pay',
107+
className: 'wc-monei-google-pay-payment-method',
108+
isApplicableToSubscription: true,
109+
paymentProcessFunction: 'processGooglePayPayment',
110+
isHostedPayment: false,
111+
countriesSupported: ['ES', 'PT', 'FR', 'DE', 'IT', 'UK', 'US'], // Example countries
112+
selector: {
113+
classic: 'input[name="payment_method"][value="monei_google_pay"]',
114+
block: '.wc-block-components-radio-control__input[value="monei_google_pay"]'
115+
},
116+
presetCredentials: 'success'
117+
},
118+
119+
// Multibanco
120+
MULTIBANCO: {
121+
id: 'monei_multibanco',
122+
name: 'Multibanco',
123+
className: 'wc-monei-multibanco-payment-method',
124+
isApplicableToSubscription: false,
125+
paymentProcessFunction: 'processMultibancoPayment',
126+
isHostedPayment: true,
127+
countriesSupported: ['PT'],
128+
selector: {
129+
classic: 'input[name="payment_method"][value="monei_multibanco"]',
130+
block: '.wc-block-components-radio-control__input[value="monei_multibanco"]'
131+
},
132+
presetCredentials: 'success'
133+
},
134+
135+
// MBWay
136+
MBWAY: {
137+
id: 'monei_mbway',
138+
name: 'MBWay',
139+
className: 'wc-monei-mbway-payment-method',
140+
isApplicableToSubscription: false,
141+
paymentProcessFunction: 'processMBWayPayment',
142+
isHostedPayment: true,
143+
countriesSupported: ['PT'],
144+
selector: {
145+
classic: 'input[name="payment_method"][value="monei_mbway"]',
146+
block: '.wc-block-components-radio-control__input[value="monei_mbway"]'
147+
},
148+
presetCredentials: 'success'
149+
},
150+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export const PAYMENT_TEST_DATA = {
2+
creditCard: {
3+
success: {
4+
cardNumber: '4444444444444422',
5+
expiry: '12/34',
6+
cvc: '123',
7+
cardholderName: 'John Doe'
8+
},
9+
threeDSecure: {
10+
cardNumber: '4444444444444406',
11+
expiry: '12/34',
12+
cvc: '123',
13+
cardholderName: 'John Doe'
14+
},
15+
fail: {
16+
cardNumber: '4444444444444406',
17+
expiry: '12/34',
18+
cvc: '123',
19+
cardholderName: 'John Doe'
20+
}
21+
},
22+
bizum: {
23+
success: {
24+
phoneNumber: '+3450000000000'
25+
},
26+
fail: {
27+
phoneNumber: '+3450000000000'
28+
}
29+
},
30+
// Add other payment methods as needed
31+
};

tests/fixtures/product-types.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Represents the configuration for a product type
3+
*/
4+
export interface ProductType {
5+
id: string;
6+
name: string;
7+
isSubscription: boolean;
8+
subscriptionPlugin?: string; // 'woocommerce' or 'yith'
9+
sampleProductId?: number; // ID of a sample product of this type for testing
10+
sampleProductSlug?: string; // Slug of a sample product
11+
price?: number; // Price to expect
12+
}
13+
14+
/**
15+
* Available product types to test with
16+
*/
17+
export const PRODUCT_TYPES: Record<string, ProductType> = {
18+
// Simple product
19+
SIMPLE: {
20+
id: 'simple',
21+
name: 'Simple Product',
22+
isSubscription: false,
23+
sampleProductId: 63,
24+
sampleProductSlug: 'simple',
25+
price: 19.99
26+
},
27+
28+
// Variable product
29+
VARIABLE: {
30+
id: 'variable',
31+
name: 'Variable Product',
32+
isSubscription: false,
33+
sampleProductId: 456,
34+
sampleProductSlug: 'sample-variable-product',
35+
price: 29.99
36+
},
37+
38+
// WooCommerce Subscription
39+
WC_SUBSCRIPTION: {
40+
id: 'subscription',
41+
name: 'WooCommerce Subscription',
42+
isSubscription: true,
43+
subscriptionPlugin: 'woocommerce',
44+
sampleProductId: 789,
45+
sampleProductSlug: 'sample-wc-subscription',
46+
price: 9.99
47+
},
48+
49+
// YITH Subscription
50+
YITH_SUBSCRIPTION: {
51+
id: 'yith_subscription',
52+
name: 'YITH Subscription',
53+
isSubscription: true,
54+
subscriptionPlugin: 'yith',
55+
sampleProductId: 1011,
56+
sampleProductSlug: 'sample-yith-subscription',
57+
price: 14.99
58+
}
59+
};

0 commit comments

Comments
 (0)