email-notifier 14.0.2

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.
Files changed (51) hide show
  1. package/.circleci/config.yml +11 -0
  2. package/.dockerignore +17 -0
  3. package/.github/ISSUE_TEMPLATE/config.yml +1 -0
  4. package/.github/ISSUE_TEMPLATE/no-issue-template.md +18 -0
  5. package/.ncurc.yaml +2 -0
  6. package/.nvmrc +1 -0
  7. package/.nycrc.yml +19 -0
  8. package/.versionrc +15 -0
  9. package/CHANGELOG.md +68 -0
  10. package/CODEOWNERS +5 -0
  11. package/Dockerfile +44 -0
  12. package/LICENSE.md +10 -0
  13. package/README.md +135 -0
  14. package/app.js +34 -0
  15. package/audit-ci.jsonc +9 -0
  16. package/config/custom-environment-variables.json +17 -0
  17. package/config/default.json +96 -0
  18. package/istanbul.yml +14 -0
  19. package/onboarding.md +182 -0
  20. package/package.json +114 -0
  21. package/src/lib/config.js +3 -0
  22. package/src/lib/enum.js +149 -0
  23. package/src/lib/healthCheck/subServiceHealth.js +83 -0
  24. package/src/lib/kafka/consumer.js +200 -0
  25. package/src/lib/kafka/index.js +43 -0
  26. package/src/lib/kafka/producer.js- +136 -0
  27. package/src/lib/utility.js +251 -0
  28. package/src/nodeMailer/sendMail.js +101 -0
  29. package/src/observables/actions.js +91 -0
  30. package/src/observables/index.js +30 -0
  31. package/src/setup.js +81 -0
  32. package/templates/en/adjustment/dfspEmail.mustache +7 -0
  33. package/templates/en/adjustment/hubEmail.mustache +4 -0
  34. package/templates/en/breach/dfspEmail.mustache +11 -0
  35. package/templates/en/breach/hubEmail.mustache +10 -0
  36. package/templates/en/position/dfspEmail.mustache +6 -0
  37. package/templates/en/position/hubEmail.mustache +5 -0
  38. package/templates/index.js +36 -0
  39. package/test/messageSubmitter.js +21 -0
  40. package/test/unit/hanlder.test--.js +944 -0
  41. package/test/unit/lib/healthCheck/subServiceHealth.test.js +110 -0
  42. package/test/unit/lib/kafka/consumer.test.js +365 -0
  43. package/test/unit/lib/kafka/producer.test--.js +323 -0
  44. package/test/unit/lib/utility.test.js +152 -0
  45. package/test/unit/nodeMailer/sendMail.test.js +239 -0
  46. package/test/unit/observables/action.test.js +315 -0
  47. package/test/unit/setup.mmtest.js +151 -0
  48. package/test/unit/setup.test.js +123 -0
  49. package/test/unit/templates/empty.mustache +0 -0
  50. package/test/unit/templates/index.test.js +97 -0
  51. package/test/unit/templates/ok.template +1 -0
