Socket
Socket
Sign inDemoInstall

notifications-node-client

Package Overview
Dependencies
Maintainers
3
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

notifications-node-client - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

spec/integration/schemas/v2/GET_template_by_id.json

14

CHANGELOG.md

@@ -0,3 +1,17 @@

## [3.1.0] - 2017-05-10
### Changed
* Added new methods for managing templates:
* `getTemplateById` - retrieve a single template
* `getTemplateByIdAndVersion` - retrieve a specific version for a desired template
* `getAllTemplates` - retrieve all templates (can filter by type)
* `previewTemplateById` - preview a template with personalisation applied
* Update README to describe how to catch errors
## [3.0.0] - 2016-12-16
### Changed
* Using v2 of the notification-api.

@@ -4,0 +18,0 @@

@@ -86,2 +86,10 @@ var ApiClient = require('./api_client'),

return buildQueryStringFromDict(payload);
}
function buildQueryStringFromDict(dictionary) {
var queryString = Object.keys(dictionary).map(function(key) {
return [key, dictionary[key]].map(encodeURIComponent).join("=");
}).join("&");
return queryString ? '?' + queryString : '';

@@ -153,3 +161,60 @@ }

return this.apiClient.get('/v2/notifications' + buildGetAllNotificationsQuery(templateType, status, reference, olderThanId));
},
/**
*
* @param {String} templateId
*
* @returns {Promise}
*/
getTemplateById: function(templateId) {
return this.apiClient.get('/v2/template/' + templateId);
},
/**
*
* @param {String} templateId
* @param {Integer} version
*
* @returns {Promise}
*/
getTemplateByIdAndVersion: function(templateId, version) {
return this.apiClient.get('/v2/template/' + templateId + '/version/' + version);
},
/**
*
* @param {String} type
*
* @returns {Promise}
*/
getAllTemplates: function(templateType) {
templateQuery = ''
if (templateType) {
templateQuery = '?type=' + templateType;
}
return this.apiClient.get('/v2/templates' + templateQuery);
},
/**
*
* @param {String} templateId
* @param {Dictionary} personalisation
*
* @returns {Promise}
*/
previewTemplateById: function(templateId, personalisation) {
payload = {}
if (!!personalisation) {
payload.personalisation = personalisation;
}
return this.apiClient.post('/v2/template/' + templateId + '/preview', payload);
}
});

@@ -156,0 +221,0 @@

2

