Socket
Socket
Sign inDemoInstall

notifications-node-client

Package Overview
Dependencies
72
Maintainers
4
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.1.0 to 4.2.0

DOCUMENTATION.md

7

CHANGELOG.md

@@ -0,1 +1,8 @@

## [4.2.0] - 2018-07-24
### Changed
* Added `created_by_name` to the response for `.getNotificationById()` and `.getNotifications()`:
* If the notification was sent manually this will be the name of the sender. If the notification was sent through the API this will be `null`.
## [4.1.0] - 2017-11-23

@@ -2,0 +9,0 @@

2

client/api_client.js

@@ -103,3 +103,3 @@ var restClient = require('request-promise'),

};
if(this.proxy !== null) options.proxy = this.proxy;

@@ -106,0 +106,0 @@

@@ -40,9 +40,7 @@ var ApiClient = require('./api_client'),

payload.phone_number = to;
}
}
if (type == 'letter') {
if (type == 'letter' || personalisation) {
// personalisation mandatory for letters
payload.personalisation = personalisation;
} else if (!!personalisation) {
payload.personalisation = personalisation;
}

@@ -74,3 +72,3 @@

payload = {}
let payload = {}

@@ -99,3 +97,3 @@ if (templateType) {

return [key, dictionary[key]].map(encodeURIComponent).join("=");
}).join("&");
}).join('&');

@@ -105,2 +103,17 @@ return queryString ? '?' + queryString : '';

