Skip to content

Commit

Permalink
add ancv to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m1aw committed Oct 10, 2023
1 parent a3ccf40 commit 2b7a2c7
Show file tree
Hide file tree
Showing 22 changed files with 551 additions and 7 deletions.
14 changes: 10 additions & 4 deletions packages/e2e-playwright/app/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ const htmlPages = fs.readdirSync(basePageDir).map(fileName => ({
id: fileName
}));

const htmlPageGenerator = ({ id }, index) =>
new HTMLWebpackPlugin({
filename: `${index ? `${id.toLowerCase()}/` : ''}index.html`,
//console.log('htmlPages', htmlPages);

const htmlPageGenerator = ({ id }, index) => {
console.log('htmlPageGenerator', id, index);
return new HTMLWebpackPlugin({
// make card index.html the rest of the pages will have page <lower case ID>.html
filename: `${id !== 'Cards' ? `${id.toLowerCase()}/` : ''}index.html`,
template: path.join(__dirname, `../src/pages/${id}/${id}.html`),
templateParameters: () => ({ htmlWebpackPlugin: { htmlPages } }),
inject: 'body',
chunks: [`AdyenDemo${id}`],
chunksSortMode: 'manual'
});
};

const entriesReducer = (acc, { id }) => {
acc[`AdyenDemo${id}`] = path.join(__dirname, `../src/pages/${id}/${id}.js`);
Expand All @@ -42,7 +47,8 @@ module.exports = {
new webpack.DefinePlugin({
'process.env': {
__SF_ENV__: JSON.stringify(process.env.SF_ENV || 'build'),
__CLIENT_KEY__: JSON.stringify(process.env.CLIENT_KEY || null)
__CLIENT_KEY__: JSON.stringify(process.env.CLIENT_KEY || null),
__CLIENT_ENV__: JSON.stringify(process.env.CLIENT_ENV || 'test')
}
})
],
Expand Down
14 changes: 12 additions & 2 deletions packages/e2e-playwright/app/src/handlers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { makePayment, makeDetailsCall } from './services';
import { makePayment, makeDetailsCall, createOrder } from './services';

function removeComponent(component) {
component.remove();
}

function showAuthorised() {
export function showAuthorised() {
const resultElement = document.getElementById('result-message');
resultElement.classList.remove('hide');
resultElement.innerText = 'Authorised';
Expand Down Expand Up @@ -51,3 +51,13 @@ export function handleAdditionalDetails(details, component) {
throw Error(error);
});
}

export function handleOrderRequest(resolve, reject, data) {
return createOrder(data)
.then(response => {
resolve(response);
})
.catch(error => {
reject(error);
});
}
30 changes: 30 additions & 0 deletions packages/e2e-playwright/app/src/pages/ANCV/ANCV.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>Adyen Web | ANCV</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
</head>
<body>
<main>
<form class="merchant-checkout__form" method="post">
<div class="merchant-checkout__payment-method">
<div class="merchant-checkout__payment-method__header">
<h2>ANCV</h2>
</div>
<div class="merchant-checkout__payment-method__details">
<div class="ancv-field"></div>
<button id="ancv-pay-button" type="button">Pay</button>
</div>
</div>
</form>
<div id='result-message' class="merchant-checkout__result hide"></div>
</main>

<script type="text/javascript">
window.htmlPages = <%= JSON.stringify(htmlWebpackPlugin.htmlPages) || '' %>;
</script>
</body>
</html>
62 changes: 62 additions & 0 deletions packages/e2e-playwright/app/src/pages/ANCV/ANCV.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import AdyenCheckout from '@adyen/adyen-web';
import '@adyen/adyen-web/dist/es/adyen.css';
import { handleSubmit, handleAdditionalDetails, handleError, handleOrderRequest, showAuthorised } from '../../handlers';
import { amount, shopperLocale, countryCode } from '../../services/commonConfig';
import '../../style.scss';
import { createSession } from '../../services';

const initCheckout = async () => {
const successTestAmount = { currency: 'EUR', value: 2000 };

const session = await createSession({
amount: successTestAmount,
shopperLocale,
countryCode,
reference: 'mock-playwright',
returnUrl: 'http://localhost:3024/'
});

// console.log('env env', process.env.__CLIENT_ENV__);
// console.log('env key', process.env.__CLIENT_KEY__);
const checkout = await AdyenCheckout({
environment: process.env.__CLIENT_ENV__,
// environmentUrls: {
// api: process.env.__CLIENT_ENV__
// },
analytics: {
enabled: false
},
amount: successTestAmount,
session,
clientKey: process.env.__CLIENT_KEY__,
locale: shopperLocale,
countryCode,
showPayButton: false,
//onSubmit: handleSubmit,
//onOrderRequest: handleOrderRequest,
//onAdditionalDetails: handleAdditionalDetails,
onOrderCreated: data => {
console.log('=== onOrderCreated ===', data);

window.paymentMethod = checkout.create('card').mount('.ancv-field');
},
onPaymentCompleted: () => {
showAuthorised();
},
onError: handleError,
paymentMethodsConfiguration: {
ideal: {
highlightedIssuers: ['1121', '1154', '1153']
}
}
// ...window.mainConfiguration
});

window.paymentMethod = checkout.create('ancv').mount('.ancv-field');

document.querySelector('#ancv-pay-button').addEventListener('click', () => {
window.paymentMethod.submit();
});
};

initCheckout();
9 changes: 9 additions & 0 deletions packages/e2e-playwright/mocks/createOrder/createOrder.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { SESSION_DATA_MOCK, ORDER_DATA_MOCK } from '../../tests/utils/constants';

const orderCreatedMockData = {
orderData: ORDER_DATA_MOCK,
pspReference: 'MHCDBZCH4NF96292',
sessionData: SESSION_DATA_MOCK
};

export { orderCreatedMockData };
22 changes: 22 additions & 0 deletions packages/e2e-playwright/mocks/createOrder/createOrder.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Page } from '@playwright/test';

const ORDERS_URL = 'https://checkoutshopper-*.adyen.com/checkoutshopper/v1/sessions/*/orders?*';
const createOrderMock = async (page: Page, mockedResponse: any): Promise<void> => {
await page.route(ORDERS_URL, (route, request) => {
const requestData = JSON.parse(request.postData() || '');

route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
...mockedResponse,
requestId: requestData.requestId
}),
headers: {
'Access-Control-Allow-Origin': '*'
}
});
});
};