package.json
{
"name": "notifications-node-client",
"version": "3.0.0",
"version": "3.1.0",
"description": "GOV.UK Notify Node.js client ",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -13,4 +13,3 @@ [![Dependency Status](https://david-dm.org/alphagov/notifications-node-client.svg)](https://david-dm.org/alphagov/notifications-node-client)

var NotifyClient = require('notifications-node-client').NotifyClient,
notifyClient = new NotifyClient(apiKey);
notifyClient = new NotifyClient(apiKey);
```

@@ -27,3 +26,7 @@

```javascript
notifyClient.sendSms(templateId, phoneNumber, personalisation, reference);
notifyClient
.sendSms(templateId, phoneNumber, personalisation, reference)
.then((response) => { })
.catch((err) => {})
;
```

@@ -36,3 +39,3 @@

If the request is successful, `response` will be an `Object`:
If the request is successful, `response` will be a `Dictionary`:

@@ -56,8 +59,8 @@ ```javascript

Otherwise the client will raise a `StatusCodeError`:
Otherwise the client will return an error `err`:
<table>
<thead>
<tr>
<th>`error.status_code`</th>
<th>`error.message`</th>
<th>`err.error.status_code`</th>
<th>`err.error.errors`</th>
</tr>

@@ -73,2 +76,15 @@ </thead>

[{
"error": "RateLimitError",
"message": "Exceeded rate limit for key type TEAM of 10 requests per 10 seconds"
}]
</pre>
</td>
</tr>
<tr>
<td>
<pre>429</pre>
</td>
<td>
<pre>
[{
"error": "TooManyRequestsError",

@@ -114,3 +130,7 @@ "message": "Exceeded send limits (50) for today"

```javascript
notifyClient.sendEmail(templateId, emailAddress);
notifyClient
.sendEmail(templateId, emailAddress, personalisation, reference);
.then((response) => { })
.catch((err) => {})
;
```

@@ -123,3 +143,3 @@

If the request is successful, `response` will be an `Object`:
If the request is successful, `response` will be a `Dictionary`:

@@ -144,8 +164,8 @@ ```javascript

Otherwise the client will raise a `StatusCodeError`:
Otherwise the client will return an error `err`:
<table>
<thead>
<tr>
<th>`error.status_code`</th>
<th>`error.message`</th>
<th>`err.error.status_code`</th>
<th>`err.error.errors`</th>
</tr>

@@ -161,2 +181,15 @@ </thead>

[{
"error": "RateLimitError",
"message": "Exceeded rate limit for key type TEAM of 10 requests per 10 seconds"
}]
</pre>
</td>
</tr>
<tr>
<td>
<pre>429</pre>
</td>
<td>
<pre>
[{
"error": "TooManyRequestsError",

@@ -226,3 +259,7 @@ "message": "Exceeded send limits (50) for today"

```javascript
notifyClient.getNotificationById(notificationId)
notifyClient
.getNotificationById(notificationId)
.then((response) => { })
.catch((err) => {})
;
```

@@ -235,3 +272,3 @@

If the request is successful, `response` will be an `Object`:
If the request is successful, `response` will be a `Dictionary`:

@@ -265,8 +302,8 @@ ```javascript

Otherwise the client will raise a `StatusCodeError`:
Otherwise the client will return an error `err`:
<table>
<thead>
<tr>
<th>`error.status_code`</th>
<th>`error.message`</th>
<th>`err.error.status_code`</th>
<th>`err.error.errors`</th>
</tr>

@@ -307,3 +344,7 @@ </thead>

```javascript
notifyClient.getNotifications(templateType, status, reference, olderThan)
notifyClient
.getNotifications(templateType, status, reference, olderThan)
.then((response) => { })
.catch((err) => {})
;
```

@@ -316,3 +357,3 @@

If the request is successful, `response` will be an `Object`:
If the request is successful, `response` will be a `Dictionary`:

@@ -352,8 +393,8 @@ ```javascript

Otherwise the client will raise a `StatusCodeError`:
Otherwise the client will return an error `err`:
<table>
<thead>
<tr>
<th>`error.status_code`</th>
<th>`error.message`</th>
<th>`err.error.status_code`</th>
<th>`err.error.errors`</th>
</tr>

@@ -422,1 +463,292 @@ </thead>

If omitted all messages are returned. Otherwise you can filter to retrieve all notifications older than the given notification `id`.
## Get a template by ID
```javascript
notifyClient
.getTemplateById(templateId)
.then((response) => { })
.catch((err) => {})
;
```
<details>
<summary>
Response
</summary>
If the request is successful, `response` will be a `Dictionary`:
```javascript
{
"id": "template_id",
"type": "sms|email|letter",
"created_at": "created at",
"updated_at": "updated at",
"version": "version",
"created_by": "someone@example.com",
"body": "body",
"subject": "null|email_subject"
}
```
Otherwise the client will return an error `err`:
<table>
<thead>
<tr>
<th>`err.error.status_code`</th>
<th>`err.error.errors`</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<pre>404</pre>
</td>
<td>
<pre>
[{
"error": "NoResultFound",
"message": "No result found"
]}
</pre>
</td>
</tr>
</tbody>
</table>
</details>
### Arguments
#### `templateId`
Find by clicking **API info** for the template you want to send.
## Get a template by ID and version
```javascript
notifyClient
.getTemplateByIdAndVersion(templateId, version)
.then((response) => { })
.catch((err) => {})
;
```
<details>
<summary>
Response
</summary>
If the request is successful, `response` will be a `Dictionary`:
```javascript
{
"id": "template_id",
"type": "sms|email|letter",
"created_at": "created at",
"updated_at": "updated at",
"version": "version",
"created_by": "someone@example.com",
"body": "body",
"subject": "null|email_subject"
}
```
Otherwise the client will return an error `err`:
<table>
<thead>
<tr>
<th>`err.error.status_code`</th>
<th>`err.error.errors`</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<pre>404</pre>
</td>
<td>
<pre>
[{
"error": "NoResultFound",
"message": "No result found"
]}
</pre>
</td>
</tr>
</tbody>
</table>
</details>
### Arguments
#### `templateId`
Find by clicking **API info** for the template you want to send.
#### `version`
The version number of the template
## Get all templates
```javascript
notifyClient
.getAllTemplates(templateType)
.then((response) => { })
.catch((err) => {})
;
```
_This will return the latest version for each template_
<details>
<summary>
Response
</summary>
If the request is successful, `response` will be a `Dictionary`:
```javascript
{
"templates" : [
{
"id": "template_id",
"type": "sms|email|letter",
"created_at": "created at",
"updated_at": "updated at",
"version": "version",
"created_by": "someone@example.com",
"body": "body",
"subject": "null|email_subject"
},
{
... another template
}
]
}
```
If no templates exist for a template type or there no templates for a service, the `response` will be a `Dictionary` with an empty `templates` list element:
```javascript
{
"templates" : []
}
```
</details>
### Arguments
#### `templateType`
If omitted all messages are returned. Otherwise you can filter by:
* `email`
* `sms`
* `letter`
## Generate a preview template
```javascript
personalisation = { "foo": "bar" };
notifyClient
.previewTemplateById(templateId, personalisation)
.then((response) => { })
.catch((err) => {})
;
```
<details>
<summary>
Response
</summary>
If the request is successful, `response` will be a `Dictionary`:
```javascript
{
"id": "notify_id",
"type": "sms|email|letter",
"version": "version",
"body": "Hello bar" // with substitution values,
"subject": "null|email_subject"
}
```
Otherwise the client will return an error `err`:
<table>
<thead>
<tr>
<th>`err.error.status_code`</th>
<th>`err.error.errors`</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<pre>400</pre>
</td>
<td>
<pre>
[{
"error": "BadRequestError",
"message": "Missing personalisation: [name]"
]}
</pre>
</td>
</tr>
<tr>
<td>
<pre>404</pre>
</td>
<td>
<pre>
[{
"error": "NoResultFound",
"message": "No result found"
]}
</pre>
</td>
</tr>
</tbody>
</table>
</details>
### Arguments
#### `templateId`
Find by clicking **API info** for the template you want to send.
#### `personalisation`
If a template has placeholders you need to provide their values. For example:
```javascript
personalisation={
'first_name': 'Amala',
'reference_number': '300241',
}
```
Otherwise the parameter can be omitted or `undefined` can be passed in its place.
## Tests
There are unit and integration tests that can be run to test functionality of the client. You will need to have the relevant environment variables sourced to run the tests.
To run the unit tests:
```sh
npm test
```
To run the integration tests:
```sh
npm test --integration
```

@@ -20,3 +20,3 @@ {

},
"required": ["id", "version", "uri"]
"required": ["id", "version"]
},

@@ -23,0 +23,0 @@ "email_content": {

@@ -23,2 +23,4 @@ const NotifyClient = require('../../client/notification.js').NotifyClient;

const phoneNumber = process.env.FUNCTIONAL_TEST_NUMBER;
const smsTemplateId = process.env.SMS_TEMPLATE_ID;
const emailTemplateId = process.env.EMAIL_TEMPLATE_ID;

@@ -36,11 +38,9 @@ beforeEach(() => {

describe('should send', () => {
describe('notifications', () => {
it('email', () => {
var post_notification_return_email_json = require('./schemas/v2/POST_notification_email_response.json');
const emailTemplateId = process.env.EMAIL_TEMPLATE_ID;
it('send email notification', () => {
var postEmailNotificationResponseJson = require('./schemas/v2/POST_notification_email_response.json');
return notifyClient.sendEmail(emailTemplateId, email, personalisation, clientRef).then((response) => {
response.statusCode.should.equal(201);
expect(response.body).to.be.jsonSchema(post_notification_return_email_json);
expect(response.body).to.be.jsonSchema(postEmailNotificationResponseJson);
response.body.content.body.should.equal('Hello Foo\n\nFunctional test help make our world a better place');

@@ -50,31 +50,23 @@ response.body.content.subject.should.equal('Functional Tests are good');

emailNotificationId = response.body.id;
});
})
});
it('sms', () => {
var post_notification_return_sms_json = require('./schemas/v2/POST_notification_sms_response.json');
const smsTemplateId = process.env.SMS_TEMPLATE_ID;
it('send sms notification', () => {
var postSmsNotificationResponseJson = require('./schemas/v2/POST_notification_sms_response.json');
return notifyClient.sendSms(smsTemplateId, phoneNumber, personalisation).then((response) => {
response.statusCode.should.equal(201);
expect(response.body).to.be.jsonSchema(post_notification_return_sms_json);
expect(response.body).to.be.jsonSchema(postSmsNotificationResponseJson);
response.body.content.body.should.equal('Hello Foo\n\nFunctional Tests make our world a better place');
smsNotificationId = response.body.id;
});
});
});
var getNotificationJson = require('./schemas/v2/GET_notification_response.json');
var getNotificationsJson = require('./schemas/v2/GET_notifications_response.json');
describe('should retrieve', () => {
var notificationJson = require('./schemas/v2/GET_notification_response.json');
it('email by id', () => {
it('get email notification by id', () => {
should.exist(emailNotificationId)
return notifyClient.getNotificationById(emailNotificationId).then((response) => {
response.statusCode.should.equal(200);
expect(response.body).to.be.jsonSchema(notificationJson);
expect(response.body).to.be.jsonSchema(getNotificationJson);
response.body.type.should.equal('email');

@@ -84,31 +76,107 @@ response.body.body.should.equal('Hello Foo\n\nFunctional test help make our world a better place');

});
});
it('sms by id', () => {
it('get sms notification by id', () => {
should.exist(smsNotificationId)
return notifyClient.getNotificationById(smsNotificationId).then((response) => {
response.statusCode.should.equal(200);
expect(response.body).to.be.jsonSchema(notificationJson);
expect(response.body).to.be.jsonSchema(getNotificationJson);
response.body.type.should.equal('sms');
response.body.body.should.equal('Hello Foo\n\nFunctional Tests make our world a better place');
});
});
it('all notifications', () => {
var notificationJson = require('./schemas/v2/GET_notification_response.json');
chai.tv4.addSchema('notification.json', notificationJson);
var get_notifications_return_json = require('./schemas/v2/GET_notifications_response.json');
it('get all notifications', () => {
chai.tv4.addSchema('notification.json', getNotificationJson);
return notifyClient.getNotifications().then((response) => {
response.should.have.property('statusCode', 200);
expect(response.body).to.be.jsonSchema(get_notifications_return_json);
expect(response.body).to.be.jsonSchema(getNotificationsJson);
});
});
});
describe('templates', () => {
var getTemplateJson = require('./schemas/v2/GET_template_by_id.json');
var getTemplatesJson = require('./schemas/v2/GET_templates_response.json');
var postTemplatePreviewJson = require('./schemas/v2/POST_template_preview.json');
it('get sms template by id', () => {
return notifyClient.getTemplateById(smsTemplateId).then((response) => {
response.statusCode.should.equal(200);
expect(response.body).to.be.jsonSchema(getTemplateJson);
should.not.exist(response.body.subject);
});
});
it('get email template by id', () => {
return notifyClient.getTemplateById(emailTemplateId).then((response) => {
response.statusCode.should.equal(200);
expect(response.body).to.be.jsonSchema(getTemplateJson);
response.body.body.should.equal('Hello ((name))\n\nFunctional test help make our world a better place');
response.body.subject.should.equal('Functional Tests are good');
});
});
it('get sms template by id and version', () => {
return notifyClient.getTemplateByIdAndVersion(smsTemplateId, 1).then((response) => {
response.statusCode.should.equal(200);
expect(response.body).to.be.jsonSchema(getTemplateJson);
should.not.exist(response.body.subject);
response.body.version.should.equal(1);
});
});
it('get email template by id and version', () => {
return notifyClient.getTemplateByIdAndVersion(emailTemplateId, 1).then((response) => {
response.statusCode.should.equal(200);
expect(response.body).to.be.jsonSchema(getTemplateJson);
response.body.version.should.equal(1);
});
});
it('get all templates', () => {
return notifyClient.getAllTemplates().then((response) => {
response.statusCode.should.equal(200);
expect(response.body).to.be.jsonSchema(getTemplatesJson);
});
});
it('get sms templates', () => {
return notifyClient.getAllTemplates('sms').then((response) => {
response.statusCode.should.equal(200);
expect(response.body).to.be.jsonSchema(getTemplatesJson);
});
});
it('get email templates', () => {
return notifyClient.getAllTemplates('email').then((response) => {
response.statusCode.should.equal(200);
expect(response.body).to.be.jsonSchema(getTemplatesJson);
});
});
it('preview sms template', () => {
var personalisation = { "name": "Foo" }
return notifyClient.previewTemplateById(smsTemplateId, personalisation).then((response) => {
response.statusCode.should.equal(200);
expect(response.body).to.be.jsonSchema(postTemplatePreviewJson);
response.body.type.should.equal('sms');
should.not.exist(response.body.subject);
});
});
it('preview email template', () => {
var personalisation = { "name": "Foo" }
return notifyClient.previewTemplateById(emailTemplateId, personalisation).then((response) => {
response.statusCode.should.equal(200);
expect(response.body).to.be.jsonSchema(postTemplatePreviewJson);
response.body.type.should.equal('email');
should.exist(response.body.subject);
});
});
});
});

@@ -5,9 +5,29 @@ var expect = require('chai').expect, NotifyClient = require('../client/notification.js').NotifyClient,

const baseUrl = 'http://localhost';
const serviceId = 'c745a8d8-b48a-4b0d-96e5-dbea0165ebd1';
const apiKeyId = '8b3aa916-ec82-434e-b0c5-d5d9b371d6a3';
function getNotifyClient() {
var baseUrl = 'http://localhost';
var 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;
}
describe('notification api', function() {
var notifyClient = getNotifyClient();
var notifyAuthNock = getNotifyAuthNock();
it('should send an email', function(done) {
var urlBase = 'http://localhost',
email = 'dom@example.com',
var email = 'dom@example.com',
templateId = '123',

@@ -19,15 +39,8 @@ personalisation = {foo: 'bar'},

personalisation: personalisation
},
notifyClient,
serviceId = 'c745a8d8-b48a-4b0d-96e5-dbea0165ebd1',
apiKeyId = '8b3aa916-ec82-434e-b0c5-d5d9b371d6a3';
};
nock(urlBase, {
reqheaders: {
'Authorization': 'Bearer ' + createGovukNotifyToken('POST', '/v2/notifications/email', apiKeyId, serviceId)
}})
.post('/v2/notifications/email', data)
.reply(200, {"hooray": "bkbbk"});
notifyAuthNock
.post('/v2/notifications/email', data)
.reply(200, {"hooray": "bkbbk"});
notifyClient = new NotifyClient(urlBase, serviceId, apiKeyId);
notifyClient.sendEmail(templateId, email, personalisation)

@@ -38,2 +51,3 @@ .then(function (response) {

});
});

@@ -43,4 +57,3 @@

var urlBase = 'http://localhost',
phoneNo = '07525755555',
var phoneNo = '07525755555',
templateId = '123',

@@ -52,15 +65,8 @@ personalisation = {foo: 'bar'},

personalisation: personalisation
},
notifyClient,
serviceId = 'c745a8d8-b48a-4b0d-96e5-dbea0165ebd1',
apiKeyId = '8b3aa916-ec82-434e-b0c5-d5d9b371d6a3';
};
nock(urlBase, {
reqheaders: {
'Authorization': 'Bearer ' + createGovukNotifyToken('POST', '/v2/notifications/email', apiKeyId, serviceId)
}})
notifyAuthNock
.post('/v2/notifications/sms', data)
.reply(200, {"hooray": "bkbbk"});
notifyClient = new NotifyClient(urlBase, serviceId, apiKeyId);
notifyClient.sendSms(templateId, phoneNo, personalisation)

@@ -75,16 +81,9 @@ .then(function (response) {

var urlBase = 'http://localhost',
notificationId = 'wfdfdgf',
notifyClient,
serviceId = 'c745a8d8-b48a-4b0d-96e5-dbea0165ebd1',
apiKeyId = '8b3aa916-ec82-434e-b0c5-d5d9b371d6a3';
var baseUrl = 'http://localhost',
notificationId = 'wfdfdgf';
nock(urlBase, {
reqheaders: {
'Authorization': 'Bearer ' + createGovukNotifyToken('POST', '/v2/notifications/', apiKeyId, serviceId)
}})
notifyAuthNock
.get('/v2/notifications/' + notificationId)
.reply(200, {"hooray": "bkbbk"});
notifyClient = new NotifyClient(urlBase, serviceId, apiKeyId);
notifyClient.getNotificationById(notificationId)

@@ -99,15 +98,6 @@ .then(function (response) {

var urlBase = 'http://localhost',
notifyClient,
serviceId = 'c745a8d8-b48a-4b0d-96e5-dbea0165ebd1',
apiKeyId = '8b3aa916-ec82-434e-b0c5-d5d9b371d6a3';
nock(urlBase, {
reqheaders: {
'Authorization': 'Bearer ' + createGovukNotifyToken('POST', '/v2/notifications/', apiKeyId, serviceId)
}})
notifyAuthNock
.get('/v2/notifications')
.reply(200, {"hooray": "bkbbk"});
notifyClient = new NotifyClient(urlBase, serviceId, apiKeyId);
notifyClient.getNotifications()

@@ -122,15 +112,8 @@ .then(function (response) {

var urlBase = 'http://localhost',
notifyClient,
serviceId = 'c745a8d8-b48a-4b0d-96e5-dbea0165ebd1',
apiKeyId = '8b3aa916-ec82-434e-b0c5-d5d9b371d6a3';
reference = 'myref'
nock(urlBase, {
reqheaders: {
'Authorization': 'Bearer ' + createGovukNotifyToken('POST', '/v2/notifications/', apiKeyId, serviceId)
}})
var reference = 'myref'
notifyAuthNock
.get('/v2/notifications?reference=' + reference)
.reply(200, {"hooray": "bkbbk"});
notifyClient = new NotifyClient(urlBase, serviceId, apiKeyId);
notifyClient.getNotifications(undefined, undefined, reference)

@@ -145,16 +128,8 @@ .then(function (response) {

var urlBase = 'http://localhost',
notifyClient,
serviceId = 'c745a8d8-b48a-4b0d-96e5-dbea0165ebd1',
apiKeyId = '8b3aa916-ec82-434e-b0c5-d5d9b371d6a3';
status = 'failed';
var status = 'failed';
nock(urlBase, {
reqheaders: {
'Authorization': 'Bearer ' + createGovukNotifyToken('POST', '/v2/notifications/', apiKeyId, serviceId)
}})
notifyAuthNock
.get('/v2/notifications?status=' + status)
.reply(200, {"hooray": "bkbbk"});
notifyClient = new NotifyClient(urlBase, serviceId, apiKeyId);
notifyClient.getNotifications(undefined, 'failed')

@@ -169,17 +144,9 @@ .then(function (response) {

var urlBase = 'http://localhost',
notifyClient,
serviceId = 'c745a8d8-b48a-4b0d-96e5-dbea0165ebd1',
apiKeyId = '8b3aa916-ec82-434e-b0c5-d5d9b371d6a3';
templateType = 'sms'
var templateType = 'sms'
status = 'failed';
nock(urlBase, {
reqheaders: {
'Authorization': 'Bearer ' + createGovukNotifyToken('POST', '/v2/notifications/', apiKeyId, serviceId)
}})
notifyAuthNock
.get('/v2/notifications?template_type=' + templateType + '&status=' + status)
.reply(200, {"hooray": "bkbbk"});
notifyClient = new NotifyClient(urlBase, serviceId, apiKeyId);
notifyClient.getNotifications(templateType, status)

@@ -194,18 +161,10 @@ .then(function (response) {

var urlBase = 'http://localhost',
notifyClient,
serviceId = 'c745a8d8-b48a-4b0d-96e5-dbea0165ebd1',
apiKeyId = '8b3aa916-ec82-434e-b0c5-d5d9b371d6a3';
templateType = 'sms'
var templateType = 'sms'
status = 'delivered';
reference = 'myref'
nock(urlBase, {
reqheaders: {
'Authorization': 'Bearer ' + createGovukNotifyToken('POST', '/v2/notifications/', apiKeyId, serviceId)
}})
notifyAuthNock
.get('/v2/notifications?template_type=' + templateType + '&status=' + status + '&reference=' + reference)
.reply(200, {"hooray": "bkbbk"});
notifyClient = new NotifyClient(urlBase, serviceId, apiKeyId);
notifyClient.getNotifications(templateType, status, reference)

@@ -220,7 +179,3 @@ .then(function (response) {

var urlBase = 'http://localhost',
notifyClient,
serviceId = 'c745a8d8-b48a-4b0d-96e5-dbea0165ebd1',
apiKeyId = '8b3aa916-ec82-434e-b0c5-d5d9b371d6a3';
templateType = 'sms';
var templateType = 'sms';
status = 'delivered';

@@ -230,6 +185,3 @@ reference = 'myref';

nock(urlBase, {
reqheaders: {
'Authorization': 'Bearer ' + createGovukNotifyToken('POST', '/v2/notifications/', apiKeyId, serviceId)
}})
notifyAuthNock
.get('/v2/notifications?template_type=' + templateType +

@@ -242,3 +194,2 @@ '&status=' + status +

notifyClient = new NotifyClient(urlBase, serviceId, apiKeyId);
notifyClient.getNotifications(templateType, status, reference, olderThanId)

@@ -251,2 +202,98 @@ .then(function (response) {

it('should get template by id', function(done) {
var templateId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
notifyAuthNock
.get('/v2/template/' + templateId)
.reply(200, {"foo": "bar"});
notifyClient.getTemplateById(templateId)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
});
it('should get template by id and version', function(done) {
var templateId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
version = 10;
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();
});
});
it('should get all templates with unspecified template type', function(done) {
notifyAuthNock
.get('/v2/templates')
.reply(200, {"foo": "bar"});
notifyClient.getAllTemplates()
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
});
it('should get all templates with unspecified template type', function(done) {
var templateType = 'sms'
notifyAuthNock
.get('/v2/templates?type=' + templateType)
.reply(200, {"foo": "bar"});
notifyClient.getAllTemplates(templateType)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
});
it('should preview template by id with personalisation', function(done) {
var templateId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
payload = { "name": "Foo" }
expectedPersonalisation = { "personalisation" : payload };
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();
});
});
it('should preview template by id without personalisation', function(done) {
var templateId = '35836a9e-5a97-4d99-8309-0c5a2c3dbc72';
notifyAuthNock
.post('/v2/template/' + templateId + '/preview')
.reply(200, {"foo": "bar"});
notifyClient.previewTemplateById(templateId)
.then(function (response) {
expect(response.statusCode).to.equal(200);
done();
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc