Skip to content

Commit

Permalink
Add E2E tests for authorisation adjustment (#39)
Browse files Browse the repository at this point in the history
* Updated E2E tests to contain card success and failure scenario

---------

Co-authored-by: Kwok He Chu <>
  • Loading branch information
Kwok-he-Chu authored Aug 2, 2023
1 parent 6169596 commit dc8e37a
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/authorisation-adjustment/admin-panel.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @ts-check
const { test, expect } = require('@playwright/test');

test('Admin Panel', async ({ page }) => {
await page.goto('/admin');

await expect(page).toHaveTitle("Adyen Admin Panel");
await expect(page.locator('text="ADMIN PANEL"')).toBeVisible();
});
44 changes: 44 additions & 0 deletions tests/authorisation-adjustment/card-authorised.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// @ts-check
const { test, expect } = require('@playwright/test');

test('Card Authorised', async ({ page }) => {
await page.goto('/');

await expect(page).toHaveTitle(/Booking View/);

// Select "Click here to start a hotel booking"
await page.getByRole('link', { name: 'Click here to start a hotel booking', exact: true }).click();

// Click "Continue to confirm booking"
await page.getByRole('link', { name: 'Continue to confirm booking' }).click();

// Wait for network state to be idle
await page.waitForLoadState('networkidle');

// Assert that "Card number" is visible within iframe
await expect(page.locator('text="Card number"')).toBeVisible();

// Find iframe and fill "Card number" field
const cardNumberFrame = await page.frameLocator('iframe[title*="card number"]');
await cardNumberFrame.getByPlaceholder('1234 5678 9012 3456').fill('4166 6766 6766 6746');

// Find iframe and fill "Expiry date" field
const expiryDateFrame = await page.frameLocator('iframe[title*="expiry date"]');
await expiryDateFrame.getByPlaceholder('MM/YY').fill('03/30');

// Find iframe and fill "CVC / CVV" field
const cvcFrame = await page.frameLocator('iframe[title*="security code"]');
await cvcFrame.getByPlaceholder('3 digits').fill('737');

// Find and fill "Name on card" field - Note: this field is not contained within an iframe
await page.getByPlaceholder('J. Smith').fill('J. Smith');

// Click "Pay" button
const payButton = page.locator('.adyen-checkout__button__text >> visible=true');
await expect(payButton).toBeVisible();
await payButton.click();

// Verify "authorised" text to be visible
await expect(page.locator('text=/authorised/')).toBeVisible();
await expect(page.locator('text="Return to Booking View"')).toBeVisible();
});
46 changes: 46 additions & 0 deletions tests/authorisation-adjustment/card-refused.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// @ts-check
const { test, expect } = require('@playwright/test');

test('Card Refused', async ({ page }) => {
await page.goto('/');

await expect(page).toHaveTitle(/Booking View/);

// Select "Click here to start a hotel booking"
await page.getByRole('link', { name: 'Click here to start a hotel booking', exact: true }).click();

// Click "Continue to confirm booking"
await page.getByRole('link', { name: 'Continue to confirm booking' }).click();

// Wait for network state to be idle
await page.waitForLoadState('networkidle');

// Assert that "Card number" is visible within iframe
await expect(page.locator('text="Card number"')).toBeVisible();

// Find iframe and fill "Card number" field
const cardNumberFrame = await page.frameLocator('iframe[title*="card number"]');
await cardNumberFrame.getByPlaceholder('1234 5678 9012 3456').fill('4166 6766 6766 6746');

// Find iframe and fill "Expiry date" field
const expiryDateFrame = await page.frameLocator('iframe[title*="expiry date"]');
await expiryDateFrame.getByPlaceholder('MM/YY').fill('03/30');

// Find iframe and fill "CVC / CVV" field
const cvcFrame = await page.frameLocator('iframe[title*="security code"]');
await cvcFrame.getByPlaceholder('3 digits').fill('737');

// https://docs.adyen.com/development-resources/testing/result-code-testing/testing-with-card-holder-name/#payment-result
// Find and fill "Name on card" field with "capture failed" to trigger fail scenario - Note: this field is not contained within an iframe
await page.getByPlaceholder('J. Smith').fill('DECLINED');

// Click "Pay" button
const payButton = page.locator('.adyen-checkout__button__text >> visible=true');
await expect(payButton).toBeVisible();
await payButton.click();

// Verify "refused" text to be visible
await expect(page.locator('text=/refused/')).toBeVisible();

await expect(page.locator('text="Return to Booking View"')).toBeVisible();
});
41 changes: 41 additions & 0 deletions tests/authorisation-adjustment/webhook.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// @ts-check
const { test, expect } = require('@playwright/test');

test('Webhook Notification', async ({ request }) => {
const notifications = await request.post(`/api/webhooks/notifications`, {
data: {
"live": "false",
"notificationItems":[
{
"NotificationRequestItem":{
"additionalData":{
"hmacSignature":"+JWKfq4ynALK+FFzGgHnp1jSMQJMBJeb87dlph24sXw="
},
"eventCode":"AUTHORISATION",
"success":"true",
"eventDate":"2019-06-28T18:03:50+01:00",
"merchantAccountCode":"YOUR_MERCHANT_ACCOUNT",
"pspReference": "7914073381342284",
"merchantReference": "YOUR_REFERENCE",
"amount": {
"value":24999,
"currency":"EUR"
}
}
}
]
}
});

/// Verify notification is not accepted (invalid HMAC)

// Status code not 404 (verify webhook is found)
expect(notifications.status()).not.toEqual(404);

// Status code not 200 (verify webhook does not accept the notification ie HMAC invalid)
expect(notifications.status()).not.toEqual(200);

// Body response does not contain [accepted]
notifications.text()
.then(value => {expect(value).not.toEqual("[accepted]");} );
});

0 comments on commit dc8e37a

Please sign in to comment.