forked from paypal/paypal-checkout-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaypal.test.js
155 lines (125 loc) · 5.61 KB
/
paypal.test.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* @flow */
import { FUNDING } from '@paypal/sdk-constants';
import { withPage, waitForClose } from './common';
import { runCheckoutLoginFlow, resolveCheckoutContingencies, runCheckoutChoicePage, completeCheckoutReviewPage, renderSmartButtons, getButtonByFundingSource, clickButton, changeFundingSource } from './procedures';
import { ACCOUNTS } from './accounts';
describe('PayPal end to end tests', () => {
it('Should run an end-to-end transaction on stage with the paypal button', async () => {
await withPage(async ({ page }) => {
const buttonFrame = await renderSmartButtons(page, `
{
createOrder: function (data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '10.00'
}
}]
});
},
updateClientConfiguration: true,
onApprove: function (data, actions) {
window.capturePromise = actions.order.capture();
}
}
`);
const button = await getButtonByFundingSource(buttonFrame, FUNDING.PAYPAL);
const checkoutPopup = await clickButton(page, button);
await runCheckoutLoginFlow(checkoutPopup, {
user: ACCOUNTS.US_BUYER.EMAIL,
password: ACCOUNTS.US_BUYER.PASSWORD
});
await resolveCheckoutContingencies(checkoutPopup);
await runCheckoutChoicePage(checkoutPopup);
await completeCheckoutReviewPage(checkoutPopup);
await waitForClose(checkoutPopup);
const { id } = await page.evaluate(`
window.capturePromise
`);
if (!id) {
throw new Error(`Expected to get order id from transaction`);
}
// eslint-disable-next-line no-console
console.info('Order ID:', id);
});
});
it('Should run an end-to-end transaction on stage with the credit button', async () => {
await withPage(async ({ page }) => {
const buttonFrame = await renderSmartButtons(page, `
{
createOrder: function (data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '50.00'
}
}]
});
},
updateClientConfiguration: true,
onApprove: function (data, actions) {
window.capturePromise = actions.order.capture();
}
}
`);
const button = await getButtonByFundingSource(buttonFrame, FUNDING.CREDIT);
const checkoutPopup = await clickButton(page, button);
await runCheckoutLoginFlow(checkoutPopup, {
user: ACCOUNTS.US_BUYER_WITH_CREDIT.EMAIL,
password: ACCOUNTS.US_BUYER_WITH_CREDIT.PASSWORD
});
await resolveCheckoutContingencies(checkoutPopup);
await runCheckoutChoicePage(checkoutPopup);
await completeCheckoutReviewPage(checkoutPopup);
await waitForClose(checkoutPopup);
const { id } = await page.evaluate(`
window.capturePromise
`);
if (!id) {
throw new Error(`Expected to get order id from transaction`);
}
// eslint-disable-next-line no-console
console.info('Order ID:', id);
});
});
it('Should run an end-to-end transaction on stage with the credit button and change funding source', async () => {
await withPage(async ({ page }) => {
const buttonFrame = await renderSmartButtons(page, `
{
createOrder: function (data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '50.00'
}
}]
});
},
updateClientConfiguration: true,
onApprove: function (data, actions) {
window.capturePromise = actions.order.capture();
}
}
`);
const button = await getButtonByFundingSource(buttonFrame, FUNDING.CREDIT);
const checkoutPopup = await clickButton(page, button);
await runCheckoutLoginFlow(checkoutPopup, {
user: ACCOUNTS.US_BUYER_WITH_CREDIT.EMAIL,
password: ACCOUNTS.US_BUYER_WITH_CREDIT.PASSWORD
});
await resolveCheckoutContingencies(checkoutPopup);
await runCheckoutChoicePage(checkoutPopup);
await changeFundingSource(checkoutPopup);
await completeCheckoutReviewPage(checkoutPopup);
await waitForClose(checkoutPopup);
const { id } = await page.evaluate(`
window.capturePromise
`);
if (!id) {
throw new Error(`Expected to get order id from transaction`);
}
// eslint-disable-next-line no-console
console.info('Order ID:', id);
});
});
});