notifications-node-client 8.3.0 → 8.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -2
- package/.dockerignore +0 -1
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -18
- package/CHANGELOG.md +0 -297
- package/CONTRIBUTING.md +0 -59
- package/Dockerfile +0 -17
- package/Makefile +0 -42
- package/scripts/run_with_docker.sh +0 -21
- package/scripts/test_send.js +0 -57
- package/spec/api_client.js +0 -156
- package/spec/authentication.js +0 -32
- package/spec/integration/schemas/v1/GET_notifications_return.json +0 -37
- package/spec/integration/schemas/v1/POST_notification_return_email.json +0 -27
- package/spec/integration/schemas/v1/POST_notification_return_sms.json +0 -26
- package/spec/integration/schemas/v1/definitions.json +0 -12
- package/spec/integration/schemas/v1/email_notification.json +0 -106
- package/spec/integration/schemas/v1/sms_notification.json +0 -104
- package/spec/integration/schemas/v2/GET_notification_response.json +0 -50
- package/spec/integration/schemas/v2/GET_notifications_response.json +0 -29
- package/spec/integration/schemas/v2/GET_received_text_response.json +0 -23
- package/spec/integration/schemas/v2/GET_received_texts_response.json +0 -29
- package/spec/integration/schemas/v2/GET_template_by_id.json +0 -30
- package/spec/integration/schemas/v2/GET_templates_response.json +0 -15
- package/spec/integration/schemas/v2/POST_notification_email_response.json +0 -18
- package/spec/integration/schemas/v2/POST_notification_letter_response.json +0 -19
- package/spec/integration/schemas/v2/POST_notification_precompiled_letter_response.json +0 -19
- package/spec/integration/schemas/v2/POST_notification_sms_response.json +0 -18
- package/spec/integration/schemas/v2/POST_template_preview.json +0 -14
- package/spec/integration/schemas/v2/definitions.json +0 -51
- package/spec/integration/test.js +0 -415
- package/spec/integration/test_files/one_page_pdf.pdf +0 -0
- package/spec/notification.js +0 -633
- package/spec/test_files/simple.csv +0 -2
- package/spec/types-test.ts +0 -153
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
3
|
-
"description": "GET response schema when getting all templates",
|
|
4
|
-
"type": "object",
|
|
5
|
-
"properties": {
|
|
6
|
-
"templates": {
|
|
7
|
-
"type": "array",
|
|
8
|
-
"items": {
|
|
9
|
-
"type": "object",
|
|
10
|
-
"$ref": "definitions.json#/template"
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"required": ["templates"]
|
|
15
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/schema#",
|
|
3
|
-
"description": "POST notification email response schema",
|
|
4
|
-
"type" : "object",
|
|
5
|
-
"properties": {
|
|
6
|
-
"id": {"$ref": "definitions.json#/uuid"},
|
|
7
|
-
"reference": {"type": ["string", "null"]},
|
|
8
|
-
"content": {"$ref": "definitions.json#/email_content"},
|
|
9
|
-
"uri": {"type": "string"},
|
|
10
|
-
"template": {"$ref": "definitions.json#/template"},
|
|
11
|
-
"scheduled_for": {"oneOf":[
|
|
12
|
-
{"$ref": "definitions.json#/datetime"},
|
|
13
|
-
{"type": "null"}
|
|
14
|
-
]}
|
|
15
|
-
},
|
|
16
|
-
"additionalProperties": false,
|
|
17
|
-
"required": ["id", "content", "uri", "template"]
|
|
18
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/schema#",
|
|
3
|
-
"description": "POST notification letter response schema",
|
|
4
|
-
"type" : "object",
|
|
5
|
-
"properties": {
|
|
6
|
-
"id": {"$ref": "definitions.json#/uuid"},
|
|
7
|
-
"reference": {"type": ["string", "null"]},
|
|
8
|
-
"postage": {"type": "string"},
|
|
9
|
-
"content": {"$ref": "definitions.json#/letter_content"},
|
|
10
|
-
"uri": {"type": "string"},
|
|
11
|
-
"template": {"$ref": "definitions.json#/template"},
|
|
12
|
-
"scheduled_for": {"oneOf":[
|
|
13
|
-
{"$ref": "definitions.json#/datetime"},
|
|
14
|
-
{"type": "null"}
|
|
15
|
-
]}
|
|
16
|
-
},
|
|
17
|
-
"additionalProperties": false,
|
|
18
|
-
"required": ["id", "content", "uri", "template"]
|
|
19
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/schema#",
|
|
3
|
-
"description": "POST notification precompiled letter response schema",
|
|
4
|
-
"type" : "object",
|
|
5
|
-
"properties": {
|
|
6
|
-
"id": {"$ref": "definitions.json#/uuid"},
|
|
7
|
-
"reference": {"type": ["string", "null"]},
|
|
8
|
-
"postage": {"type": "string"},
|
|
9
|
-
"content": {"$ref": "definitions.json#/letter_content"},
|
|
10
|
-
"uri": {"type": "string"},
|
|
11
|
-
"template": {"$ref": "definitions.json#/template"},
|
|
12
|
-
"scheduled_for": {"oneOf":[
|
|
13
|
-
{"$ref": "definitions.json#/datetime"},
|
|
14
|
-
{"type": "null"}
|
|
15
|
-
]}
|
|
16
|
-
},
|
|
17
|
-
"additionalProperties": false,
|
|
18
|
-
"required": ["id", "postage"]
|
|
19
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/schema#",
|
|
3
|
-
"description": "POST notification sms response schema",
|
|
4
|
-
"type" : "object",
|
|
5
|
-
"properties": {
|
|
6
|
-
"id": {"$ref": "definitions.json#/uuid"},
|
|
7
|
-
"reference": {"type": ["string", "null"]},
|
|
8
|
-
"content": {"$ref": "definitions.json#/sms_content"},
|
|
9
|
-
"uri": {"type": "string"},
|
|
10
|
-
"template": {"$ref": "definitions.json#/template"},
|
|
11
|
-
"scheduled_for": {"oneOf":[
|
|
12
|
-
{"$ref": "definitions.json#/datetime"},
|
|
13
|
-
{"type": "null"}
|
|
14
|
-
]}
|
|
15
|
-
},
|
|
16
|
-
"additionalProperties": false,
|
|
17
|
-
"required": ["id", "content", "uri", "template"]
|
|
18
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
3
|
-
"description": "POST template preview schema response",
|
|
4
|
-
"type": "object",
|
|
5
|
-
"title": "reponse v2/template/{id}/preview",
|
|
6
|
-
"properties": {
|
|
7
|
-
"id": {"$ref": "definitions.json#/uuid"},
|
|
8
|
-
"type": {"enum": ["sms", "email", "letter"] },
|
|
9
|
-
"version": {"type": "integer"},
|
|
10
|
-
"body": {"type": "string"},
|
|
11
|
-
"subject": {"type": ["string", "null"]}
|
|
12
|
-
},
|
|
13
|
-
"required": ["id", "type", "version", "body"]
|
|
14
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/schema#",
|
|
3
|
-
"description": "Common definitions - usage example: {'$ref': 'definitions.json#/uuid'} (swap quotes for double quotes)",
|
|
4
|
-
"uuid": {
|
|
5
|
-
"type": "string",
|
|
6
|
-
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
|
|
7
|
-
},
|
|
8
|
-
"datetime": {
|
|
9
|
-
"type": "string",
|
|
10
|
-
"format": "date-time"
|
|
11
|
-
},
|
|
12
|
-
"template": {
|
|
13
|
-
"type": "object",
|
|
14
|
-
"title": "notification content",
|
|
15
|
-
"properties": {
|
|
16
|
-
"id": {"$ref": "#/uuid"},
|
|
17
|
-
"version": {"type": "integer"},
|
|
18
|
-
"uri": {"type": "string"}
|
|
19
|
-
},
|
|
20
|
-
"required": ["id", "version"]
|
|
21
|
-
},
|
|
22
|
-
"email_content": {
|
|
23
|
-
"type": "object",
|
|
24
|
-
"title": "notification email content",
|
|
25
|
-
"properties": {
|
|
26
|
-
"body": {"type": "string"},
|
|
27
|
-
"from_email": {"type": "string", "format": "email_address"},
|
|
28
|
-
"subject": {"type": "string"},
|
|
29
|
-
"one_click_unsubscribe_url": {"type": ["string", "null"], "format": "uri"}
|
|
30
|
-
},
|
|
31
|
-
"required": ["body", "from_email", "subject"]
|
|
32
|
-
},
|
|
33
|
-
"sms_content": {
|
|
34
|
-
"type": "object",
|
|
35
|
-
"title": "notification sms content",
|
|
36
|
-
"properties": {
|
|
37
|
-
"body": {"type": "string"},
|
|
38
|
-
"from_number": {"type": "string"}
|
|
39
|
-
},
|
|
40
|
-
"required": ["body", "from_number"]
|
|
41
|
-
},
|
|
42
|
-
"letter_content": {
|
|
43
|
-
"type": "object",
|
|
44
|
-
"title": "notification letter content",
|
|
45
|
-
"properties": {
|
|
46
|
-
"body": {"type": "string"},
|
|
47
|
-
"subject": {"type": "string"}
|
|
48
|
-
},
|
|
49
|
-
"required": ["body", "subject"]
|
|
50
|
-
}
|
|
51
|
-
}
|
package/spec/integration/test.js
DELETED
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const NotifyClient = require('../../client/notification.js').NotifyClient;
|
|
3
|
-
|
|
4
|
-
const chai = require('chai');
|
|
5
|
-
const chaiAsPromised = require('chai-as-promised');
|
|
6
|
-
const chaiJsonSchema = require('chai-json-schema');
|
|
7
|
-
const chaiBytes = require('chai-bytes');
|
|
8
|
-
chai.use(chaiAsPromised);
|
|
9
|
-
chai.use(chaiJsonSchema);
|
|
10
|
-
chai.use(chaiBytes);
|
|
11
|
-
|
|
12
|
-
const should = chai.should();
|
|
13
|
-
const expect = chai.expect;
|
|
14
|
-
|
|
15
|
-
// will not run unless flag provided `npm test --integration`
|
|
16
|
-
const describer = process.env.npm_config_integration ? describe.only : describe.skip;
|
|
17
|
-
|
|
18
|
-
function make_random_id() {
|
|
19
|
-
var text = "";
|
|
20
|
-
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
21
|
-
|
|
22
|
-
for (var i = 0; i < 5; i++)
|
|
23
|
-
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
24
|
-
|
|
25
|
-
return text;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describer('notification api with a live service', function () {
|
|
29
|
-
// default is 2000 (ms) - api is sometimes slower than this :(
|
|
30
|
-
this.timeout(120000)
|
|
31
|
-
|
|
32
|
-
let notifyClient;
|
|
33
|
-
let teamNotifyClient;
|
|
34
|
-
let emailNotificationId;
|
|
35
|
-
let smsNotificationId;
|
|
36
|
-
let letterNotificationId;
|
|
37
|
-
const personalisation = { name: 'Foo' };
|
|
38
|
-
const clientRef = 'client-ref';
|
|
39
|
-
const oneClickUnsubscribeURL = 'https://www.example.com';
|
|
40
|
-
const email = process.env.FUNCTIONAL_TEST_EMAIL;
|
|
41
|
-
const phoneNumber = process.env.FUNCTIONAL_TEST_NUMBER;
|
|
42
|
-
const letterContact = {
|
|
43
|
-
address_line_1: make_random_id(),
|
|
44
|
-
address_line_2: 'Foo',
|
|
45
|
-
postcode: 'SW1 1AA',
|
|
46
|
-
};
|
|
47
|
-
const smsTemplateId = process.env.SMS_TEMPLATE_ID;
|
|
48
|
-
const smsSenderId = process.env.SMS_SENDER_ID || undefined;
|
|
49
|
-
const emailTemplateId = process.env.EMAIL_TEMPLATE_ID;
|
|
50
|
-
const emailReplyToId = process.env.EMAIL_REPLY_TO_ID || undefined;
|
|
51
|
-
const letterTemplateId = process.env.LETTER_TEMPLATE_ID;
|
|
52
|
-
|
|
53
|
-
beforeEach(() => {
|
|
54
|
-
|
|
55
|
-
const urlBase = process.env.NOTIFY_API_URL;
|
|
56
|
-
const apiKeyId = process.env.API_KEY
|
|
57
|
-
const inboundSmsKeyId = process.env.INBOUND_SMS_QUERY_KEY;
|
|
58
|
-
const teamApiKeyId = process.env.API_SENDING_KEY;
|
|
59
|
-
notifyClient = new NotifyClient(urlBase, apiKeyId);
|
|
60
|
-
teamNotifyClient = new NotifyClient(urlBase, teamApiKeyId);
|
|
61
|
-
receivedTextClient = new NotifyClient(urlBase, inboundSmsKeyId);
|
|
62
|
-
var definitions_json = require('./schemas/v2/definitions.json');
|
|
63
|
-
chai.tv4.addSchema('definitions.json', definitions_json);
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('notifications', () => {
|
|
68
|
-
it('send email notification', () => {
|
|
69
|
-
var postEmailNotificationResponseJson = require('./schemas/v2/POST_notification_email_response.json'),
|
|
70
|
-
options = {personalisation: personalisation, reference: clientRef};
|
|
71
|
-
|
|
72
|
-
return notifyClient.sendEmail(emailTemplateId, email, options).then((response) => {
|
|
73
|
-
response.status.should.equal(201);
|
|
74
|
-
expect(response.data).to.be.jsonSchema(postEmailNotificationResponseJson);
|
|
75
|
-
response.data.content.body.should.equal('Hello Foo\r\n\r\nFunctional test help make our world a better place');
|
|
76
|
-
response.data.content.subject.should.equal('Functional Tests are good');
|
|
77
|
-
response.data.reference.should.equal(clientRef);
|
|
78
|
-
emailNotificationId = response.data.id;
|
|
79
|
-
})
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('send email notification with email_reply_to_id', () => {
|
|
83
|
-
var postEmailNotificationResponseJson = require('./schemas/v2/POST_notification_email_response.json'),
|
|
84
|
-
options = {personalisation: personalisation, reference: clientRef, emailReplyToId: emailReplyToId};
|
|
85
|
-
|
|
86
|
-
should.exist(emailReplyToId);
|
|
87
|
-
return notifyClient.sendEmail(emailTemplateId, email, options).then((response) => {
|
|
88
|
-
response.status.should.equal(201);
|
|
89
|
-
expect(response.data).to.be.jsonSchema(postEmailNotificationResponseJson);
|
|
90
|
-
response.data.content.body.should.equal('Hello Foo\r\n\r\nFunctional test help make our world a better place');
|
|
91
|
-
response.data.content.subject.should.equal('Functional Tests are good');
|
|
92
|
-
should.equal(response.data.content.one_click_unsubscribe_url, null);
|
|
93
|
-
response.data.reference.should.equal(clientRef);
|
|
94
|
-
emailNotificationId = response.data.id;
|
|
95
|
-
})
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('send email notification with unsubscribe link', () => {
|
|
99
|
-
var postEmailNotificationResponseJson = require('./schemas/v2/POST_notification_email_response.json'),
|
|
100
|
-
options = {personalisation: personalisation, reference: clientRef, oneClickUnsubscribeURL: oneClickUnsubscribeURL};
|
|
101
|
-
|
|
102
|
-
return notifyClient.sendEmail(emailTemplateId, email, options).then((response) => {
|
|
103
|
-
response.status.should.equal(201);
|
|
104
|
-
expect(response.data).to.be.jsonSchema(postEmailNotificationResponseJson);
|
|
105
|
-
response.data.content.body.should.equal('Hello Foo\r\n\r\nFunctional test help make our world a better place');
|
|
106
|
-
response.data.content.subject.should.equal('Functional Tests are good');
|
|
107
|
-
response.data.content.one_click_unsubscribe_url.should.equal(oneClickUnsubscribeURL);
|
|
108
|
-
response.data.reference.should.equal(clientRef);
|
|
109
|
-
emailNotificationId = response.data.id;
|
|
110
|
-
})
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('send email notification with document upload', () => {
|
|
114
|
-
var postEmailNotificationResponseJson = require('./schemas/v2/POST_notification_email_response.json'),
|
|
115
|
-
options = {personalisation: { name: 'Foo', documents:
|
|
116
|
-
notifyClient.prepareUpload(Buffer.from("%PDF-1.5 testpdf"))
|
|
117
|
-
}, reference: clientRef};
|
|
118
|
-
|
|
119
|
-
return notifyClient.sendEmail(emailTemplateId, email, options).then((response) => {
|
|
120
|
-
response.status.should.equal(201);
|
|
121
|
-
expect(response.data).to.be.jsonSchema(postEmailNotificationResponseJson);
|
|
122
|
-
response.data.content.body.should.equal('Hello Foo\r\n\r\nFunctional test help make our world a better place');
|
|
123
|
-
response.data.content.subject.should.equal('Functional Tests are good');
|
|
124
|
-
response.data.reference.should.equal(clientRef);
|
|
125
|
-
emailNotificationId = response.data.id;
|
|
126
|
-
})
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('send email notification with CSV document upload', () => {
|
|
130
|
-
var postEmailNotificationResponseJson = require('./schemas/v2/POST_notification_email_response.json'),
|
|
131
|
-
options = {personalisation: { name: 'Foo', documents:
|
|
132
|
-
notifyClient.prepareUpload(Buffer.from("a,b"), true)
|
|
133
|
-
}, reference: clientRef};
|
|
134
|
-
|
|
135
|
-
return notifyClient.sendEmail(emailTemplateId, email, options).then((response) => {
|
|
136
|
-
response.status.should.equal(201);
|
|
137
|
-
expect(response.data).to.be.jsonSchema(postEmailNotificationResponseJson);
|
|
138
|
-
response.data.content.body.should.equal('Hello Foo\r\n\r\nFunctional test help make our world a better place');
|
|
139
|
-
response.data.content.subject.should.equal('Functional Tests are good');
|
|
140
|
-
response.data.reference.should.equal(clientRef);
|
|
141
|
-
emailNotificationId = response.data.id;
|
|
142
|
-
})
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('send sms notification', () => {
|
|
146
|
-
var postSmsNotificationResponseJson = require('./schemas/v2/POST_notification_sms_response.json'),
|
|
147
|
-
options = {personalisation: personalisation};
|
|
148
|
-
|
|
149
|
-
return notifyClient.sendSms(smsTemplateId, phoneNumber, options).then((response) => {
|
|
150
|
-
response.status.should.equal(201);
|
|
151
|
-
expect(response.data).to.be.jsonSchema(postSmsNotificationResponseJson);
|
|
152
|
-
response.data.content.body.should.equal('Hello Foo\n\nFunctional Tests make our world a better place');
|
|
153
|
-
smsNotificationId = response.data.id;
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('send sms notification with sms_sender_id', () => {
|
|
158
|
-
var postSmsNotificationResponseJson = require('./schemas/v2/POST_notification_sms_response.json'),
|
|
159
|
-
options = {personalisation: personalisation, reference: clientRef, smsSenderId: smsSenderId};
|
|
160
|
-
|
|
161
|
-
should.exist(smsSenderId);
|
|
162
|
-
return teamNotifyClient.sendSms(smsTemplateId, phoneNumber, options).then((response) => {
|
|
163
|
-
response.status.should.equal(201);
|
|
164
|
-
expect(response.data).to.be.jsonSchema(postSmsNotificationResponseJson);
|
|
165
|
-
response.data.content.body.should.equal('Hello Foo\n\nFunctional Tests make our world a better place');
|
|
166
|
-
smsNotificationId = response.data.id;
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('send letter notification', () => {
|
|
171
|
-
var postLetterNotificationResponseJson = require('./schemas/v2/POST_notification_letter_response.json'),
|
|
172
|
-
options = {personalisation: letterContact};
|
|
173
|
-
|
|
174
|
-
return notifyClient.sendLetter(letterTemplateId, options).then((response) => {
|
|
175
|
-
response.status.should.equal(201);
|
|
176
|
-
expect(response.data).to.be.jsonSchema(postLetterNotificationResponseJson);
|
|
177
|
-
response.data.content.body.should.equal('Hello ' + letterContact.address_line_1);
|
|
178
|
-
letterNotificationId = response.data.id;
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('send a precompiled letter notification', () => {
|
|
183
|
-
var postPrecompiledLetterNotificationResponseJson = require(
|
|
184
|
-
'./schemas/v2/POST_notification_precompiled_letter_response.json'
|
|
185
|
-
);
|
|
186
|
-
fs.readFile('./spec/integration/test_files/one_page_pdf.pdf', function(err, pdf_file) {
|
|
187
|
-
return notifyClient.sendPrecompiledLetter("my_reference", pdf_file, "first")
|
|
188
|
-
.then((response) => {
|
|
189
|
-
response.status.should.equal(201);
|
|
190
|
-
expect(response.data).to.be.jsonSchema(postPrecompiledLetterNotificationResponseJson);
|
|
191
|
-
letterNotificationId = response.data.id;
|
|
192
|
-
})
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
var getNotificationJson = require('./schemas/v2/GET_notification_response.json');
|
|
197
|
-
var getNotificationsJson = require('./schemas/v2/GET_notifications_response.json');
|
|
198
|
-
|
|
199
|
-
it('get email notification by id', () => {
|
|
200
|
-
should.exist(emailNotificationId)
|
|
201
|
-
return notifyClient.getNotificationById(emailNotificationId).then((response) => {
|
|
202
|
-
response.status.should.equal(200);
|
|
203
|
-
expect(response.data).to.be.jsonSchema(getNotificationJson);
|
|
204
|
-
response.data.type.should.equal('email');
|
|
205
|
-
response.data.body.should.equal('Hello Foo\r\n\r\nFunctional test help make our world a better place');
|
|
206
|
-
response.data.subject.should.equal('Functional Tests are good');
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('get sms notification by id', () => {
|
|
211
|
-
should.exist(smsNotificationId)
|
|
212
|
-
return notifyClient.getNotificationById(smsNotificationId).then((response) => {
|
|
213
|
-
response.status.should.equal(200);
|
|
214
|
-
expect(response.data).to.be.jsonSchema(getNotificationJson);
|
|
215
|
-
response.data.type.should.equal('sms');
|
|
216
|
-
response.data.body.should.equal('Hello Foo\n\nFunctional Tests make our world a better place');
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('get letter notification by id', () => {
|
|
221
|
-
should.exist(letterNotificationId)
|
|
222
|
-
return notifyClient.getNotificationById(letterNotificationId).then((response) => {
|
|
223
|
-
response.status.should.equal(200);
|
|
224
|
-
expect(response.data).to.be.jsonSchema(getNotificationJson);
|
|
225
|
-
response.data.type.should.equal('letter');
|
|
226
|
-
response.data.body.should.equal('Hello ' + letterContact.address_line_1);
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('get a letter pdf', (done) => {
|
|
231
|
-
should.exist(letterNotificationId)
|
|
232
|
-
pdf_contents = fs.readFileSync('./spec/integration/test_files/one_page_pdf.pdf');
|
|
233
|
-
var count = 0
|
|
234
|
-
// it takes a while for the pdf for a freshly sent letter to become ready, so we need to retry the promise
|
|
235
|
-
// a few times, and apply delay in between the attempts. Since our function returns a promise,
|
|
236
|
-
// and it's asynchronous, we cannot use a regular loop to do that. That's why we envelop our promise in a
|
|
237
|
-
// function which we call up to 7 times or until the promise is resolved.
|
|
238
|
-
const tryClient = () => {
|
|
239
|
-
return notifyClient.getPdfForLetterNotification(letterNotificationId)
|
|
240
|
-
.then((file_buffer) => {
|
|
241
|
-
expect(pdf_contents).to.equalBytes(file_buffer);
|
|
242
|
-
done();
|
|
243
|
-
})
|
|
244
|
-
.catch((err) => {
|
|
245
|
-
if (err.constructor.name === 'AssertionError') {
|
|
246
|
-
done(err);
|
|
247
|
-
}
|
|
248
|
-
if (err.response.data && (err.response.data.errors[0].error === "PDFNotReadyError")) {
|
|
249
|
-
count += 1
|
|
250
|
-
if (count < 24) {
|
|
251
|
-
setTimeout(tryClient, 5000)
|
|
252
|
-
} else {
|
|
253
|
-
done(new Error('Too many PDFNotReadyError errors'));
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
})
|
|
257
|
-
};
|
|
258
|
-
tryClient()
|
|
259
|
-
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it('get all notifications', () => {
|
|
263
|
-
chai.tv4.addSchema('notification.json', getNotificationJson);
|
|
264
|
-
return notifyClient.getNotifications().then((response) => {
|
|
265
|
-
response.should.have.property('status', 200);
|
|
266
|
-
expect(response.data).to.be.jsonSchema(getNotificationsJson);
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
describe('templates', () => {
|
|
273
|
-
|
|
274
|
-
var getTemplateJson = require('./schemas/v2/GET_template_by_id.json');
|
|
275
|
-
var getTemplatesJson = require('./schemas/v2/GET_templates_response.json');
|
|
276
|
-
var postTemplatePreviewJson = require('./schemas/v2/POST_template_preview.json');
|
|
277
|
-
var getReceivedTextJson = require('./schemas/v2/GET_received_text_response.json');
|
|
278
|
-
var getReceivedTextsJson = require('./schemas/v2/GET_received_texts_response.json');
|
|
279
|
-
|
|
280
|
-
it('get sms template by id', () => {
|
|
281
|
-
return notifyClient.getTemplateById(smsTemplateId).then((response) => {
|
|
282
|
-
response.status.should.equal(200);
|
|
283
|
-
expect(response.data).to.be.jsonSchema(getTemplateJson);
|
|
284
|
-
response.data.name.should.equal('Client Functional test sms template');
|
|
285
|
-
should.not.exist(response.data.subject);
|
|
286
|
-
should.not.exist(response.data.letter_contact_block);
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
it('get email template by id', () => {
|
|
291
|
-
return notifyClient.getTemplateById(emailTemplateId).then((response) => {
|
|
292
|
-
response.status.should.equal(200);
|
|
293
|
-
expect(response.data).to.be.jsonSchema(getTemplateJson);
|
|
294
|
-
response.data.body.should.equal('Hello ((name))\r\n\r\nFunctional test help make our world a better place');
|
|
295
|
-
response.data.name.should.equal('Client Functional test email template');
|
|
296
|
-
response.data.subject.should.equal('Functional Tests are good');
|
|
297
|
-
should.not.exist(response.data.letter_contact_block);
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
it('get letter template by id', () => {
|
|
302
|
-
return notifyClient.getTemplateById(letterTemplateId).then((response) => {
|
|
303
|
-
response.status.should.equal(200);
|
|
304
|
-
expect(response.data).to.be.jsonSchema(getTemplateJson);
|
|
305
|
-
response.data.body.should.equal('Hello ((address_line_1))');
|
|
306
|
-
response.data.name.should.equal('Client functional letter template');
|
|
307
|
-
response.data.subject.should.equal('Main heading');
|
|
308
|
-
response.data.letter_contact_block.should.equal(
|
|
309
|
-
'Government Digital Service\nThe White Chapel Building\n' +
|
|
310
|
-
'10 Whitechapel High Street\nLondon\nE1 8QS\nUnited Kingdom'
|
|
311
|
-
);
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it('get sms template by id and version', () => {
|
|
316
|
-
return notifyClient.getTemplateByIdAndVersion(smsTemplateId, 1).then((response) => {
|
|
317
|
-
response.status.should.equal(200);
|
|
318
|
-
expect(response.data).to.be.jsonSchema(getTemplateJson);
|
|
319
|
-
response.data.name.should.equal('Example text message template');
|
|
320
|
-
should.not.exist(response.data.subject);
|
|
321
|
-
response.data.version.should.equal(1);
|
|
322
|
-
should.not.exist(response.data.letter_contact_block);
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
it('get email template by id and version', () => {
|
|
327
|
-
return notifyClient.getTemplateByIdAndVersion(emailTemplateId, 1).then((response) => {
|
|
328
|
-
response.status.should.equal(200);
|
|
329
|
-
expect(response.data).to.be.jsonSchema(getTemplateJson);
|
|
330
|
-
response.data.name.should.equal('Client Functional test email template');
|
|
331
|
-
response.data.version.should.equal(1);
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
it('get letter template by id and version', () => {
|
|
336
|
-
return notifyClient.getTemplateByIdAndVersion(letterTemplateId, 1).then((response) => {
|
|
337
|
-
response.status.should.equal(200);
|
|
338
|
-
expect(response.data).to.be.jsonSchema(getTemplateJson);
|
|
339
|
-
response.data.name.should.equal('Untitled');
|
|
340
|
-
response.data.version.should.equal(1);
|
|
341
|
-
// version 1 of the template had no letter_contact_block
|
|
342
|
-
should.not.exist(response.data.letter_contact_block);
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
it('get all templates', () => {
|
|
347
|
-
return notifyClient.getAllTemplates().then((response) => {
|
|
348
|
-
response.status.should.equal(200);
|
|
349
|
-
expect(response.data).to.be.jsonSchema(getTemplatesJson);
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
it('get sms templates', () => {
|
|
354
|
-
return notifyClient.getAllTemplates('sms').then((response) => {
|
|
355
|
-
response.status.should.equal(200);
|
|
356
|
-
expect(response.data).to.be.jsonSchema(getTemplatesJson);
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
it('get email templates', () => {
|
|
361
|
-
return notifyClient.getAllTemplates('email').then((response) => {
|
|
362
|
-
response.status.should.equal(200);
|
|
363
|
-
expect(response.data).to.be.jsonSchema(getTemplatesJson);
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
it('get letter templates', () => {
|
|
368
|
-
return notifyClient.getAllTemplates('letter').then((response) => {
|
|
369
|
-
response.status.should.equal(200);
|
|
370
|
-
expect(response.data).to.be.jsonSchema(getTemplatesJson);
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
it('preview sms template', () => {
|
|
375
|
-
var personalisation = { "name": "Foo" }
|
|
376
|
-
return notifyClient.previewTemplateById(smsTemplateId, personalisation).then((response) => {
|
|
377
|
-
response.status.should.equal(200);
|
|
378
|
-
expect(response.data).to.be.jsonSchema(postTemplatePreviewJson);
|
|
379
|
-
response.data.type.should.equal('sms');
|
|
380
|
-
should.not.exist(response.data.subject);
|
|
381
|
-
});
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
it('preview email template', () => {
|
|
385
|
-
var personalisation = { "name": "Foo" }
|
|
386
|
-
return notifyClient.previewTemplateById(emailTemplateId, personalisation).then((response) => {
|
|
387
|
-
response.status.should.equal(200);
|
|
388
|
-
expect(response.data).to.be.jsonSchema(postTemplatePreviewJson);
|
|
389
|
-
response.data.type.should.equal('email');
|
|
390
|
-
should.exist(response.data.subject);
|
|
391
|
-
});
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
it('preview letter template', () => {
|
|
395
|
-
var personalisation = { "address_line_1": "Foo", "address_line_2": "Bar", "postcode": "SW1 1AA" }
|
|
396
|
-
return notifyClient.previewTemplateById(letterTemplateId, personalisation).then((response) => {
|
|
397
|
-
response.status.should.equal(200);
|
|
398
|
-
expect(response.data).to.be.jsonSchema(postTemplatePreviewJson);
|
|
399
|
-
response.data.type.should.equal('letter');
|
|
400
|
-
should.exist(response.data.subject);
|
|
401
|
-
});
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
it('get all received texts', () => {
|
|
405
|
-
chai.tv4.addSchema('receivedText.json', getReceivedTextJson);
|
|
406
|
-
return receivedTextClient.getReceivedTexts().then((response) => {
|
|
407
|
-
response.status.should.equal(200);
|
|
408
|
-
expect(response.data).to.be.jsonSchema(getReceivedTextsJson);
|
|
409
|
-
expect(response.data["received_text_messages"]).to.be.an('array').that.is.not.empty;
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
});
|
|
Binary file
|