-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
payment.spec.js
128 lines (114 loc) · 3.89 KB
/
payment.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const { test, expect } = require( '@playwright/test' );
const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
test.describe( 'Payment setup task', () => {
test.use( { storageState: process.env.ADMINSTATE } );
test.beforeEach( async ( { page } ) => {
await page.goto(
'wp-admin/admin.php?page=wc-admin&path=/setup-wizard'
);
await page.click( 'text=Skip setup store details' );
await page.click( 'button >> text=No thanks' );
await page.waitForLoadState( 'networkidle' );
} );
test.afterAll( async ( { baseURL } ) => {
const api = new wcApi( {
url: baseURL,
consumerKey: process.env.CONSUMER_KEY,
consumerSecret: process.env.CONSUMER_SECRET,
version: 'wc/v3',
} );
await api.put( 'payment_gateways/bacs', {
enabled: false,
} );
await api.put( 'payment_gateways/cod', {
enabled: false,
} );
} );
test( 'Can visit the payment setup task from the homescreen if the setup wizard has been skipped', async ( {
page,
} ) => {
await page.goto( 'wp-admin/admin.php?page=wc-admin' );
await page.click( 'text=Set up payments' );
await expect(
page.locator( '.woocommerce-layout__header-wrapper > h1' )
).toHaveText( 'Set up payments' );
} );
test( 'Saving valid bank account transfer details enables the payment method', async ( {
page,
} ) => {
// load the bank transfer page
await page.goto(
'wp-admin/admin.php?page=wc-admin&task=payments&id=bacs'
);
// purposely no await -- close the help dialog if/when it appears
page.locator( '.components-button.is-small.has-icon' )
.click()
.catch( () => {} );
// fill in bank transfer form
await page.fill( '//input[@placeholder="Account name"]', 'Savings' );
await page.fill( '//input[@placeholder="Account number"]', '1234' );
await page.fill( '//input[@placeholder="Bank name"]', 'Test Bank' );
await page.fill( '//input[@placeholder="Sort code"]', '12' );
await page.fill( '//input[@placeholder="IBAN"]', '12 3456 7890' );
await page.fill( '//input[@placeholder="BIC / Swift"]', 'ABBA' );
await page.click( 'text=Save' );
// check that bank transfers were set up
await expect(
page.locator( 'div.components-snackbar__content' )
).toContainText( 'Direct bank transfer details added successfully' );
await page.goto( 'wp-admin/admin.php?page=wc-settings&tab=checkout' );
await expect(
page.locator(
'//tr[@data-gateway_id="bacs"]/td[@class="status"]/a'
)
).toHaveClass( 'wc-payment-gateway-method-toggle-enabled' );
} );
test( 'Enabling cash on delivery enables the payment method', async ( {
page,
baseURL,
} ) => {
// Payments page differs if located outside of a WCPay-supported country, so make sure we aren't.
const api = new wcApi( {
url: baseURL,
consumerKey: process.env.CONSUMER_KEY,
consumerSecret: process.env.CONSUMER_SECRET,
version: 'wc/v3',
} );
// ensure store address is US
await api.post( 'settings/general/batch', {
update: [
{
id: 'woocommerce_store_address',
value: 'addr 1',
},
{
id: 'woocommerce_store_city',
value: 'San Francisco',
},
{
id: 'woocommerce_default_country',
value: 'US:CA',
},
{
id: 'woocommerce_store_postcode',
value: '94107',
},
],
} );
await page.goto( 'wp-admin/admin.php?page=wc-admin&task=payments' );
// purposely no await -- close the help dialog if/when it appears
page.locator( '.components-button.is-small.has-icon' )
.click()
.catch( () => {} );
await page.waitForLoadState( 'networkidle' );
// enable COD payment option
await page.click(
'div.woocommerce-task-payment-cod > div.woocommerce-task-payment__footer > button'
);
await page.waitForLoadState( 'networkidle' );
await page.goto( 'wp-admin/admin.php?page=wc-settings&tab=checkout' );
await expect(
page.locator( '//tr[@data-gateway_id="cod"]/td[@class="status"]/a' )
).toHaveClass( 'wc-payment-gateway-method-toggle-enabled' );
} );
} );