@@ -0,0 +1,239 @@
1
+ /*****
2
+ License
3
+ --------------
4
+ Copyright © 2017 Bill & Melinda Gates Foundation
5
+ The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
8
+ Contributors
9
+ --------------
10
+ This is the official list of the Mojaloop project contributors for this file.
11
+ Names of the original copyright holders (individuals or organizations)
12
+ should be listed with a '*' in the first column. People who have
13
+ contributed from an organization can be listed under the organization
14
+ that actually holds the copyright for their contributions (see the
15
+ Gates Foundation organization for an example). Those individuals should have
16
+ their names indented and be marked with a '-'. Email address can be added
17
+ optionally within square brackets <email>.
18
+ * Gates Foundation
19
+ - Name Surname <name.surname@gatesfoundation.com>
20
+
21
+ - Shashikant Hirugade <shashikant.hirugade@modusbox.com>
22
+ --------------
23
+ ******/
24
+
25
+ 'use strict'
26
+
27
+ const Test = require('tapes')(require('tape'))
28
+ const Sinon = require('sinon')
29
+ const Mailer = require('../../../src/nodeMailer/sendMail')
30
+ const nodemailer = require('nodemailer')
31
+ const Config = require('../../../src/lib/config')
32
+
33
+ Test('nodeMailer unit tests (sendMail.js) : ', async sendMailTest => {
34
+ let sandbox
35
+
36
+ sendMailTest.beforeEach(t => {
37
+ sandbox = Sinon.createSandbox()
38
+ sandbox.stub(nodemailer, 'createTransport')
39
+ t.end()
40
+ })
41
+
42
+ sendMailTest.afterEach(t => {
43
+ // restore the environment as it was before
44
+ sandbox.restore()
45
+ t.end()
46
+ })
47
+
48
+ await sendMailTest.test(' sendMail should return success.', async assert => {
49
+ const mockMessage = {
50
+ value: {
51
+ from: Config.get('HUB_PARTICIPANT').NAME,
52
+ to: 'dfsp1',
53
+ id: '694dd040-a315-4427-bcf0-e29229c4defe',
54
+ content: {
55
+ header: {},
56
+ payload: {
57
+ from: Config.get('HUB_PARTICIPANT').NAME,
58
+ to: 'dfsp1',
59
+ recepientDetails: {
60
+ _id: '5bf5480aa305f9801a6d59db',
61
+ name: 'dfsp1',
62
+ type: 'NET_DEBIT_CAP_ADJUSTMENT',
63
+ value: 'dean.bothma@modusbox.com',
64
+ action: 'sendEmail',
65
+ createdAt: '2018-11-21T11:56:58.919Z',
66
+ updatedAt: '2018-11-21T14:00:38.993Z',
67
+ __v: 0
68
+ },
69
+ hubDetails: {
70
+ _id: '5bf5480aa305f9801a6d59dd',
71
+ name: 'Hub',
72
+ type: 'NET_DEBIT_CAP_ADJUSTMENT',
73
+ value: 'dean.bothma@modusbox.com',
74
+ action: 'sendEmail',
75
+ createdAt: '2018-11-21T11:56:58.950Z',
76
+ updatedAt: '2018-11-21T14:00:39.077Z',
77
+ __v: 0
78
+ },
79
+ messageDetails: {
80
+ dfsp: 'dfsp1',
81
+ limitType: 'NET_DEBIT_CAP',
82
+ value: 1000,
83
+ currency: 'USD',
84
+ triggeredBy: '5bf5480ba305f9801a6d59e0',
85
+ repetitionsAllowed: 3,
86
+ fromEvent: '5bf5480ba305f9801a6d59e4',
87
+ action: 'sendEmail',
88
+ notificationEndpointType: 'NET_DEBIT_CAP_ADJUSTMENT',
89
+ templateType: 'adjustment',
90
+ language: 'en',
91
+ messageSubject: 'NET_DEBIT_CAP LIMIT ADJUSTMENT',
92
+ notificationInterval: 3,
93
+ resetPeriod: 60
94
+ }
95
+ }
96
+ },
97
+ type: 'application/json',
98
+ metadata: {
99
+ event: {
100
+ id: '4276f87a-0a17-485f-acb8-f2d582a1f608',
101
+ responseTo: '88d15b71-ae0d-4e31-a285-c3fdd5982180',
102
+ type: 'notification',
103
+ action: 'event',
104
+ createdAt: '2018-12-11T13:36:58.225Z',
105
+ state: { status: 'success', code: 0, description: 'action successful' }
106
+ },
107
+ 'protocol.createdAt': 1544535418447
108
+ },
109
+ pp: ''
110
+ },
111
+ size: 1363,
112
+ key: {
113
+ type: 'Buffer',
114
+ data: [51, 48, 55, 54, 50, 51, 49, 55, 45, 54, 48, 97, 48, 45, 52, 98, 102, 52, 45, 98, 98, 97, 97, 45, 100, 50, 49, 50, 53, 101, 49, 100, 54, 52, 50, 97]
115
+ },
116
+ topic: 'topic-notification-event',
117
+ offset: 4,
118
+ partition: 0,
119
+ timestamp: 1544535418448
120
+ }
121
+
122
+ const transport = {
123
+ sendMail: (data, callback) => {
124
+ callback(null, { response: 'ok' })
125
+ }
126
+ }
127
+
128
+ nodemailer.createTransport.returns(transport)
129
+
130
+ try {
131
+ const mailer = new Mailer()
132
+ const result = await mailer.sendMailMessage(mockMessage.value)
133
+
134
+ assert.deepEqual(result, {
135
+ emailSent: 'ok'
136
+ })
137
+ sandbox.restore()
138
+ assert.end()
139
+ } catch (e) {
140
+ assert.fail(`test failed with error ${e}`)
141
+ assert.end()
142
+ }
143
+ })
144
+
145
+ await sendMailTest.test(' sendMail should throw an error.', async assert => {
146
+ const mockMessage = {
147
+ value: {
148
+ from: Config.get('HUB_PARTICIPANT').NAME,
149
+ to: 'dfsp1',
150
+ id: '694dd040-a315-4427-bcf0-e29229c4defe',
151
+ content: {
152
+ header: {},
153
+ payload: {
154
+ from: Config.get('HUB_PARTICIPANT').NAME,
155
+ to: 'dfsp1',
156
+ recepientDetails: {
157
+ _id: '5bf5480aa305f9801a6d59db',
158
+ name: 'dfsp1',
159
+ type: 'NET_DEBIT_CAP_ADJUSTMENT',
160
+ value: 'dean.bothma@modusbox.com',
161
+ action: 'sendEmail',
162
+ createdAt: '2018-11-21T11:56:58.919Z',
163
+ updatedAt: '2018-11-21T14:00:38.993Z',
164
+ __v: 0
165
+ },
166
+ hubDetails: {
167
+ _id: '5bf5480aa305f9801a6d59dd',
168
+ name: 'Hub',
169
+ type: 'NET_DEBIT_CAP_ADJUSTMENT',
170
+ value: 'dean.bothma@modusbox.com',
171
+ action: 'sendEmail',
172
+ createdAt: '2018-11-21T11:56:58.950Z',
173
+ updatedAt: '2018-11-21T14:00:39.077Z',
174
+ __v: 0
175
+ },
176
+ messageDetails: {
177
+ dfsp: 'dfsp1',
178
+ limitType: 'NET_DEBIT_CAP',
179
+ value: 1000,
180
+ currency: 'USD',
181
+ triggeredBy: '5bf5480ba305f9801a6d59e0',
182
+ repetitionsAllowed: 3,
183
+ fromEvent: '5bf5480ba305f9801a6d59e4',
184
+ action: 'sendEmail',
185
+ notificationEndpointType: 'NET_DEBIT_CAP_ADJUSTMENT',
186
+ templateType: 'adjustment',
187
+ language: 'en',
188
+ messageSubject: 'NET_DEBIT_CAP LIMIT ADJUSTMENT',
189
+ notificationInterval: 3,
190
+ resetPeriod: 60
191
+ }
192
+ }
193
+ },
194
+ type: 'application/json',
195
+ metadata: {
196
+ event: {
197
+ id: '4276f87a-0a17-485f-acb8-f2d582a1f608',
198
+ responseTo: '88d15b71-ae0d-4e31-a285-c3fdd5982180',
199
+ type: 'notification',
200
+ action: 'event',
201
+ createdAt: '2018-12-11T13:36:58.225Z',
202
+ state: { status: 'success', code: 0, description: 'action successful' }
203
+ },
204
+ 'protocol.createdAt': 1544535418447
205
+ },
206
+ pp: ''
207
+ },
208
+ size: 1363,
209
+ key: {
210
+ type: 'Buffer',
211
+ data: [51, 48, 55, 54, 50, 51, 49, 55, 45, 54, 48, 97, 48, 45, 52, 98, 102, 52, 45, 98, 98, 97, 97, 45, 100, 50, 49, 50, 53, 101, 49, 100, 54, 52, 50, 97]
212
+ },
213
+ topic: 'topic-notification-event',
214
+ offset: 4,
215
+ partition: 0,
216
+ timestamp: 1544535418448
217
+ }
218
+
219
+ const transportFail = {
220
+ sendMail: (data, callback) => {
221
+ const err = new Error('some error')
222
+ callback(err, null)
223
+ }
224
+ }
225
+
226
+ nodemailer.createTransport.returns(transportFail)
227
+
228
+ try {
229
+ const mailer = new Mailer()
230
+ await mailer.sendMailMessage(mockMessage)
231
+ assert.fail('should throw')
232
+ assert.end()
233
+ } catch (e) {
234
+ assert.ok(e.message, 'some error')
235
+ assert.end()
236
+ }
237
+ })
238
+ await sendMailTest.end()
239
+ })
@@ -0,0 +1,315 @@
1
+ /*****
2
+ License
3
+ --------------
4
+ Copyright © 2017 Bill & Melinda Gates Foundation
5
+ The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
8
+ Contributors
9
+ --------------
10
+ This is the official list of the Mojaloop project contributors for this file.
11
+ Names of the original copyright holders (individuals or organizations)
12
+ should be listed with a '*' in the first column. People who have
13
+ contributed from an organization can be listed under the organization
14
+ that actually holds the copyright for their contributions (see the
15
+ Gates Foundation organization for an example). Those individuals should have
16
+ their names indented and be marked with a '-'. Email address can be added
17
+ optionally within square brackets <email>.
18
+ * Gates Foundation
19
+ - Name Surname <name.surname@gatesfoundation.com>
20
+
21
+ - Shashikant Hirugade <shashikant.hirugade@modusbox.com>
22
+ --------------
23
+ ******/
24
+
25
+ 'use strict'
26
+
27
+ const Test = require('tapes')(require('tape'))
28
+ const Email = require('../../../src/nodeMailer/sendMail')
29
+ const Sinon = require('sinon')
30
+ const ActionObservable = require('../../../src/observables/actions').actionObservable
31
+ const Config = require('../../../src/lib/config')
32
+
33
+ Test('RxJs Observable Tests (Action Observable) : ', async actionTest => {
34
+ Sinon.config = {
35
+ useFakeTimers: false
36
+ }
37
+
38
+ let sandbox
39
+ actionTest.beforeEach(t => {
40
+ // create a sandbox
41
+ sandbox = Sinon.createSandbox()
42
+ // start stubbing stuff
43
+ sandbox.stub(Email.prototype, 'sendMailMessage')
44
+ t.end()
45
+ })
46
+
47
+ actionTest.afterEach(t => {
48
+ // restore the environment as it was before
49
+ sandbox.restore()
50
+ t.end()
51
+ })
52
+
53
+ await actionTest.test('Should test the actionObservable succeeds', async assert => {
54
+ const mockMessage = {
55
+ value: {
56
+ from: Config.get('HUB_PARTICIPANT').NAME,
57
+ to: 'dfsp1',
58
+ id: '694dd040-a315-4427-bcf0-e29229c4defe',
59
+ content: {
60
+ header: {},
61
+ payload: {
62
+ from: Config.get('HUB_PARTICIPANT').NAME,
63
+ to: 'dfsp1',
64
+ recepientDetails: {
65
+ _id: '5bf5480aa305f9801a6d59db',
66
+ name: 'dfsp1',
67
+ type: 'NET_DEBIT_CAP_ADJUSTMENT',
68
+ value: 'dean.bothma@modusbox.com',
69
+ action: 'sendEmail',
70
+ createdAt: '2018-11-21T11:56:58.919Z',
71
+ updatedAt: '2018-11-21T14:00:38.993Z',
72
+ __v: 0
73
+ },
74
+ hubDetails: {
75
+ _id: '5bf5480aa305f9801a6d59dd',
76
+ name: 'Hub',
77
+ type: 'NET_DEBIT_CAP_ADJUSTMENT',
78
+ value: 'dean.bothma@modusbox.com',
79
+ action: 'sendEmail',
80
+ createdAt: '2018-11-21T11:56:58.950Z',
81
+ updatedAt: '2018-11-21T14:00:39.077Z',
82
+ __v: 0
83
+ },
84
+ messageDetails: {
85
+ dfsp: 'dfsp1',
86
+ limitType: 'NET_DEBIT_CAP',
87
+ value: 1000,
88
+ currency: 'USD',
89
+ triggeredBy: '5bf5480ba305f9801a6d59e0',
90
+ repetitionsAllowed: 3,
91
+ fromEvent: '5bf5480ba305f9801a6d59e4',
92
+ action: 'sendEmail',
93
+ notificationEndpointType: 'NET_DEBIT_CAP_ADJUSTMENT',
94
+ templateType: 'adjustment',
95
+ language: 'en',
96
+ messageSubject: 'NET_DEBIT_CAP LIMIT ADJUSTMENT',
97
+ notificationInterval: 3,
98
+ resetPeriod: 60
99
+ }
100
+ }
101
+ },
102
+ type: 'application/json',
103
+ metadata: {
104
+ event: {
105
+ id: '4276f87a-0a17-485f-acb8-f2d582a1f608',
106
+ responseTo: '88d15b71-ae0d-4e31-a285-c3fdd5982180',
107
+ type: 'notification',
108
+ action: 'event',
109
+ createdAt: '2018-12-11T13:36:58.225Z',
110
+ state: { status: 'success', code: 0, description: 'action successful' }
111
+ },
112
+ 'protocol.createdAt': 1544535418447
113
+ },
114
+ pp: ''
115
+ },
116
+ size: 1363,
117
+ key: {
118
+ type: 'Buffer',
119
+ data: [51, 48, 55, 54, 50, 51, 49, 55, 45, 54, 48, 97, 48, 45, 52, 98, 102, 52, 45, 98, 98, 97, 97, 45, 100, 50, 49, 50, 53, 101, 49, 100, 54, 52, 50, 97]
120
+ },
121
+ topic: 'topic-notification-event',
122
+ offset: 4,
123
+ partition: 0,
124
+ timestamp: 1544535418448
125
+ }
126
+ const emailer = new Email()
127
+ emailer.sendMailMessage.resolves(true)
128
+ ActionObservable(mockMessage).subscribe(
129
+ result => {
130
+ assert.deepEqual(result, {
131
+ dfspMailResult: true,
132
+ hubMailResult: true
133
+ })
134
+ assert.end()
135
+ },
136
+ error => {
137
+ assert.fail(`test failed with error ${error}`)
138
+ assert.end()
139
+ })
140
+ })
141
+
142
+ await actionTest.test('Should fail when sent mail message fails.', async assert => {
143
+ const mockMessage = {
144
+ value: {
145
+ from: Config.get('HUB_PARTICIPANT').NAME,
146
+ to: 'dfsp1',
147
+ id: '694dd040-a315-4427-bcf0-e29229c4defe',
148
+ content: {
149
+ header: {},
150
+ payload: {
151
+ from: Config.get('HUB_PARTICIPANT').NAME,
152
+ to: 'dfsp1',
153
+ recepientDetails: {
154
+ _id: '5bf5480aa305f9801a6d59db',
155
+ name: 'dfsp1',
156
+ type: 'NET_DEBIT_CAP_ADJUSTMENT',
157
+ value: 'dean.bothma@modusbox.com',
158
+ action: 'sendEmail',
159
+ createdAt: '2018-11-21T11:56:58.919Z',
160
+ updatedAt: '2018-11-21T14:00:38.993Z',
161
+ __v: 0
162
+ },
163
+ hubDetails: {
164
+ _id: '5bf5480aa305f9801a6d59dd',
165
+ name: 'Hub',
166
+ type: 'NET_DEBIT_CAP_ADJUSTMENT',
167
+ value: 'dean.bothma@modusbox.com',
168
+ action: 'sendEmail',
169
+ createdAt: '2018-11-21T11:56:58.950Z',
170
+ updatedAt: '2018-11-21T14:00:39.077Z',
171
+ __v: 0
172
+ },
173
+ messageDetails: {
174
+ dfsp: 'dfsp1',
175
+ limitType: 'NET_DEBIT_CAP',
176
+ value: 1000,
177
+ currency: 'USD',
178
+ triggeredBy: '5bf5480ba305f9801a6d59e0',
179
+ repetitionsAllowed: 3,
180
+ fromEvent: '5bf5480ba305f9801a6d59e4',
181
+ action: 'sendEmail',
182
+ notificationEndpointType: 'NET_DEBIT_CAP_ADJUSTMENT',
183
+ templateType: 'adjustment',
184
+ language: 'en',
185
+ messageSubject: 'NET_DEBIT_CAP LIMIT ADJUSTMENT',
186
+ notificationInterval: 3,
187
+ resetPeriod: 60
188
+ }
189
+ }
190
+ },
191
+ type: 'application/json',
192
+ metadata: {
193
+ event: {
194
+ id: '4276f87a-0a17-485f-acb8-f2d582a1f608',
195
+ responseTo: '88d15b71-ae0d-4e31-a285-c3fdd5982180',
196
+ type: 'notification',
197
+ action: 'event',
198
+ createdAt: '2018-12-11T13:36:58.225Z',
199
+ state: { status: 'success', code: 0, description: 'action successful' }
200
+ },
201
+ 'protocol.createdAt': 1544535418447
202
+ },
203
+ pp: ''
204
+ },
205
+ size: 1363,
206
+ key: {
207
+ type: 'Buffer',
208
+ data: [51, 48, 55, 54, 50, 51, 49, 55, 45, 54, 48, 97, 48, 45, 52, 98, 102, 52, 45, 98, 98, 97, 97, 45, 100, 50, 49, 50, 53, 101, 49, 100, 54, 52, 50, 97]
209
+ },
210
+ topic: 'topic-notification-event',
211
+ offset: 4,
212
+ partition: 0,
213
+ timestamp: 1544535418448
214
+ }
215
+ const emailer = new Email()
216
+ emailer.sendMailMessage.rejects(new Error('Failure'))
217
+ ActionObservable(mockMessage).subscribe(
218
+ () => {
219
+ assert.fail('should have thrown')
220
+ assert.end()
221
+ },
222
+ error => {
223
+ assert.equal(error.message, 'Failure')
224
+ assert.end()
225
+ })
226
+ })
227
+
228
+ await actionTest.test('Should test the actionObservable fails with incorrect action', async assert => {
229
+ const mockMessage = {
230
+ value: {
231
+ from: Config.get('HUB_PARTICIPANT').NAME,
232
+ to: 'dfsp1',
233
+ id: '694dd040-a315-4427-bcf0-e29229c4defe',
234
+ content: {
235
+ header: {},
236
+ payload: {
237
+ from: Config.get('HUB_PARTICIPANT').NAME,
238
+ to: 'dfsp1',
239
+ recepientDetails: {
240
+ _id: '5bf5480aa305f9801a6d59db',
241
+ name: 'dfsp1',
242
+ type: 'NET_DEBIT_CAP_ADJUSTMENT',
243
+ value: 'dean.bothma@modusbox.com',
244
+ action: 'Fail test',
245
+ createdAt: '2018-11-21T11:56:58.919Z',
246
+ updatedAt: '2018-11-21T14:00:38.993Z',
247
+ __v: 0
248
+ },
249
+ hubDetails: {
250
+ _id: '5bf5480aa305f9801a6d59dd',
251
+ name: 'Hub',
252
+ type: 'NET_DEBIT_CAP_ADJUSTMENT',
253
+ value: 'dean.bothma@modusbox.com',
254
+ action: 'Fail test',
255
+ createdAt: '2018-11-21T11:56:58.950Z',
256
+ updatedAt: '2018-11-21T14:00:39.077Z',
257
+ __v: 0
258
+ },
259
+ messageDetails: {
260
+ dfsp: 'dfsp1',
261
+ limitType: 'NET_DEBIT_CAP',
262
+ value: 1000,
263
+ currency: 'USD',
264
+ triggeredBy: '5bf5480ba305f9801a6d59e0',
265
+ repetitionsAllowed: 3,
266
+ fromEvent: '5bf5480ba305f9801a6d59e4',
267
+ action: 'Fail test',
268
+ notificationEndpointType: 'NET_DEBIT_CAP_ADJUSTMENT',
269
+ templateType: 'adjustment',
270
+ language: 'en',
271
+ messageSubject: 'NET_DEBIT_CAP LIMIT ADJUSTMENT',
272
+ notificationInterval: 3,
273
+ resetPeriod: 60
274
+ }
275
+ }
276
+ },
277
+ type: 'application/json',
278
+ metadata: {
279
+ event: {
280
+ id: '4276f87a-0a17-485f-acb8-f2d582a1f608',
281
+ responseTo: '88d15b71-ae0d-4e31-a285-c3fdd5982180',
282
+ type: 'notification',
283
+ action: 'event',
284
+ createdAt: '2018-12-11T13:36:58.225Z',
285
+ state: { status: 'success', code: 0, description: 'action successful' }
286
+ },
287
+ 'protocol.createdAt': 1544535418447
288
+ },
289
+ pp: ''
290
+ },
291
+ size: 1363,
292
+ key: {
293
+ type: 'Buffer',
294
+ data: [51, 48, 55, 54, 50, 51, 49, 55, 45, 54, 48, 97, 48, 45, 52, 98, 102, 52, 45, 98, 98, 97, 97, 45, 100, 50, 49, 50, 53, 101, 49, 100, 54, 52, 50, 97]
295
+ },
296
+ topic: 'topic-notification-event',
297
+ offset: 4,
298
+ partition: 0,
299
+ timestamp: 1544535418448
300
+ }
301
+ const emailer = new Email()
302
+ emailer.sendMailMessage.resolves(true)
303
+
304
+ ActionObservable(mockMessage).subscribe(
305
+ () => {
306
+ assert.fail('should have thrown')
307
+ assert.end()
308
+ },
309
+ error => {
310
+ assert.equal(error.message, 'Action are not supported')
311
+ assert.end()
312
+ })
313
+ })
314
+ await actionTest.end()
315
+ })
@@ -0,0 +1,151 @@
1
+ /* HOT observeable is the topicObservable
2
+ COLD are the rest observables */
3
+
4
+ const marbles = require('rxjs-marbles/tape').marbles
5
+ const Sinon = require('sinon')
6
+ const Test = require('tapes')(require('tape'))
7
+ // const Setup = require('../../src/setup').setup
8
+ // const Kafka = require('../../src/lib/kafka')
9
+ // const KafkaConsumer = require('@mojaloop/central-services-stream').Kafka.Consumer
10
+ // const Rx = require('rxjs')
11
+ const { filter, switchMap } = require('rxjs/operators')
12
+ const Mailer = require('../../src/nodeMailer/sendMail')
13
+ const Config = require('../../src/lib/config')
14
+
15
+ const Observables = require('../../src/observables/actions')
16
+ const hubName = Config.get('HUB_PARTICIPANT').NAME
17
+
18
+ Test('Test the action observables Setup', marbles((m, t) => {
19
+ const sandbox = Sinon.createSandbox()
20
+ // start stubbing stuff
21
+ sandbox.stub(Mailer.prototype, 'sendMailMessage')
22
+ const emailer = new Mailer()
23
+ emailer.sendMailMessage.resolves(true)
24
+
25
+ t.plan(2)
26
+
27
+ const mockMessage = {
28
+ value: {
29
+ from: hubName,
30
+ to: 'dfsp1',
31
+ id: '694dd040-a315-4427-bcf0-e29229c4defe',
32
+ content: {
33
+ header: {},
34
+ payload: {
35
+ from: Config.get('HUB_PARTICIPANT').hubName,
36
+ to: 'dfsp1',
37
+ recepientDetails: {
38
+ _id: '5bf5480aa305f9801a6d59db',
39
+ name: 'dfsp1',
40
+ type: 'NET_DEBIT_CAP_ADJUSTMENT',
41
+ value: 'dean.bothma@modusbox.com',
42
+ action: 'sendEmail',
43
+ createdAt: '2018-11-21T11:56:58.919Z',
44
+ updatedAt: '2018-11-21T14:00:38.993Z',
45
+ __v: 0
46
+ },
47
+ hubDetails: {
48
+ _id: '5bf5480aa305f9801a6d59dd',
49
+ name: 'Hub',
50
+ type: 'NET_DEBIT_CAP_ADJUSTMENT',
51
+ value: 'dean.bothma@modusbox.com',
52
+ action: 'sendEmail',
53
+ createdAt: '2018-11-21T11:56:58.950Z',
54
+ updatedAt: '2018-11-21T14:00:39.077Z',
55
+ __v: 0
56
+ },
57
+ messageDetails: {
58
+ dfsp: 'dfsp1',
59
+ limitType: 'NET_DEBIT_CAP',
60
+ value: 1000,
61
+ currency: 'USD',
62
+ triggeredBy: '5bf5480ba305f9801a6d59e0',
63
+ repetitionsAllowed: 3,
64
+ fromEvent: '5bf5480ba305f9801a6d59e4',
65
+ action: 'sendEmail',
66
+ notificationEndpointType: 'NET_DEBIT_CAP_ADJUSTMENT',
67
+ templateType: 'adjustment',
68
+ language: 'en',
69
+ messageSubject: 'NET_DEBIT_CAP LIMIT ADJUSTMENT',
70
+ notificationInterval: 3,
71
+ resetPeriod: 60
72
+ }
73
+ }
74
+ },
75
+ type: 'application/json',
76
+ metadata: {
77
+ event: {
78
+ id: '4276f87a-0a17-485f-acb8-f2d582a1f608',
79
+ responseTo: '88d15b71-ae0d-4e31-a285-c3fdd5982180',
80
+ type: 'notification',
81
+ action: 'event',
82
+ createdAt: '2018-12-11T13:36:58.225Z',
83
+ state: { status: 'success', code: 0, description: 'action successful' }
84
+ },
85
+ 'protocol.createdAt': 1544535418447
86
+ },
87
+ pp: ''
88
+ },
89
+ size: 1363,
90
+ key: {
91
+ type: 'Buffer',
92
+ data: [51, 48, 55, 54, 50, 51, 49, 55, 45, 54, 48, 97, 48, 45, 52, 98, 102, 52, 45, 98, 98, 97, 97, 45, 100, 50, 49, 50, 53, 101, 49, 100, 54, 52, 50, 97]
93
+ },
94
+ topic: 'topic-notification-event',
95
+ offset: 4,
96
+ partition: 0,
97
+ timestamp: 1544535418448
98
+ }
99
+
100
+ const inputs = {
101
+ a: mockMessage,
102
+ b: {}
103
+ }
104
+
105
+ const outputs = {
106
+ r: {
107
+ dfspMailResult: true,
108
+ hubMailResult: true
109
+ }
110
+ }
111
+
112
+ const source = m.cold('-a', inputs) // topic observable
113
+ const subs = '^a'
114
+ const expected = m.cold('-r', outputs)
115
+
116
+ const destination = source
117
+ .pipe(filter(data => data.value.from === hubName),
118
+ switchMap(Observables.actionObservable))
119
+
120
+ // const subscription = destination.subscribe()
121
+ m.expect(source).toHaveSubscriptions(subs)
122
+ m.expect(destination).toBeObservable(expected)
123
+
124
+ t.end()
125
+ })
126
+
127
+ )
128
+
129
+ // ?=> {
130
+ // let sandbox
131
+ // let ConsumerStub
132
+ // let UtilityStub
133
+ // let LoggerStub
134
+ // let RxStub
135
+ // let filterStub
136
+ // let switchMapStub
137
+ // let ObservablesStub
138
+ // let healthcheckStub
139
+
140
+ // setupTest.beforeEach(t => {
141
+ // sandbox = Sinon.createSandbox()
142
+ // sandbox.stub(KafkaConsumer.prototype, 'constructor').resolves()
143
+ // sandbox.stub(KafkaConsumer.prototype, 'connect').resolves()
144
+ // sandbox.stub(KafkaConsumer.prototype, 'consume').resolves()
145
+ // sandbox.stub(KafkaConsumer.prototype, 'commitMessageSync').resolves()
146
+ // sandbox.stub(Kafka.Consumer, 'getConsumer').returns({
147
+ // commitMessageSync: async function () { return true }
148
+ // })
149
+ // sandbox.stub(Rx.prototype, 'Observable')
150
+ // })
151
+ // })