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.
- package/.circleci/config.yml +11 -0
- package/.dockerignore +17 -0
- package/.github/ISSUE_TEMPLATE/config.yml +1 -0
- package/.github/ISSUE_TEMPLATE/no-issue-template.md +18 -0
- package/.ncurc.yaml +2 -0
- package/.nvmrc +1 -0
- package/.nycrc.yml +19 -0
- package/.versionrc +15 -0
- package/CHANGELOG.md +68 -0
- package/CODEOWNERS +5 -0
- package/Dockerfile +44 -0
- package/LICENSE.md +10 -0
- package/README.md +135 -0
- package/app.js +34 -0
- package/audit-ci.jsonc +9 -0
- package/config/custom-environment-variables.json +17 -0
- package/config/default.json +96 -0
- package/istanbul.yml +14 -0
- package/onboarding.md +182 -0
- package/package.json +114 -0
- package/src/lib/config.js +3 -0
- package/src/lib/enum.js +149 -0
- package/src/lib/healthCheck/subServiceHealth.js +83 -0
- package/src/lib/kafka/consumer.js +200 -0
- package/src/lib/kafka/index.js +43 -0
- package/src/lib/kafka/producer.js- +136 -0
- package/src/lib/utility.js +251 -0
- package/src/nodeMailer/sendMail.js +101 -0
- package/src/observables/actions.js +91 -0
- package/src/observables/index.js +30 -0
- package/src/setup.js +81 -0
- package/templates/en/adjustment/dfspEmail.mustache +7 -0
- package/templates/en/adjustment/hubEmail.mustache +4 -0
- package/templates/en/breach/dfspEmail.mustache +11 -0
- package/templates/en/breach/hubEmail.mustache +10 -0
- package/templates/en/position/dfspEmail.mustache +6 -0
- package/templates/en/position/hubEmail.mustache +5 -0
- package/templates/index.js +36 -0
- package/test/messageSubmitter.js +21 -0
- package/test/unit/hanlder.test--.js +944 -0
- package/test/unit/lib/healthCheck/subServiceHealth.test.js +110 -0
- package/test/unit/lib/kafka/consumer.test.js +365 -0
- package/test/unit/lib/kafka/producer.test--.js +323 -0
- package/test/unit/lib/utility.test.js +152 -0
- package/test/unit/nodeMailer/sendMail.test.js +239 -0
- package/test/unit/observables/action.test.js +315 -0
- package/test/unit/setup.mmtest.js +151 -0
- package/test/unit/setup.test.js +123 -0
- package/test/unit/templates/empty.mustache +0 -0
- package/test/unit/templates/index.test.js +97 -0
- package/test/unit/templates/ok.template +1 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const Test = require('tapes')(require('tape'))
|
|
4
|
+
const Sinon = require('sinon')
|
|
5
|
+
const { statusEnum, serviceName } = require('@mojaloop/central-services-shared').HealthCheck.HealthCheckEnums
|
|
6
|
+
|
|
7
|
+
const Mailer = require('../../../../src/nodeMailer/sendMail')
|
|
8
|
+
const Consumer = require('../../../../src/lib/kafka/consumer')
|
|
9
|
+
const {
|
|
10
|
+
getSubServiceHealthBroker,
|
|
11
|
+
getSubServiceHealthSMTP
|
|
12
|
+
} = require('../../../../src/lib/healthCheck/subServiceHealth')
|
|
13
|
+
|
|
14
|
+
const mailer = Mailer.sharedInstance()
|
|
15
|
+
|
|
16
|
+
Test('SubServiceHealth test', function (subServiceHealthTest) {
|
|
17
|
+
let sandbox
|
|
18
|
+
|
|
19
|
+
subServiceHealthTest.beforeEach(t => {
|
|
20
|
+
sandbox = Sinon.createSandbox()
|
|
21
|
+
sandbox.stub(Consumer, 'getListOfTopics')
|
|
22
|
+
sandbox.stub(Consumer, 'isConnected')
|
|
23
|
+
sandbox.stub(mailer.transporter, 'verify')
|
|
24
|
+
|
|
25
|
+
t.end()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
subServiceHealthTest.afterEach(t => {
|
|
29
|
+
sandbox.restore()
|
|
30
|
+
|
|
31
|
+
t.end()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
subServiceHealthTest.test('getSubServiceHealthSMTP', smtpTest => {
|
|
35
|
+
smtpTest.test('passes when transporter.verify() suceeds', async test => {
|
|
36
|
+
// Arrange
|
|
37
|
+
mailer.transporter.verify.resolves()
|
|
38
|
+
const expected = { name: serviceName.smtpServer, status: statusEnum.OK }
|
|
39
|
+
|
|
40
|
+
// Act
|
|
41
|
+
const result = await getSubServiceHealthSMTP()
|
|
42
|
+
|
|
43
|
+
// Assert
|
|
44
|
+
test.deepEqual(result, expected, 'getSubServiceHealthSMTP should match expected result')
|
|
45
|
+
test.end()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
smtpTest.test('fails when transporter.verify() fails', async test => {
|
|
49
|
+
// Arrange
|
|
50
|
+
mailer.transporter.verify.throws(new Error('Authentication failed'))
|
|
51
|
+
const expected = { name: serviceName.smtpServer, status: statusEnum.DOWN }
|
|
52
|
+
|
|
53
|
+
// Act
|
|
54
|
+
const result = await getSubServiceHealthSMTP()
|
|
55
|
+
|
|
56
|
+
// Assert
|
|
57
|
+
test.deepEqual(result, expected, 'getSubServiceHealthSMTP should match expected result')
|
|
58
|
+
test.end()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
smtpTest.end()
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
subServiceHealthTest.test('getSubServiceHealthBroker', brokerTest => {
|
|
65
|
+
brokerTest.test('broker test passes when there are no topics', async test => {
|
|
66
|
+
// Arrange
|
|
67
|
+
Consumer.getListOfTopics.returns([])
|
|
68
|
+
const expected = { name: serviceName.broker, status: statusEnum.OK }
|
|
69
|
+
|
|
70
|
+
// Act
|
|
71
|
+
const result = await getSubServiceHealthBroker()
|
|
72
|
+
|
|
73
|
+
// Assert
|
|
74
|
+
test.deepEqual(result, expected, 'getSubServiceHealthBroker should match expected result')
|
|
75
|
+
test.end()
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
brokerTest.test('broker test fails when one broker cannot connect', async test => {
|
|
79
|
+
// Arrange
|
|
80
|
+
Consumer.getListOfTopics.returns(['admin1', 'admin2'])
|
|
81
|
+
Consumer.isConnected.throws(new Error('Not connected!'))
|
|
82
|
+
const expected = { name: serviceName.broker, status: statusEnum.DOWN }
|
|
83
|
+
|
|
84
|
+
// Act
|
|
85
|
+
const result = await getSubServiceHealthBroker()
|
|
86
|
+
|
|
87
|
+
// Assert
|
|
88
|
+
test.deepEqual(result, expected, 'getSubServiceHealthBroker should match expected result')
|
|
89
|
+
test.end()
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
brokerTest.test('Passes when it connects', async test => {
|
|
93
|
+
// Arrange
|
|
94
|
+
Consumer.getListOfTopics.returns(['admin1', 'admin2'])
|
|
95
|
+
Consumer.isConnected.returns(Promise.resolve(true))
|
|
96
|
+
const expected = { name: serviceName.broker, status: statusEnum.OK }
|
|
97
|
+
|
|
98
|
+
// Act
|
|
99
|
+
const result = await getSubServiceHealthBroker()
|
|
100
|
+
|
|
101
|
+
// Assert
|
|
102
|
+
test.deepEqual(result, expected, 'getSubServiceHealthBroker should match expected result')
|
|
103
|
+
test.end()
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
brokerTest.end()
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
subServiceHealthTest.end()
|
|
110
|
+
})
|
|
@@ -0,0 +1,365 @@
|
|
|
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
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
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.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Gates Foundation organization for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Gates Foundation
|
|
23
|
+
- Name Surname <name.surname@gatesfoundation.com>
|
|
24
|
+
|
|
25
|
+
* Georgi Georgiev <georgi.georgiev@modusbox.com>
|
|
26
|
+
* Lewis Daly <lewis@vesselstech.com>
|
|
27
|
+
|
|
28
|
+
--------------
|
|
29
|
+
******/
|
|
30
|
+
'use strict'
|
|
31
|
+
|
|
32
|
+
const src = '../../../../src'
|
|
33
|
+
const Test = require('tapes')(require('tape'))
|
|
34
|
+
const Sinon = require('sinon')
|
|
35
|
+
const rewire = require('rewire')
|
|
36
|
+
const KafkaConsumer = require('@mojaloop/central-services-stream').Kafka.Consumer
|
|
37
|
+
|
|
38
|
+
const Consumer = require(`${src}/lib/kafka/consumer`)
|
|
39
|
+
|
|
40
|
+
Test('Consumer', ConsumerTest => {
|
|
41
|
+
let sandbox
|
|
42
|
+
|
|
43
|
+
ConsumerTest.beforeEach(test => {
|
|
44
|
+
sandbox = Sinon.createSandbox()
|
|
45
|
+
sandbox.stub(KafkaConsumer.prototype, 'constructor').resolves()
|
|
46
|
+
sandbox.stub(KafkaConsumer.prototype, 'connect').resolves()
|
|
47
|
+
sandbox.stub(KafkaConsumer.prototype, 'consume').resolves()
|
|
48
|
+
sandbox.stub(KafkaConsumer.prototype, 'commitMessageSync').resolves()
|
|
49
|
+
sandbox.stub(KafkaConsumer.prototype, 'getMetadata').resolves()
|
|
50
|
+
test.end()
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
ConsumerTest.afterEach(test => {
|
|
54
|
+
sandbox.restore()
|
|
55
|
+
test.end()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
ConsumerTest.test('isConnected should', isConnectedTest => {
|
|
59
|
+
isConnectedTest.test('return true if connected', async test => {
|
|
60
|
+
// Arrange
|
|
61
|
+
const topicName = 'admin'
|
|
62
|
+
const config = { rdkafkaConf: {} }
|
|
63
|
+
const getMetadataPromiseStub = sandbox.stub()
|
|
64
|
+
const metadata = {
|
|
65
|
+
orig_broker_id: 0,
|
|
66
|
+
orig_broker_name: 'kafka:9092/0',
|
|
67
|
+
topics: [
|
|
68
|
+
{ name: 'admin', partitions: [] }
|
|
69
|
+
],
|
|
70
|
+
brokers: [{ id: 0, host: 'kafka', port: 9092 }]
|
|
71
|
+
}
|
|
72
|
+
getMetadataPromiseStub.returns(Promise.resolve(metadata))
|
|
73
|
+
const ConsumerProxy = rewire(`${src}/lib/kafka/consumer`)
|
|
74
|
+
ConsumerProxy.__set__('getMetadataPromise', getMetadataPromiseStub)
|
|
75
|
+
|
|
76
|
+
// Act
|
|
77
|
+
await ConsumerProxy.createHandler(topicName, config)
|
|
78
|
+
const result = await ConsumerProxy.isConnected(topicName)
|
|
79
|
+
|
|
80
|
+
// Assert
|
|
81
|
+
test.equal(result, true, 'The consumer is connected')
|
|
82
|
+
test.end()
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
isConnectedTest.test('throw if the topic cannot be found', async test => {
|
|
86
|
+
// Arrange
|
|
87
|
+
const topicName = 'random-topic'
|
|
88
|
+
const ConsumerProxy = rewire(`${src}/lib/kafka/consumer`)
|
|
89
|
+
// Don't register any topics
|
|
90
|
+
|
|
91
|
+
// Act
|
|
92
|
+
try {
|
|
93
|
+
await ConsumerProxy.isConnected(topicName)
|
|
94
|
+
test.fail('should have thrown an exception')
|
|
95
|
+
} catch (err) {
|
|
96
|
+
test.equal(err.message, `No consumer found for topic ${topicName}`, 'The error messages match.')
|
|
97
|
+
test.pass('Threw an exception when the topic was not found')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Assert
|
|
101
|
+
test.end()
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
isConnectedTest.test('throw if not connected', async test => {
|
|
105
|
+
// Arrange
|
|
106
|
+
const topicName = 'admin'
|
|
107
|
+
const config = { rdkafkaConf: {} }
|
|
108
|
+
const getMetadataPromiseStub = sandbox.stub()
|
|
109
|
+
const metadata = {
|
|
110
|
+
orig_broker_id: 0,
|
|
111
|
+
orig_broker_name: 'kafka:9092/0',
|
|
112
|
+
topics: [
|
|
113
|
+
{ name: 'not-admin', partitions: [] }
|
|
114
|
+
],
|
|
115
|
+
brokers: [{ id: 0, host: 'kafka', port: 9092 }]
|
|
116
|
+
}
|
|
117
|
+
getMetadataPromiseStub.returns(Promise.resolve(metadata))
|
|
118
|
+
const ConsumerProxy = rewire(`${src}/lib/kafka/consumer`)
|
|
119
|
+
ConsumerProxy.__set__('getMetadataPromise', getMetadataPromiseStub)
|
|
120
|
+
|
|
121
|
+
// Act
|
|
122
|
+
await ConsumerProxy.createHandler(topicName, config)
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
await ConsumerProxy.isConnected(topicName)
|
|
126
|
+
test.fail('should have thrown an exception')
|
|
127
|
+
} catch (err) {
|
|
128
|
+
test.equal(err.message, `Connected to consumer, but ${topicName} not found.`, 'The error messages match.')
|
|
129
|
+
test.pass('Threw an exception when the topic was not found')
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Assert
|
|
133
|
+
test.end()
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
isConnectedTest.end()
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
ConsumerTest.test('createHandler should', createHandlerTest => {
|
|
140
|
+
createHandlerTest.test('not throw error if it fails to connect', async (test) => {
|
|
141
|
+
const topicName = 'admin'
|
|
142
|
+
const config = { rdkafkaConf: {} }
|
|
143
|
+
KafkaConsumer.prototype.constructor.throws(new Error())
|
|
144
|
+
KafkaConsumer.prototype.connect.throws(new Error())
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
await Consumer.createHandler(topicName, config)
|
|
148
|
+
test.pass('Created handler in spite of failure to connect.')
|
|
149
|
+
} catch (err) {
|
|
150
|
+
test.fail(`Should not have thrown err: ${err.message}`)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
test.end()
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
createHandlerTest.test('handle arrays', async (test) => {
|
|
157
|
+
const topicName = ['admin2', 'admin1']
|
|
158
|
+
const config = { rdkafkaConf: {} }
|
|
159
|
+
try {
|
|
160
|
+
await Consumer.createHandler(topicName, config)
|
|
161
|
+
test.pass('passed')
|
|
162
|
+
} catch (err) {
|
|
163
|
+
test.fail('Error Thrown')
|
|
164
|
+
}
|
|
165
|
+
test.end()
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
createHandlerTest.test('topic is still added if fails to connect', async (test) => {
|
|
169
|
+
// Arrange
|
|
170
|
+
const ConsumerProxy = rewire(`${src}/lib/kafka/consumer`)
|
|
171
|
+
const topicName = 'admin'
|
|
172
|
+
const config = { rdkafkaConf: {} }
|
|
173
|
+
KafkaConsumer.prototype.connect.throws(new Error())
|
|
174
|
+
|
|
175
|
+
// Act
|
|
176
|
+
await ConsumerProxy.createHandler(topicName, config)
|
|
177
|
+
const topics = ConsumerProxy.getListOfTopics()
|
|
178
|
+
|
|
179
|
+
// Assert
|
|
180
|
+
test.deepEqual(topics, [topicName], 'Topic should still be in list even if consumer failed to connect.')
|
|
181
|
+
test.end()
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
createHandlerTest.test('should have a timestamp of 0 if couldn\'t connect', async test => {
|
|
185
|
+
// Arrange
|
|
186
|
+
const ConsumerProxy = rewire(`${src}/lib/kafka/consumer`)
|
|
187
|
+
const topicName = ['admin2', 'admin1']
|
|
188
|
+
const config = { rdkafkaConf: {} }
|
|
189
|
+
KafkaConsumer.prototype.connect.throws(new Error())
|
|
190
|
+
|
|
191
|
+
// Act
|
|
192
|
+
await ConsumerProxy.createHandler(topicName, config)
|
|
193
|
+
const result = ConsumerProxy.__get__('listOfConsumers')
|
|
194
|
+
const timestamps = Object.keys(result).map(k => result[k].connectedTimeStamp)
|
|
195
|
+
|
|
196
|
+
// Assert
|
|
197
|
+
test.deepEqual(timestamps, [0, 0], 'Timestamps should be 0')
|
|
198
|
+
test.end()
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
createHandlerTest.test('should contain a timestamp of when it connected', async test => {
|
|
202
|
+
// Arrange
|
|
203
|
+
const ConsumerProxy = rewire(`${src}/lib/kafka/consumer`)
|
|
204
|
+
const topicName = ['admin2', 'admin1']
|
|
205
|
+
const config = { rdkafkaConf: {} }
|
|
206
|
+
// KafkaConsumer.prototype.connect.throws(new Error())
|
|
207
|
+
|
|
208
|
+
// Act
|
|
209
|
+
await ConsumerProxy.createHandler(topicName, config)
|
|
210
|
+
const result = ConsumerProxy.__get__('listOfConsumers')
|
|
211
|
+
const timestamps = Object.keys(result).map(k => result[k].connectedTimeStamp)
|
|
212
|
+
|
|
213
|
+
// Assert
|
|
214
|
+
timestamps.forEach(ts => test.ok(ts > 0, 'Timestamp should be greater than 0'))
|
|
215
|
+
test.end()
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
createHandlerTest.end()
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
ConsumerTest.test('getListOfTopics should', getListOfTopicsTest => {
|
|
222
|
+
getListOfTopicsTest.test('return an empty array when there are no topics', test => {
|
|
223
|
+
// Arrange
|
|
224
|
+
const ConsumerProxy = rewire(`${src}/lib/kafka/consumer`)
|
|
225
|
+
ConsumerProxy.__set__('listOfConsumers', {})
|
|
226
|
+
const expected = []
|
|
227
|
+
|
|
228
|
+
// Act
|
|
229
|
+
const result = ConsumerProxy.getListOfTopics()
|
|
230
|
+
|
|
231
|
+
// Assert
|
|
232
|
+
test.deepEqual(result, expected, 'Should return an empty array')
|
|
233
|
+
test.end()
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
getListOfTopicsTest.test('return a list of topics', test => {
|
|
237
|
+
// Arrange
|
|
238
|
+
const ConsumerProxy = rewire(`${src}/lib/kafka/consumer`)
|
|
239
|
+
ConsumerProxy.__set__('listOfConsumers', { admin1: {}, admin2: {} })
|
|
240
|
+
const expected = ['admin1', 'admin2']
|
|
241
|
+
|
|
242
|
+
// Act
|
|
243
|
+
const result = ConsumerProxy.getListOfTopics()
|
|
244
|
+
|
|
245
|
+
// Assert
|
|
246
|
+
test.deepEqual(result, expected, 'Should return an empty array')
|
|
247
|
+
test.end()
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
getListOfTopicsTest.end()
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
ConsumerTest.test('getConsumer should', getConsumerTest => {
|
|
254
|
+
const topicName = 'admin'
|
|
255
|
+
const expected = 'consumer'
|
|
256
|
+
|
|
257
|
+
getConsumerTest.test('return list of consumers', async (test) => {
|
|
258
|
+
const ConsumerProxy = rewire(`${src}/lib/kafka/consumer`)
|
|
259
|
+
ConsumerProxy.__set__('listOfConsumers', {
|
|
260
|
+
admin: {
|
|
261
|
+
consumer: expected
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
try {
|
|
265
|
+
const result = await ConsumerProxy.getConsumer(topicName)
|
|
266
|
+
test.equal(result, expected)
|
|
267
|
+
} catch (err) {
|
|
268
|
+
test.fail()
|
|
269
|
+
}
|
|
270
|
+
test.end()
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
getConsumerTest.test('throw error', async (test) => {
|
|
274
|
+
const ConsumerProxy = rewire(`${src}/lib/kafka/consumer`)
|
|
275
|
+
try {
|
|
276
|
+
await ConsumerProxy.getConsumer(topicName)
|
|
277
|
+
test.fail('Error not thrown!')
|
|
278
|
+
} catch (err) {
|
|
279
|
+
test.pass()
|
|
280
|
+
}
|
|
281
|
+
test.end()
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
getConsumerTest.end()
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
ConsumerTest.test('isConsumerAutoCommitEnabled should', isConsumerAutoCommitEnabledTest => {
|
|
288
|
+
const topicName = 'admin'
|
|
289
|
+
|
|
290
|
+
isConsumerAutoCommitEnabledTest.test('throw error', async (test) => {
|
|
291
|
+
const ConsumerProxy = rewire(`${src}/lib/kafka/consumer`)
|
|
292
|
+
try {
|
|
293
|
+
await ConsumerProxy.isConsumerAutoCommitEnabled(topicName)
|
|
294
|
+
test.fail('Error not thrown!')
|
|
295
|
+
} catch (err) {
|
|
296
|
+
test.pass('Successfully threw error')
|
|
297
|
+
}
|
|
298
|
+
test.end()
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
isConsumerAutoCommitEnabledTest.test('return result', async (test) => {
|
|
302
|
+
// Arrange
|
|
303
|
+
const topics = ['admin2', 'admin1']
|
|
304
|
+
const config = { rdkafkaConf: {} }
|
|
305
|
+
const ConsumerProxy = rewire(`${src}/lib/kafka/consumer`)
|
|
306
|
+
await ConsumerProxy.createHandler(topics, config)
|
|
307
|
+
|
|
308
|
+
// Act
|
|
309
|
+
try {
|
|
310
|
+
const result = await ConsumerProxy.isConsumerAutoCommitEnabled('admin1')
|
|
311
|
+
|
|
312
|
+
// Assert
|
|
313
|
+
test.equal(result, true, 'isConsumerAutoCommitEnabled is true')
|
|
314
|
+
} catch (err) {
|
|
315
|
+
test.fail(`Should not have thrown err: ${err.message}`)
|
|
316
|
+
}
|
|
317
|
+
test.end()
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
isConsumerAutoCommitEnabledTest.end()
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
ConsumerTest.test('registerNotificationHandler should', async registerTests => {
|
|
324
|
+
registerTests.test('fail if the Consumer fails to connect', async test => {
|
|
325
|
+
// Arrange
|
|
326
|
+
KafkaConsumer.prototype.constructor.throws(new Error())
|
|
327
|
+
KafkaConsumer.prototype.connect.throws(new Error('Failed to connect'))
|
|
328
|
+
KafkaConsumer.prototype.getMetadata.throws(new Error('Failed to get metadata'))
|
|
329
|
+
|
|
330
|
+
// Act
|
|
331
|
+
try {
|
|
332
|
+
await Consumer.registerNotificationHandler()
|
|
333
|
+
test.fail('Should have thrown an error')
|
|
334
|
+
} catch (err) {
|
|
335
|
+
// Assert
|
|
336
|
+
test.pass('Successfully threw error when attempting to connect to consumer')
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
test.end()
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
registerTests.test('connect to the consumer', async test => {
|
|
343
|
+
// Arrange
|
|
344
|
+
const isConnectedStub = sandbox.stub()
|
|
345
|
+
isConnectedStub.returns(Promise.resolve(true))
|
|
346
|
+
const ConsumerProxy = rewire(`${src}/lib/kafka/consumer`)
|
|
347
|
+
ConsumerProxy.__set__('isConnected', isConnectedStub)
|
|
348
|
+
|
|
349
|
+
// Act
|
|
350
|
+
try {
|
|
351
|
+
await ConsumerProxy.registerNotificationHandler()
|
|
352
|
+
// Assert
|
|
353
|
+
test.pass('Successfully connected to the consumer')
|
|
354
|
+
} catch (err) {
|
|
355
|
+
test.fail('Should not have thrown an error')
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
test.end()
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
registerTests.end()
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
ConsumerTest.end()
|
|
365
|
+
})
|