notifications-node-client
Advanced tools
Comparing version 8.0.0 to 8.1.0
@@ -0,1 +1,5 @@ | ||
## 8.1.0 - 2024-05-09 | ||
* The `sendEmail` function can now be passed `oneClickUnsubscribeURL` as an optional argument. | ||
## 8.0.0 - 2023-12-27 | ||
@@ -2,0 +6,0 @@ |
@@ -26,6 +26,7 @@ var ApiClient = require('./api_client'); | ||
* @param {String} replyToId | ||
* @param {String} oneClickUnsubscribeURL | ||
* | ||
* @returns {Object} | ||
*/ | ||
function createNotificationPayload(type, templateId, to, personalisation, reference, replyToId) { | ||
function createNotificationPayload(type, templateId, to, personalisation, reference, replyToId, oneClickUnsubscribeURL) { | ||
@@ -57,2 +58,6 @@ var payload = { | ||
if (oneClickUnsubscribeURL && type == 'email') { | ||
payload.one_click_unsubscribe_url = oneClickUnsubscribeURL; | ||
} | ||
return payload; | ||
@@ -149,3 +154,3 @@ } | ||
options = options || {}; | ||
var err = checkOptionsKeys(['personalisation', 'reference', 'emailReplyToId'], options) | ||
var err = checkOptionsKeys(['personalisation', 'reference', 'emailReplyToId', 'oneClickUnsubscribeURL'], options) | ||
if (err) { | ||
@@ -156,6 +161,7 @@ return Promise.reject(err); | ||
reference = options.reference || undefined, | ||
emailReplyToId = options.emailReplyToId || undefined; | ||
emailReplyToId = options.emailReplyToId || undefined, | ||
oneClickUnsubscribeURL = options.oneClickUnsubscribeURL || undefined; | ||
return this.apiClient.post('/v2/notifications/email', | ||
createNotificationPayload('email', templateId, emailAddress, personalisation, reference, emailReplyToId)); | ||
createNotificationPayload('email', templateId, emailAddress, personalisation, reference, emailReplyToId, oneClickUnsubscribeURL)); | ||
}, | ||
@@ -162,0 +168,0 @@ |
{ | ||
"name": "notifications-node-client", | ||
"version": "8.0.0", | ||
"version": "8.1.0", | ||
"homepage": "https://docs.notifications.service.gov.uk/node.html", | ||
@@ -39,2 +39,1 @@ "repository": { | ||
} | ||
@@ -28,3 +28,4 @@ { | ||
"from_email": {"type": "string", "format": "email_address"}, | ||
"subject": {"type": "string"} | ||
"subject": {"type": "string"}, | ||
"one_click_unsubscribe_url": {"type": ["string", "null"], "format": "uri"} | ||
}, | ||
@@ -31,0 +32,0 @@ "required": ["body", "from_email", "subject"] |
@@ -39,2 +39,3 @@ const fs = require('fs'); | ||
const clientRef = 'client-ref'; | ||
const oneClickUnsubscribeURL = 'https://www.example.com'; | ||
const email = process.env.FUNCTIONAL_TEST_EMAIL; | ||
@@ -92,2 +93,3 @@ const phoneNumber = process.env.FUNCTIONAL_TEST_NUMBER; | ||
response.data.content.subject.should.equal('Functional Tests are good'); | ||
should.equal(response.data.content.one_click_unsubscribe_url, null); | ||
response.data.reference.should.equal(clientRef); | ||
@@ -98,2 +100,17 @@ emailNotificationId = response.data.id; | ||
it('send email notification with unsubscribe link', () => { | ||
var postEmailNotificationResponseJson = require('./schemas/v2/POST_notification_email_response.json'), | ||
options = {personalisation: personalisation, reference: clientRef, oneClickUnsubscribeURL: oneClickUnsubscribeURL}; | ||
return notifyClient.sendEmail(emailTemplateId, email, options).then((response) => { | ||
response.status.should.equal(201); | ||
expect(response.data).to.be.jsonSchema(postEmailNotificationResponseJson); | ||
response.data.content.body.should.equal('Hello Foo\r\n\r\nFunctional test help make our world a better place'); | ||
response.data.content.subject.should.equal('Functional Tests are good'); | ||
response.data.content.one_click_unsubscribe_url.should.equal(oneClickUnsubscribeURL); | ||
response.data.reference.should.equal(clientRef); | ||
emailNotificationId = response.data.id; | ||
}) | ||
}); | ||
it('send email notification with document upload', () => { | ||
@@ -100,0 +117,0 @@ var postEmailNotificationResponseJson = require('./schemas/v2/POST_notification_email_response.json'), |
@@ -95,2 +95,27 @@ const chai = require('chai'); | ||
it('should send an email with a one click unsubscribe URL', () => { | ||
let email = 'me@example.com', | ||
templateId = '123', | ||
options = { | ||
personalisation: {foo: 'bar'}, | ||
oneClickUnsubscribeURL: '456', | ||
}, | ||
data = { | ||
template_id: templateId, | ||
email_address: email, | ||
personalisation: options.personalisation, | ||
one_click_unsubscribe_url: options.oneClickUnsubscribeURL | ||
}; | ||
notifyAuthNock | ||
.post('/v2/notifications/email', data) | ||
.reply(200, {hooray: 'bkbbk'}); | ||
return notifyClient.sendEmail(templateId, email, options) | ||
.then((response) => { | ||
expect(response.status).to.equal(200); | ||
}); | ||
}); | ||
it('should send an email with document upload', () => { | ||
@@ -97,0 +122,0 @@ let email = 'dom@example.com', |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
182767
2091