-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add test failing webhook * Add test successful webhook * Add uuid * Add test to receive and display the token * Rename file * Correct expectation
- Loading branch information
Showing
5 changed files
with
309 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// @ts-check | ||
const { test, expect } = require('@playwright/test'); | ||
const utilities = require('../utilities'); | ||
|
||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
|
||
// test RecurringDetailReference is displayed in the Admin panel | ||
test('Display RecurringDetailReference', async ({ request, page }) => { | ||
|
||
var shopperReference = uuidv4(); | ||
var token = uuidv4(); | ||
|
||
// send webhook with RECURRING_CONTRACT event | ||
var notificationRequestItem = { | ||
"eventCode": "RECURRING_CONTRACT", | ||
"eventDate": "2023-06-20T16:09:48+02:00", | ||
"merchantAccountCode": "YOUR_MERCHANT_ACCOUNT", | ||
"merchantReference": "YOUR_PAYMENT_REFERENCE", | ||
"originalReference": "INITIAL_PAYMENT_PSP_REFERENCE", | ||
"originalPsp": "PSP_REFERENCE", | ||
"paymentMethod": "mc", | ||
"amount": { | ||
"value": 0, | ||
"currency": "EUR" | ||
}, | ||
"success": "true", | ||
}; | ||
|
||
// calculate signature from payload | ||
const hmacSignature = await utilities.calculateHmacSignature(notificationRequestItem); | ||
// add 'additionalData' with hmacSignature | ||
notificationRequestItem["additionalData"] = { | ||
"hmacSignature": "" + hmacSignature + "", | ||
"recurring.recurringDetailReference": token, | ||
"recurring.shopperReference": shopperReference, | ||
"shopperReference": "YOUR_SHOPPER_REFERENCE" | ||
} | ||
|
||
// POST webhook | ||
const notifications = await request.post(`/api/webhooks/notifications`, { | ||
data: { | ||
"live": "false", | ||
"notificationItems": [ | ||
{ | ||
"NotificationRequestItem": notificationRequestItem | ||
} | ||
] | ||
} | ||
}); | ||
|
||
// Verify status code | ||
expect(notifications.status()).toEqual(200); | ||
|
||
// Verify token is visible in the Admin panel | ||
await page.goto('/admin'); | ||
|
||
await expect(page).toHaveTitle("Adyen Subscription Admin View"); | ||
await expect(page.locator('text="ADMIN PANEL"')).toBeVisible(); | ||
|
||
await expect(page.locator('text="ShopperReference: ' + shopperReference + '"')).toBeVisible(); | ||
await expect(page.locator('text="RecurringDetailReference: ' + token + '"')).toBeVisible(); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// @ts-check | ||
const { test, expect } = require('@playwright/test'); | ||
|
||
test('Webhook failure', async ({ request }) => { | ||
const notifications = await request.post(`/api/webhooks/notifications`, { | ||
data: { | ||
"live": "false", | ||
"notificationItems": [ | ||
{ | ||
"NotificationRequestItem": { | ||
"additionalData": { | ||
"hmacSignature": "INVALID_HMAC_SIGNATURE", | ||
"recurring.recurringDetailReference": "XXXXXXXXX", | ||
"recurring.shopperReference": "UniqueShopperReference" | ||
}, | ||
"eventCode": "AUTHORISATION", | ||
"success": "true", | ||
"eventDate": "2019-06-28T18:03:50+01:00", | ||
"merchantAccountCode": "YOUR_MERCHANT_ACCOUNT", | ||
"pspReference": "7914073381342284", | ||
"merchantReference": "YOUR_REFERENCE", | ||
"amount": { | ||
"value": 0, | ||
"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]"); }); | ||
}); |
Oops, something went wrong.