function checkOptionsKeys(allowedKeys, options) {
let invalidKeys = Object.keys(options).filter((key_name) =>
!allowedKeys.includes(key_name)
);
if (invalidKeys.length) {
let err_msg = (
'NotifyClient now uses an options configuration object. Options ' + JSON.stringify(invalidKeys) +
' not recognised. Please refer to the README.md for more information on method signatures.'
)
return new Error(err_msg);
}
return null;
}
_.extend(NotifyClient.prototype, {

@@ -128,4 +141,8 @@ /**

sendEmail: function (templateId, emailAddress, options) {
var options = options || {},
personalisation = options.personalisation || undefined,
options = options || {};
var err = checkOptionsKeys(['personalisation', 'reference', 'emailReplyToId'], options)
if (err) {
return Promise.reject(err);
}
var personalisation = options.personalisation || undefined,
reference = options.reference || undefined,

@@ -147,3 +164,8 @@ emailReplyToId = options.emailReplyToId || undefined;

sendSms: function (templateId, phoneNumber, options) {
var options = options || {};
options = options || {};
var err = checkOptionsKeys(['personalisation', 'reference', 'smsSenderId'], options)
if (err) {
return Promise.reject(err);
}
var personalisation = options.personalisation || undefined;

@@ -165,3 +187,7 @@ var reference = options.reference || undefined;

sendLetter: function (templateId, options) {
var options = options || {};
options = options || {};
var err = checkOptionsKeys(['personalisation', 'reference'], options)
if (err) {
return Promise.reject(err);
}
var personalisation = options.personalisation || undefined;

@@ -226,3 +252,3 @@ var reference = options.reference || undefined;

getAllTemplates: function(templateType) {
templateQuery = ''
let templateQuery = ''

@@ -245,5 +271,5 @@ if (templateType) {

payload = {}
let payload = {}
if (!!personalisation) {
if (personalisation) {
payload.personalisation = personalisation;

@@ -250,0 +276,0 @@ }

{
"name": "notifications-node-client",
"version": "4.1.0",
"version": "4.2.0",
"description": "GOV.UK Notify Node.js client ",

@@ -13,17 +13,17 @@ "main": "index.js",

"dependencies": {
"jsonwebtoken": "7.4.1",
"request": "^2.73.0",
"request-promise": "^4.0.1",
"underscore": "^1.8.3"
"jsonwebtoken": "8.2.1",
"request": "2.87.0",
"request-promise": "4.2.2",
"underscore": "^1.9.0"
},
"devDependencies": {
"chai": "3.4.1",
"chai-as-promised": "^5.3.0",
"chai-json-schema": "^1.3.0",
"jsonschema": "^1.1.0",
"mocha": "2.3.4",
"mockdate": "1.0.3",
"nock": "8.0.0",
"optimist": "^0.6.1"
"chai": "4.1.2",
"chai-as-promised": "7.1.1",
"chai-json-schema": "1.5.0",
"jsonschema": "1.2.4",
"mocha": "5.2.0",
"mockdate": "2.0.2",
"nock": "9.2.6",
"optimist": "0.6.1"
}
}

@@ -43,3 +43,3 @@ # GOV.UK Notify Node.js client

#### Method
#### Method

@@ -53,3 +53,6 @@ <details>

notifyClient
.sendSms(templateId, phoneNumber, personalisation, reference, smsSenderId)
.sendSms(templateId, phoneNumber, {
personalisation: personalisation,
reference: reference,
smsSenderId: smsSenderId})
.then(response => console.log(response))

@@ -114,3 +117,4 @@ .catch(err => console.error(err))

##### `reference`
##### `options`
###### `reference`

@@ -132,3 +136,3 @@ An optional identifier you generate. The `reference` can be used as a unique reference for the notification. Because Notify does not require this reference to be unique you could also use this reference to identify a batch or group of notifications.

If you are not using the `smsSenderId` argument, this parameter can be omitted. Otherwise `undefined` should be passed in its place.
This does not need to be provided if your template does not contain placeholders.

@@ -141,22 +145,4 @@ ##### `smsSenderId`

If other optional arguments before `smsSenderId` are not in use they need to be set to `undefined`.
Example usage with optional reference -
```
sendSms('123', '+447900900123', undefined, 'your ref', '465')
```
Example usage with optional personalisation -
```
sendSms('123', '+447900900123', '{"name": "test"}', undefined, '465')
```
Example usage with only optional `smsSenderId` set -
```
sendSms('123', '+447900900123', undefined, undefined, '465')
```
</details>

@@ -176,3 +162,6 @@

notifyClient
.sendEmail(templateId, emailAddress, personalisation, reference, emailReplyToId)
.sendEmail(templateId, emailAddress, {
personalisation: personalisation,
reference: reference,
emailReplyToId: emailReplyToId})
.then(response => console.log(response))

@@ -239,3 +228,4 @@ .catch(err => console.error(err))

##### `reference`
##### `options`
###### `reference`

@@ -246,4 +236,10 @@ An optional identifier you generate. The `reference` can be used as a unique reference for the notification. Because Notify does not require this reference to be unique you could also use this reference to identify a batch or group of notifications.

##### `personalisation`
###### `emailReplyToId`
Optional. Specifies the identifier of the email reply-to address to set for the notification. The identifiers are found in your service Settings, when you 'Manage' your 'Email reply to addresses'.
If you omit this argument your default email reply-to address will be set for the notification.
###### `personalisation`
If a template has placeholders, you need to provide their values, for example:

@@ -260,19 +256,5 @@

Optional. Specifies the identifier of the email reply-to address to set for the notification. The identifiers are found in your service Settings, when you 'Manage' your 'Email reply to addresses'.
Optional. Specifies the identifier of the email reply-to address to set for the notification. The identifiers are found in your service Settings, when you 'Manage' your 'Email reply to addresses'.
If you omit this argument your default email reply-to address will be set for the notification.
If other optional arguments before `emailReplyToId` are not in use they need to be set to `undefined`.
Example usage with optional reference -
```
sendEmail('123', 'test@gov.uk', undefined, 'your ref', '465')
```
Example usage with optional personalisation -
```
sendEmail('123', 'test@gov.uk', '{"name": "test"}', undefined, '465')
```
Example usage with only optional `emailReplyToId` set -
```
sendEmail('123', 'test@gov.uk', undefined, undefined, '465')
```
</details>

@@ -292,3 +274,5 @@

notifyClient
.sendLetter(templateId, personalisation, reference)
.sendLetter(templateId, {
personalisation: personalisation,
reference: reference})
.then(response => console.log(response))

@@ -303,8 +287,8 @@ .catch(err => console.error object)

personalisation={
'address_line_1': 'The Occupier', # required
'address_line_2': '123 High Street', # required
'address_line_3': 'London',
'postcode': 'SW14 6BH', # required
address_line_1: 'The Occupier', // required
address_line_2: '123 High Street', // required
address_line_3: 'London',
postcode: 'SW14 6BH', // required
... # any other optional address lines, or personalisation fields found in your template
// ... any other optional address lines, or personalisation fields found in your template
},

@@ -382,11 +366,11 @@ ```

personalisation={
'address_line_1': 'The Occupier', # mandatory address field
'address_line_2': 'Flat 2', # mandatory address field
'address_line_3': '123 High Street', # optional address field
'address_line_4': 'Richmond upon Thames', # optional address field
'address_line_5': 'London', # optional address field
'address_line_6': 'Middlesex', # optional address field
'postcode': 'SW14 6BH', # mandatory address field
'application_id': '1234', # field from template
'application_date': '2017-01-01', # field from template
address_line_1: 'The Occupier', // mandatory address field
address_line_2: 'Flat 2', // mandatory address field
address_line_3: '123 High Street', // optional address field
address_line_4: 'Richmond upon Thames', // optional address field
address_line_5: 'London', // optional address field
address_line_6: 'Middlesex', // optional address field
postcode: 'SW14 6BH', // mandatory address field
application_id: '1234', // field from template
application_date: '2017-01-01', // field from template
}

@@ -449,2 +433,3 @@ ```

},
"created_by_name": "name of the person who sent the notification if sent manually",
"created_at": "created at",

@@ -526,2 +511,3 @@ "sent_at": "sent to provider at",

},
"created_by_name": "name of the person who sent the notification if sent manually",
"created_at": "created at",

@@ -612,3 +598,3 @@ "sent_at": "sent to provider at",

#### Method
#### Method

@@ -981,5 +967,1 @@ <details>

```

@@ -24,2 +24,3 @@ {

"created_at": {"type": "string"},
"created_by_name": {"type": ["string", "null"]},
"sent_at": {"type": ["string", "null"]},

@@ -35,4 +36,4 @@ "completed_at": {"type": ["string", "null"]},

"line_1", "line_2", "line_3", "line_4", "line_5", "line_6", "postcode",
"type", "status", "template", "created_at", "sent_at", "completed_at"
"type", "status", "template", "created_at", "created_by_name", "sent_at", "completed_at"
]
}

@@ -23,2 +23,2 @@ {

"additionalProperties": false
}
}

@@ -29,2 +29,2 @@ {

"additionalProperties": false
}
}

@@ -25,3 +25,6 @@ const NotifyClient = require('../../client/notification.js').NotifyClient;

describer('notification api with a live service', () => {
describer('notification api with a live service', function () {
// default is 2000 (ms) - api is sometimes slower than this :(
this.timeout(10000)
let notifyClient;

@@ -36,3 +39,3 @@ let whitelistNotifyClient;

const phoneNumber = process.env.FUNCTIONAL_TEST_NUMBER;
const letterContact = {
const letterContact = {
address_line_1: make_random_id(),

@@ -100,3 +103,3 @@ address_line_2: 'Foo',

expect(response.body).to.be.jsonSchema(postSmsNotificationResponseJson);
response.body.content.body.should.equal('Hello Foo\r\n\r\nFunctional Tests make our world a better place');
response.body.content.body.should.equal('Hello Foo\n\nFunctional Tests make our world a better place');
smsNotificationId = response.body.id;

@@ -114,3 +117,3 @@ });

expect(response.body).to.be.jsonSchema(postSmsNotificationResponseJson);
response.body.content.body.should.equal('Hello Foo\r\n\r\nFunctional Tests make our world a better place');
response.body.content.body.should.equal('Hello Foo\n\nFunctional Tests make our world a better place');
smsNotificationId = response.body.id;

@@ -152,3 +155,3 @@ });

response.body.type.should.equal('sms');
response.body.body.should.equal('Hello Foo\r\n\r\nFunctional Tests make our world a better place');
response.body.body.should.equal('Hello Foo\n\nFunctional Tests make our world a better place');
});

@@ -236,7 +239,6 @@ });

it('get all templates', (done) => {
it('get all templates', () => {
return notifyClient.getAllTemplates().then((response) => {
response.statusCode.should.equal(200);
expect(response.body).to.be.jsonSchema(getTemplatesJson);
done();
});

@@ -296,3 +298,3 @@ });

it('get all received texts', (done) => {
it('get all received texts', () => {
chai.tv4.addSchema('receivedText.json', getReceivedTextJson);

@@ -303,3 +305,2 @@ return receivedTextClient.getReceivedTexts().then((response) => {

expect(response.body["received_text_messages"]).to.be.an('array').that.is.not.empty;
done();
});

@@ -306,0 +307,0 @@ });

@@ -1,5 +0,6 @@

var expect = require('chai').expect, NotifyClient = require('../client/notification.js').NotifyClient,
MockDate = require('mockdate'),
nock = require('nock'),
createGovukNotifyToken = require('../client/authentication.js');
let expect = require('chai').expect,
NotifyClient = require('../client/notification.js').NotifyClient,
MockDate = require('mockdate'),
nock = require('nock'),
createGovukNotifyToken = require('../client/authentication.js');

@@ -13,397 +14,429 @@ MockDate.set(1234567890000);

function getNotifyClient() {
var baseUrl = 'http://localhost';
var notifyClient = new NotifyClient(baseUrl, serviceId, apiKeyId);
return notifyClient;
let baseUrl = 'http://localhost';
let notifyClient = new NotifyClient(baseUrl, serviceId, apiKeyId);
return notifyClient;
}
function getNotifyAuthNock() {
var notifyNock = nock(baseUrl, {
reqheaders: {
'Authorization': 'Bearer ' + createGovukNotifyToken('POST', '/v2/notifications/', apiKeyId, serviceId)
}
})
return notifyNock;
let notifyNock = nock(baseUrl, {
reqheaders: {
'Authorization': 'Bearer ' + createGovukNotifyToken('POST', '/v2/notifications/', apiKeyId, serviceId)
}
})
return notifyNock;
}
describe('notification api', function() {
describe('notification api', () => {
beforeEach(function() {
MockDate.set(1234567890000);
});
beforeEach(() => {
MockDate.set(1234567890000);
});
afterEach(function() {
MockDate.reset();
});
afterEach(() => {
MockDate.reset();
});
var notifyClient = getNotifyClient();
var notifyAuthNock = getNotifyAuthNock();
let notifyClient = getNotifyClient();
let notifyAuthNock = getNotifyAuthNock();
it('should send an email', function(done) {
describe('sendEmail', () => {
it('should send an email', () => {
var email = 'dom@example.com',
templateId = '123',
options = {
personalisation: {foo: 'bar'},
},
data = {
template_id: templateId,
email_address: email,
personalisation: options.personalisation
};
let email = 'dom@example.com',
templateId = '123',
options = {
personalisation: {foo: 'bar'},
},
data = {
template_id: templateId,
email_address: email,
personalisation: options.personalisation
};
notifyAuthNock
.post('/v2/notifications/email', data)
.reply(200, {"hooray": "bkbbk"});
notifyAuthNock
.post('/v2/notifications/email', data)
.reply(200, {hooray: 'bkbbk'});
notifyClient.sendEmail(templateId, email, options)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
return notifyClient.sendEmail(templateId, email, options)
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
it('should send an email with email_reply_to_id', function(done) {
var email = 'dom@example.com',
templateId = '123',
options = {
personalisation: {foo: 'bar'},
emailReplyToId: '456',
},
data = {
template_id: templateId,
email_address: email,
personalisation: options.personalisation,
email_reply_to_id: options.emailReplyToId
};
it('should send an email with email_reply_to_id', () => {
notifyAuthNock
.post('/v2/notifications/email', data)
.reply(200, {"hooray": "bkbbk"});
let email = 'dom@example.com',
templateId = '123',
options = {
personalisation: {foo: 'bar'},
emailReplyToId: '456',
},
data = {
template_id: templateId,
email_address: email,
personalisation: options.personalisation,
email_reply_to_id: options.emailReplyToId
};
notifyClient.sendEmail(templateId, email, options)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
notifyAuthNock
.post('/v2/notifications/email', data)
.reply(200, {hooray: 'bkbbk'});
return notifyClient.sendEmail(templateId, email, options)
.then((response) => {
expect(response.statusCode).to.equal(200);
});
});
it('should send an sms', function(done) {
it('should reject options dicts with unknown options', () => {
let email = 'foo@bar.com',
templateId = '123',
// old personalisation dict
options = {
firstname: 'Fred',
surname: 'Smith',
reference: 'ABC123'
};
return notifyClient.sendEmail(templateId, email, options)
.catch((err) => expect(err.message).to.include('["firstname","surname"]'));
});
});
var phoneNo = '07525755555',
templateId = '123',
options = {
personalisation: {foo: 'bar'},
},
data = {
template_id: templateId,
phone_number: phoneNo,
personalisation: options.personalisation
};
describe('sendSms', () => {
notifyAuthNock
.post('/v2/notifications/sms', data)
.reply(200, {"hooray": "bkbbk"});
it('should send an sms', () => {
notifyClient.sendSms(templateId, phoneNo, options)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
let phoneNo = '07525755555',
templateId = '123',
options = {
personalisation: {foo: 'bar'},
},
data = {
template_id: templateId,
phone_number: phoneNo,
personalisation: options.personalisation
};
notifyAuthNock
.post('/v2/notifications/sms', data)
.reply(200, {hooray: 'bkbbk'});
return notifyClient.sendSms(templateId, phoneNo, options)
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
it('should send an sms with smsSenderId', function(done) {
it('should send an sms with smsSenderId', () => {
var phoneNo = '07525755555',
templateId = '123',
options = {
personalisation: {foo: 'bar'},
smsSenderId: '456',
},
data = {
template_id: templateId,
phone_number: phoneNo,
personalisation: options.personalisation,
sms_sender_id: options.smsSenderId,
};
let phoneNo = '07525755555',
templateId = '123',
options = {
personalisation: {foo: 'bar'},
smsSenderId: '456',
},
data = {
template_id: templateId,
phone_number: phoneNo,
personalisation: options.personalisation,
sms_sender_id: options.smsSenderId,
};
notifyAuthNock
.post('/v2/notifications/sms', data)
.reply(200, {"hooray": "bkbbk"});
notifyAuthNock
.post('/v2/notifications/sms', data)
.reply(200, {hooray: 'bkbbk'});
notifyClient.sendSms(templateId, phoneNo, options)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
return notifyClient.sendSms(templateId, phoneNo, options)
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
it('should send a letter', function(done) {
var templateId = '123',
options = {
personalisation: {
address_line_1: 'Mr Tester',
address_line_2: '1 Test street',
postcode: 'NW1 2UN'
},
it('should reject options dicts with unknown options', () => {
let phoneNumber = '07123456789',
templateId = '123',
// old personalisation dict
options = {
firstname: 'Fred',
surname: 'Smith',
reference: 'ABC123'
};
return notifyClient.sendSms(templateId, phoneNumber, options)
.catch((err) => expect(err.message).to.include('["firstname","surname"]'));
});
});
describe('sendLetter', () => {
it('should send a letter', () => {
let templateId = '123',
options = {
personalisation: {
address_line_1: 'Mr Tester',
address_line_2: '1 Test street',
postcode: 'NW1 2UN'
},
data = {
template_id: templateId,
personalisation: options.personalisation
};
},
data = {
template_id: templateId,
personalisation: options.personalisation
};
notifyAuthNock
.post('/v2/notifications/letter', data)
.reply(200, {"hooray": "bkbbk"});
notifyAuthNock
.post('/v2/notifications/letter', data)
.reply(200, {hooray: 'bkbbk'});
notifyClient.sendLetter(templateId, options)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
return notifyClient.sendLetter(templateId, options)
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
it('should get notification by id', function(done) {
it('should reject options dicts with unknown options', () => {
let templateId = '123',
// old personalisation dict
options = {
address_line_1: 'Mr Tester',
address_line_2: '1 Test street',
postcode: 'NW1 2UN',
reference: 'ABC123'
};
return notifyClient.sendLetter(templateId, options)
.catch((err) => expect(err.message).to.include('["address_line_1","address_line_2","postcode"]'));
});
var baseUrl = 'http://localhost',
notificationId = 'wfdfdgf';
});
notifyAuthNock
.get('/v2/notifications/' + notificationId)
.reply(200, {"hooray": "bkbbk"});
it('should get notification by id', () => {
notifyClient.getNotificationById(notificationId)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
});
let notificationId = 'wfdfdgf';
it('should get all notifications', function(done) {
notifyAuthNock
.get('/v2/notifications/' + notificationId)
.reply(200, {hooray: 'bkbbk'});
notifyAuthNock
.get('/v2/notifications')
.reply(200, {"hooray": "bkbbk"});
return notifyClient.getNotificationById(notificationId)
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
notifyClient.getNotifications()
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
describe('getNotifications', () => {
it('should get all notifications', () => {
notifyAuthNock
.get('/v2/notifications')
.reply(200, {hooray: 'bkbbk'});
return notifyClient.getNotifications()
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
it('should get all notifications with a reference', function(done) {
it('should get all notifications with a reference', () => {
var reference = 'myref'
let reference = 'myref';
notifyAuthNock
.get('/v2/notifications?reference=' + reference)
.reply(200, {"hooray": "bkbbk"});
notifyAuthNock
.get('/v2/notifications?reference=' + reference)
.reply(200, {hooray: 'bkbbk'});
notifyClient.getNotifications(undefined, undefined, reference)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
return notifyClient.getNotifications(undefined, undefined, reference)
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
it('should get all failed notifications', function(done) {
it('should get all failed notifications', () => {
var status = 'failed';
let status = 'failed';
notifyAuthNock
.get('/v2/notifications?status=' + status)
.reply(200, {"hooray": "bkbbk"});
notifyAuthNock
.get('/v2/notifications?status=' + status)
.reply(200, {hooray: 'bkbbk'});
notifyClient.getNotifications(undefined, 'failed')
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
return notifyClient.getNotifications(undefined, 'failed')
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
it('should get all failed sms notifications', function(done) {
it('should get all failed sms notifications', () => {
var templateType = 'sms'
status = 'failed';
let templateType = 'sms';
let status = 'failed';
notifyAuthNock
.get('/v2/notifications?template_type=' + templateType + '&status=' + status)
.reply(200, {"hooray": "bkbbk"});
notifyAuthNock
.get('/v2/notifications?template_type=' + templateType + '&status=' + status)
.reply(200, {hooray: 'bkbbk'});
notifyClient.getNotifications(templateType, status)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
return notifyClient.getNotifications(templateType, status)
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
it('should get all delivered sms notifications with a reference', function(done) {
it('should get all delivered sms notifications with a reference', () => {
var templateType = 'sms'
status = 'delivered';
reference = 'myref'
let templateType = 'sms';
let status = 'delivered';
let reference = 'myref';
notifyAuthNock
.get('/v2/notifications?template_type=' + templateType + '&status=' + status + '&reference=' + reference)
.reply(200, {"hooray": "bkbbk"});
notifyAuthNock
.get('/v2/notifications?template_type=' + templateType + '&status=' + status + '&reference=' + reference)
.reply(200, {hooray: 'bkbbk'});
notifyClient.getNotifications(templateType, status, reference)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
return notifyClient.getNotifications(templateType, status, reference)
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
it('should get all failed email notifications with a reference older than a given notification', function(done) {
it('should get all failed email notifications with a reference older than a given notification', () => {
var templateType = 'sms';
status = 'delivered';
reference = 'myref';
olderThanId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
let templateType = 'sms';
let status = 'delivered';
let reference = 'myref';
let olderThanId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
notifyAuthNock
.get('/v2/notifications?template_type=' + templateType +
'&status=' + status +
'&reference=' + reference +
'&older_than=' + olderThanId
)
.reply(200, {"hooray": "bkbbk"});
notifyAuthNock
.get('/v2/notifications?template_type=' + templateType +
'&status=' + status +
'&reference=' + reference +
'&older_than=' + olderThanId
)
.reply(200, {hooray: 'bkbbk'});
notifyClient.getNotifications(templateType, status, reference, olderThanId)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
return notifyClient.getNotifications(templateType, status, reference, olderThanId)
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
});
it('should get template by id', function(done) {
describe('template funtions', () => {
var templateId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
it('should get template by id', () => {
notifyAuthNock
.get('/v2/template/' + templateId)
.reply(200, {"foo": "bar"});
let templateId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
notifyClient.getTemplateById(templateId)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
notifyAuthNock
.get('/v2/template/' + templateId)
.reply(200, {foo: 'bar'});
return notifyClient.getTemplateById(templateId)
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
it('should get template by id and version', function(done) {
it('should get template by id and version', () => {
var templateId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
version = 10;
let templateId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
let version = 10;
notifyAuthNock
.get('/v2/template/' + templateId + '/version/' + version)
.reply(200, {"foo": "bar"});
notifyAuthNock
.get('/v2/template/' + templateId + '/version/' + version)
.reply(200, {foo: 'bar'});
notifyClient.getTemplateByIdAndVersion(templateId, version)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
return notifyClient.getTemplateByIdAndVersion(templateId, version)
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
it('should get all templates with unspecified template type', function(done) {
it('should get all templates with unspecified template type', () => {
notifyAuthNock
.get('/v2/templates')
.reply(200, {"foo": "bar"});
notifyAuthNock
.get('/v2/templates')
.reply(200, {foo: 'bar'});
notifyClient.getAllTemplates()
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
return notifyClient.getAllTemplates()
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
it('should get all templates with unspecified template type', function(done) {
it('should get all templates with unspecified template type', () => {
var templateType = 'sms'
let templateType = 'sms'
notifyAuthNock
.get('/v2/templates?type=' + templateType)
.reply(200, {"foo": "bar"});
notifyAuthNock
.get('/v2/templates?type=' + templateType)
.reply(200, {foo: 'bar'});
notifyClient.getAllTemplates(templateType)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
return notifyClient.getAllTemplates(templateType)
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
it('should preview template by id with personalisation', function(done) {
it('should preview template by id with personalisation', () => {
var templateId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
payload = { "name": "Foo" }
expectedPersonalisation = { "personalisation" : payload };
let templateId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
let payload = {name: 'Foo' }
let expectedPersonalisation = {personalisation: payload };
notifyAuthNock
.post('/v2/template/' + templateId + '/preview', expectedPersonalisation)
.reply(200, {"foo": "bar"});
notifyAuthNock
.post('/v2/template/' + templateId + '/preview', expectedPersonalisation)
.reply(200, {foo: 'bar'});
notifyClient.previewTemplateById(templateId, payload)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
return notifyClient.previewTemplateById(templateId, payload)
.then(function (response) {
expect(response.statusCode).to.equal(200);
});
});
it('should preview template by id without personalisation', function(done) {
it('should preview template by id without personalisation', () => {
var templateId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
let templateId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
notifyAuthNock
.post('/v2/template/' + templateId + '/preview')
.reply(200, {"foo": "bar"});
notifyAuthNock
.post('/v2/template/' + templateId + '/preview')
.reply(200, {foo: 'bar'});
notifyClient.previewTemplateById(templateId)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
return notifyClient.previewTemplateById(templateId)
.then(function (response) {
expect(response .statusCode).to.equal(200);
});
});
});
it('should get latest 250 received texts', function(done) {
it('should get latest 250 received texts', function() {
notifyAuthNock
.get('/v2/received-text-messages')
.reply(200, {"foo":"bar"});
notifyAuthNock
.get('/v2/received-text-messages')
.reply(200, {"foo":"bar"});
notifyClient.getReceivedTexts()
.then(function(response){
expect(response.statusCode).to.equal(200);
done();
});
});
return notifyClient.getReceivedTexts()
.then(function(response){
expect(response.statusCode).to.equal(200);
});
});
it('should get up to next 250 received texts with a reference older than a given message id', function(done) {
it('should get up to next 250 received texts with a reference older than a given message id', function() {
var olderThanId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
var olderThanId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
notifyAuthNock
.get('/v2/received-text-messages?older_than=' + olderThanId)
.reply(200, {"foo":"bar"});
notifyAuthNock
.get('/v2/received-text-messages?older_than=' + olderThanId)
.reply(200, {"foo":"bar"});
notifyClient.getReceivedTexts(olderThanId)
.then(function(response){
expect(response.statusCode).to.equal(200);
done();
});
return notifyClient.getReceivedTexts(olderThanId)
.then(function(response){
expect(response.statusCode).to.equal(200);
});
});
});
MockDate.reset();

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc