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,123 @@
1
+ const Sinon = require('sinon')
2
+ const Test = require('tapes')(require('tape'))
3
+ const Proxyquire = require('proxyquire')
4
+ const Config = require('../../src/lib/config')
5
+
6
+ Test('Setup test', async setupTest => {
7
+ let sandbox,
8
+ setupProxy,
9
+ subStub,
10
+ pipeStub,
11
+ operatorsStub,
12
+ conStub,
13
+ ConsumerStub,
14
+ UtilityStub,
15
+ RxStub,
16
+ ObservablesStub,
17
+ createHealthCheckServerStub,
18
+ HealthCheckConstructorStub
19
+
20
+ const topicName = 'test-topic'
21
+ setupTest.beforeEach(t => {
22
+ try {
23
+ sandbox = Sinon.createSandbox()
24
+
25
+ conStub = {
26
+ commitMessageSync: sandbox.stub().returns(async function () { return true }),
27
+ consume: sandbox.stub().resolves(),
28
+ _status: { running: true }
29
+ }
30
+
31
+ subStub = {
32
+ subscribe: sandbox.stub().returns(true)
33
+ }
34
+
35
+ pipeStub = {
36
+ pipe: sandbox.stub().returns(subStub)
37
+ }
38
+
39
+ RxStub = {
40
+ Observable: {
41
+ create: sandbox.stub().returns(pipeStub)
42
+ }
43
+ }
44
+
45
+ operatorsStub = {
46
+ filter: sandbox.stub().returns(() => {}),
47
+ switchMap: sandbox.stub().returns(() => {})
48
+ }
49
+
50
+ ObservablesStub = {
51
+ actionObservable: sandbox.stub()
52
+ }
53
+
54
+ HealthCheckConstructorStub = sandbox.stub()
55
+ const mockHealthCheck = class HealthCheckStubbed {
56
+ constructor () {
57
+ HealthCheckConstructorStub()
58
+ }
59
+ }
60
+
61
+ createHealthCheckServerStub = sandbox.stub().returns()
62
+
63
+ UtilityStub = {
64
+ trantransformGeneralTopicName: sandbox.stub().returns(topicName)
65
+ }
66
+
67
+ ConsumerStub = {
68
+ registerNotificationHandler: sandbox.stub().resolves(),
69
+ isConsumerAutoCommitEnabled: sandbox.stub().returns(true),
70
+ getConsumer: sandbox.stub().returns(conStub)
71
+ }
72
+
73
+ setupProxy = Proxyquire('../../src/setup', {
74
+ rxjs: RxStub,
75
+ './observables': ObservablesStub,
76
+ '@mojaloop/central-services-health': {
77
+ createHealthCheckServer: createHealthCheckServerStub,
78
+ defaultHealthHandler: () => {}
79
+ },
80
+ '@mojaloop/central-services-shared': {
81
+ HealthCheck: {
82
+ HealthCheck: mockHealthCheck,
83
+ HealthCheckEnums: {
84
+ serviceName: {
85
+ broker: 'broker'
86
+ }
87
+ }
88
+ }
89
+ },
90
+ 'rxjs/operators': operatorsStub,
91
+ './lib/utility': UtilityStub,
92
+ './lib/kafka/consumer': ConsumerStub
93
+ })
94
+ } catch (e) {
95
+ console.error(e)
96
+ }
97
+ t.end()
98
+ })
99
+
100
+ setupTest.afterEach(t => {
101
+ sandbox.restore()
102
+ t.end()
103
+ })
104
+
105
+ await setupTest.test('setup should', async assert => {
106
+ try {
107
+ const result = await setupProxy.setup()
108
+ assert.ok(result, 'Notifier setup finished')
109
+ assert.ok(createHealthCheckServerStub.calledOnce, 'healthCheck initialized')
110
+ assert.ok(createHealthCheckServerStub.withArgs(Config.get('PORT'), () => {}))
111
+ assert.ok(HealthCheckConstructorStub.calledOnce, 'HealthCheck constructor called')
112
+
113
+ assert.ok(RxStub.Observable.create.calledOnce, 'Observable created')
114
+ assert.ok(operatorsStub.filter.calledOnce, 'Filter created')
115
+ assert.end()
116
+ } catch (e) {
117
+ console.error(e)
118
+ assert.end()
119
+ }
120
+ })
121
+
122
+ setupTest.end()
123
+ })
File without changes
@@ -0,0 +1,97 @@
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 Sinon = require('sinon')
28
+ const Templates = require('../../../templates/index')
29
+ const Test = require('tapes')(require('tape'))
30
+ const fs = require('fs')
31
+ const { promisify } = require('util')
32
+ const readFilePromise = promisify(fs.readFile)
33
+ const Path = require('path')
34
+
35
+ Test('Templates unit tests (Index.js) : ', async templateTest => {
36
+ let sandbox
37
+ templateTest.beforeEach(t => {
38
+ // create a sandbox
39
+ sandbox = Sinon.createSandbox()
40
+ // start stubbing stuff
41
+ t.end()
42
+ })
43
+
44
+ templateTest.afterEach(t => {
45
+ // restore the environment as it was before
46
+ sandbox.restore()
47
+ t.end()
48
+ })
49
+
50
+ await templateTest.test(' getTemplateNamesByType should throw an error when incorrect path is given.', async assert => {
51
+ try {
52
+ await Templates.loadTemplates('/test', 'mustache')
53
+ assert.fail('should throw')
54
+ assert.end()
55
+ } catch (e) {
56
+ assert.ok(e instanceof Error)
57
+ assert.end()
58
+ }
59
+ })
60
+
61
+ await templateTest.test('Load templates should throw an error if template is empty or cannot be loaded.', async assert => {
62
+ try {
63
+ await Templates.loadTemplates('../test/unit/templates', 'mustache')
64
+ assert.fail('should throw')
65
+ assert.end()
66
+ } catch (e) {
67
+ assert.equal(e.message, 'Templates cannot be loaded')
68
+ assert.end()
69
+ }
70
+ })
71
+
72
+ await templateTest.test('Load templates should throw an error if template is incorrect or missing type is given.', async assert => {
73
+ try {
74
+ await Templates.loadTemplates('../test/unit/templates', 'wrong')
75
+ assert.fail('should throw')
76
+ assert.end()
77
+ } catch (e) {
78
+ assert.equal(e.message, 'No such template type')
79
+ assert.end()
80
+ }
81
+ })
82
+
83
+ await templateTest.test('Load templates should load test template.', async assert => {
84
+ try {
85
+ const dirPath = Path.join(__dirname, 'ok.template')
86
+ const okTemplate = await readFilePromise(dirPath, { encoding: 'utf8' })
87
+ const result = await Templates.loadTemplates('../test/unit/templates', 'template')
88
+ assert.equal(result.ok, okTemplate)
89
+ assert.end()
90
+ } catch (e) {
91
+ assert.fail('error was thrown')
92
+ assert.end()
93
+ }
94
+ })
95
+
96
+ await templateTest.end()
97
+ })
@@ -0,0 +1 @@
1
+ test is ok