export { createOrderMock };
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { SESSION_DATA_MOCK, ORDER_DATA_MOCK } from '../../tests/utils/constants';

const paymentDetailsPartiallyAuthorisedAncvMockData = {
order: {
amount: {
currency: 'EUR',
value: 2001
},
expiresAt: '2023-10-10T13:12:59.00Z',
orderData: ORDER_DATA_MOCK,
pspReference: 'MHCDBZCH4NF96292',
reference: 'ABC123',
remainingAmount: {
currency: 'EUR',
value: 100
}
},
resultCode: 'PartiallyAuthorised',
sessionData: SESSION_DATA_MOCK
};

export { paymentDetailsPartiallyAuthorisedAncvMockData };
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Page } from '@playwright/test';

const PAYMENTS_URL = 'https://checkoutshopper-*.adyen.com/checkoutshopper/v1/sessions/*/paymentDetails?*';
const paymentDetailsMock = async (page: Page, mockedResponse: any): Promise<void> => {
await page.route(PAYMENTS_URL, (route, request) => {
const requestData = JSON.parse(request.postData() || '');

route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
...mockedResponse,
requestId: requestData.requestId
}),
headers: {
'Access-Control-Allow-Origin': '*'
}
});
});
};

export { paymentDetailsMock };
43 changes: 43 additions & 0 deletions packages/e2e-playwright/mocks/payments/payments.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { SESSION_DATA_MOCK, ORDER_DATA_MOCK, SESSION_RESULT_MOCK } from '../../tests/utils/constants';

const paymentsActionAncvMockData = {
action: {
paymentData: SESSION_DATA_MOCK,
paymentMethodType: 'ancv',
type: 'await'
},
order: {
amount: {
currency: 'EUR',
value: 2001
},
expiresAt: '2023-10-10T13:12:59.00Z',
orderData: ORDER_DATA_MOCK,
pspReference: 'MHCDBZCH4NF96292',
reference: 'ABC123'
},
resultCode: 'Pending',
sessionData: SESSION_DATA_MOCK,
sessionResult: SESSION_RESULT_MOCK
};

const paymentsSuccessCardMockData = {
order: {
amount: {
currency: 'EUR',
value: 2001
},
expiresAt: '2023-10-10T13:12:59.00Z',
pspReference: 'MHCDBZCH4NF96292',
reference: 'ABC123',
remainingAmount: {
currency: 'EUR',
value: 0
}
},
resultCode: 'Authorised',
sessionData: SESSION_DATA_MOCK,
sessionResult: SESSION_RESULT_MOCK
};

export { paymentsActionAncvMockData, paymentsSuccessCardMockData };
22 changes: 22 additions & 0 deletions packages/e2e-playwright/mocks/payments/payments.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Page } from '@playwright/test';

const PAYMENTS_URL = 'https://checkoutshopper-*.adyen.com/checkoutshopper/v1/sessions/*/payments?*';
const paymentsMock = async (page: Page, mockedResponse: any): Promise<void> => {
await page.route(PAYMENTS_URL, (route, request) => {
const requestData = JSON.parse(request.postData() || '');

route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
...mockedResponse,
requestId: requestData.requestId
}),
headers: {
'Access-Control-Allow-Origin': '*'
}
});
});
};

export { paymentsMock };
12 changes: 12 additions & 0 deletions packages/e2e-playwright/mocks/sessions/sessions.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { SESSION_DATA_MOCK } from '../../tests/utils/constants';

const sessionsMockData = {
amount: { currency: 'EUR', value: 2000 },
expiresAt: '2023-10-10T11:48:26+02:00',
id: 'CSFF69355B6EAD2F68',
merchantAccount: 'TestMerchantCheckout',
returnUrl: 'http://localhost:3024/',
shopperLocale: 'en-US',
sessionData: SESSION_DATA_MOCK
};
export { sessionsMockData };
23 changes: 23 additions & 0 deletions packages/e2e-playwright/mocks/sessions/sessions.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Page } from '@playwright/test';

const SESSION_URL = 'http://localhost:3024/sessions';

const sessionsMock = async (page: Page, mockedResponse: any): Promise<void> => {
await page.route(SESSION_URL, (route, request) => {
const requestData = JSON.parse(request.postData() || '');

route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
...mockedResponse,
requestId: requestData.requestId
}),
headers: {
'Access-Control-Allow-Origin': '*'
}
});
});
};

export { sessionsMock };
Loading

0 comments on commit 2b7a2c7

Please sign in to comment.