@mojaloop/ml-testing-toolkit-client-lib 0.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 (41) hide show
  1. package/.circleci/config.yml +502 -0
  2. package/.dockerignore +10 -0
  3. package/.nvmrc +1 -0
  4. package/CHANGELOG.md +5 -0
  5. package/Dockerfile +25 -0
  6. package/LICENSE.md +10 -0
  7. package/README.md +213 -0
  8. package/audit-resolve.json +14 -0
  9. package/bin/cli.js +2 -0
  10. package/jest.config.js +16 -0
  11. package/native-app-generation/assets/macos/start.sh +7 -0
  12. package/native-app-generation/build-native-app.sh +57 -0
  13. package/package.json +132 -0
  14. package/src/client.js +49 -0
  15. package/src/extras/s3-upload.js +69 -0
  16. package/src/extras/slack-broadcast.js +149 -0
  17. package/src/modes/monitoring.js +32 -0
  18. package/src/modes/outbound.js +179 -0
  19. package/src/modes/testcaseDefinitionReport.js +53 -0
  20. package/src/objectStore.js +39 -0
  21. package/src/router.js +110 -0
  22. package/src/sample-config.json +11 -0
  23. package/src/utils/file-utils.js +53 -0
  24. package/src/utils/listeners.js +46 -0
  25. package/src/utils/logger.js +93 -0
  26. package/src/utils/report.js +127 -0
  27. package/src/utils/templateGenerator.js +65 -0
  28. package/test/lib/mockRequest.js +38 -0
  29. package/test/lib/mockResponse.js +53 -0
  30. package/test/unit/client.test.js +36 -0
  31. package/test/unit/extras/s3-upload.test.js +99 -0
  32. package/test/unit/extras/slack-broadcast.test.js +125 -0
  33. package/test/unit/listener.test.js +58 -0
  34. package/test/unit/logger.test.js +259 -0
  35. package/test/unit/monitoring-mode.test.js +38 -0
  36. package/test/unit/outbound-mode.test.js +192 -0
  37. package/test/unit/report.test.js +258 -0
  38. package/test/unit/router.test.js +110 -0
  39. package/test/unit/templateGenerator.test.js +119 -0
  40. package/test/unit/testcaseDefinitionReport-mode.test.js +72 -0
  41. package/test/util/testConfig.js +38 -0
@@ -0,0 +1,258 @@
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
+
20
+ * ModusBox
21
+ * Georgi Logodazhki <georgi.logodazhki@modusbox.com> (Original Author)
22
+ --------------
23
+ ******/
24
+ 'use strict'
25
+
26
+ const util = require('util')
27
+ const spyPromisify = jest.spyOn(util, 'promisify')
28
+ const axios = require('axios')
29
+ jest.mock('axios')
30
+ const objectStore = require('../../src/objectStore')
31
+ const spyObjectStoreGet = jest.spyOn(objectStore, 'get')
32
+ const s3Upload = require('../../src/extras/s3-upload')
33
+ jest.mock('../../src/extras/s3-upload')
34
+ const report = require('../../src/utils/report')
35
+ const Utils = require('../../src/utils/file-utils')
36
+ const SpyWriteFileAsync = jest.spyOn(Utils, 'writeFileAsync')
37
+
38
+
39
+
40
+ const data = {
41
+ runtimeInformation: {
42
+ completedTimeISO: "2020-05-07T10:44:01.687Z"
43
+ }
44
+ }
45
+
46
+ describe('Cli client', () => {
47
+ describe('run testcaseDefinitionReport functionality', () => {
48
+ it('when the report format is json should not throw an error', async () => {
49
+ spyPromisify.mockReturnValueOnce(jest.fn())
50
+ const config = {
51
+ reportFormat: 'json'
52
+ }
53
+ objectStore.set('config', config)
54
+ await expect(report.testcaseDefinition(data)).resolves.not.toBeNull
55
+ })
56
+ })
57
+ describe('run outbound functionality', () => {
58
+ it('when the report format is json should not throw an error', async () => {
59
+ spyPromisify.mockReturnValueOnce(jest.fn())
60
+ const config = {
61
+ reportFormat: 'json'
62
+ }
63
+ objectStore.set('config', config)
64
+ await expect(report.outbound(data)).resolves.not.toBeNull
65
+ })
66
+ it('when the report format is html and reportAutoFilenameEnable present should not throw an error', async () => {
67
+ const response = {
68
+ 'headers': {
69
+ 'content-disposition': 'attachment; filename=TTK-Assertion-Report-Test1-2020-05-08T13:53:51.887Z.html'
70
+ }
71
+ }
72
+ axios.post.mockReturnValueOnce(response)
73
+ spyPromisify.mockReturnValueOnce(jest.fn())
74
+ const config = {
75
+ reportFormat: 'html',
76
+ reportAutoFilenameEnable: true
77
+ }
78
+ objectStore.set('config', config)
79
+ await expect(report.outbound(data)).resolves.not.toBeNull
80
+ })
81
+ it('when the report format is html and reportFilename not present should not throw an error', async () => {
82
+ const response = {
83
+ 'headers': {
84
+ 'content-disposition': 'attachment; filename=TTK-Assertion-Report-Test1-2020-05-08T13:53:51.887Z.html'
85
+ }
86
+ }
87
+ axios.post.mockReturnValueOnce(response)
88
+ spyPromisify.mockReturnValueOnce(jest.fn())
89
+ const config = {
90
+ reportFormat: 'html'
91
+ }
92
+ objectStore.set('config', config)
93
+ await expect(report.outbound(data)).resolves.not.toBeNull
94
+ })
95
+ it('when the report format is html and content-disposition not present should not throw an error', async () => {
96
+ const response = {
97
+ 'headers': {}
98
+ }
99
+ axios.post.mockReturnValueOnce(response)
100
+ spyPromisify.mockReturnValueOnce(jest.fn())
101
+ const config = {
102
+ reportFormat: 'printhtml'
103
+ }
104
+ objectStore.set('config', config)
105
+ await expect(report.outbound(data)).resolves.not.toBeNull
106
+ })
107
+ it('when the report format is html and wrong data not present should not throw an error', async () => {
108
+ const response = {
109
+ 'headers': {
110
+ 'content-disposition': 'attachment; filname=TTK-Assertion-Report-Test1-2020-05-08T13:53:51.887Z.html'
111
+ }
112
+ }
113
+ axios.post.mockReturnValueOnce(response)
114
+ spyPromisify.mockReturnValueOnce(jest.fn())
115
+ const config = {
116
+ reportFormat: 'printhtml'
117
+ }
118
+ objectStore.set('config', config)
119
+ await expect(report.outbound(data)).resolves.not.toBeNull
120
+ })
121
+ it('when the report format is printhtml and reportFilename not present should not throw an error', async () => {
122
+ const response = {
123
+ 'headers': {
124
+ 'content-disposition': 'attachment; filename=TTK-Assertion-Report-Test1-2020-05-08T13:53:51.887Z.html'
125
+ }
126
+ }
127
+ axios.post.mockReturnValueOnce(response)
128
+ spyPromisify.mockReturnValueOnce(jest.fn())
129
+ const config = {
130
+ reportFormat: 'printhtml'
131
+ }
132
+ objectStore.set('config', config)
133
+ await expect(report.outbound(data)).resolves.not.toBeNull
134
+ })
135
+ it('when the report format is printhtml and reportFilename not present should not throw an error', async () => {
136
+ const response = {
137
+ 'headers': {
138
+ 'content-disposition': 'attachment; filename=TTK-Assertion-Report-Test1-2020-05-08T13:53:51.887Z.html'
139
+ }
140
+ }
141
+ axios.post.mockReturnValueOnce(response)
142
+ spyPromisify.mockReturnValueOnce(jest.fn())
143
+ const config = {
144
+ reportFormat: 'printhtml'
145
+ }
146
+ objectStore.set('config', config)
147
+ await expect(report.outbound(data)).resolves.not.toBeNull
148
+ })
149
+
150
+
151
+ it('when the report format is printhtml and extraSummaryInformation is supplied', async () => {
152
+ const response = {
153
+ 'headers': {
154
+ 'content-disposition': 'attachment; filename=TTK-Assertion-Report-Test1-2020-05-08T13:53:51.887Z.html'
155
+ }
156
+ }
157
+ axios.post.mockReturnValueOnce(response)
158
+ spyPromisify.mockReturnValueOnce(jest.fn())
159
+ const config = {
160
+ reportFormat: 'printhtml',
161
+ extraSummaryInformation: 'Title:Mocktitle,Summary:MockSummary'
162
+ }
163
+ objectStore.set('config', config)
164
+ await expect(report.outbound(data)).resolves.not.toBeNull
165
+ })
166
+
167
+
168
+ it('when the report format is not supported should not throw an error', async () => {
169
+ const config = {
170
+ reportFormat: 'default'
171
+ }
172
+ objectStore.set('config', config)
173
+ await expect(report.outbound(data)).resolves.not.toBeNull
174
+ })
175
+ it('when the reportTarget is file should not throw an error', async () => {
176
+ const response = {
177
+ 'headers': {
178
+ 'content-disposition': 'attachment; filename=TTK-Assertion-Report-Test1-2020-05-08T13:53:51.887Z.html'
179
+ }
180
+ }
181
+ axios.post.mockReturnValueOnce(response)
182
+ SpyWriteFileAsync.mockResolvedValueOnce()
183
+ spyPromisify.mockReturnValueOnce(jest.fn())
184
+ const config = {
185
+ reportFormat: 'html',
186
+ reportTarget: 'file://asdf'
187
+ }
188
+ objectStore.set('config', config)
189
+ await expect(report.outbound(data)).resolves.not.toBeNull
190
+ })
191
+ it('when the reportTarget is of type file with path adn auto filename enabled should not throw an error', async () => {
192
+ const response = {
193
+ 'headers': {
194
+ 'content-disposition': 'attachment; filename=TTK-Assertion-Report-Test1-2020-05-08T13:53:51.887Z.html'
195
+ }
196
+ }
197
+ axios.post.mockReturnValueOnce(response)
198
+ SpyWriteFileAsync.mockResolvedValueOnce()
199
+ spyPromisify.mockReturnValueOnce(jest.fn())
200
+ const config = {
201
+ reportFormat: 'html',
202
+ reportAutoFilenameEnable: true,
203
+ reportTarget: 'file://asdf/dasfe.html'
204
+ }
205
+ objectStore.set('config', config)
206
+ await expect(report.outbound(data)).resolves.not.toBeNull
207
+ })
208
+ it('when the reportTarget is of type file with filename and auto filename enabled should not throw an error', async () => {
209
+ const response = {
210
+ 'headers': {
211
+ 'content-disposition': 'attachment; filename=TTK-Assertion-Report-Test1-2020-05-08T13:53:51.887Z.html'
212
+ }
213
+ }
214
+ axios.post.mockReturnValueOnce(response)
215
+ SpyWriteFileAsync.mockResolvedValueOnce()
216
+ spyPromisify.mockReturnValueOnce(jest.fn())
217
+ const config = {
218
+ reportFormat: 'html',
219
+ reportAutoFilenameEnable: true,
220
+ reportTarget: 'file://dasfe.html'
221
+ }
222
+ objectStore.set('config', config)
223
+ await expect(report.outbound(data)).resolves.not.toBeNull
224
+ })
225
+ it('when the reportTarget is s3 should not throw an error', async () => {
226
+ const response = {
227
+ 'headers': {
228
+ 'content-disposition': 'attachment; filename=TTK-Assertion-Report-Test1-2020-05-08T13:53:51.887Z.html'
229
+ }
230
+ }
231
+ axios.post.mockReturnValueOnce(response)
232
+ s3Upload.uploadFileDataToS3.mockReturnValueOnce('http://some_upload_url')
233
+ spyPromisify.mockReturnValueOnce(jest.fn())
234
+ const config = {
235
+ reportFormat: 'html',
236
+ reportTarget: 's3://asdf'
237
+ }
238
+ objectStore.set('config', config)
239
+ await expect(report.outbound(data)).resolves.toHaveProperty('uploadedReportURL')
240
+
241
+ })
242
+ it('when the reportTarget is unknown should return undefined', async () => {
243
+ const response = {
244
+ 'headers': {
245
+ 'content-disposition': 'attachment; filename=TTK-Assertion-Report-Test1-2020-05-08T13:53:51.887Z.html'
246
+ }
247
+ }
248
+ axios.post.mockReturnValueOnce(response)
249
+ spyPromisify.mockReturnValueOnce(jest.fn())
250
+ const config = {
251
+ reportFormat: 'html',
252
+ reportTarget: 'asdf://asdf'
253
+ }
254
+ objectStore.set('config', config)
255
+ await expect(report.outbound(data)).resolves.toBe(undefined)
256
+ })
257
+ })
258
+ })
@@ -0,0 +1,110 @@
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
+
20
+ * ModusBox
21
+ * Georgi Logodazhki <georgi.logodazhki@modusbox.com> (Original Author)
22
+ --------------
23
+ ******/
24
+ 'use strict'
25
+
26
+ const spyExit = jest.spyOn(process, 'exit')
27
+ const { cli } = require('../../src/router')
28
+
29
+ jest.mock('../../src/utils/listeners')
30
+ jest.mock('../../src/modes/outbound')
31
+ jest.mock('../../src/modes/testcaseDefinitionReport')
32
+
33
+ describe('Cli client', () => {
34
+ describe('running router', () => {
35
+ it('when mode is monitoring should not throw an error', async () => {
36
+ const config = {
37
+ "mode": "monitoring"
38
+ }
39
+ spyExit.mockImplementationOnce(jest.fn())
40
+ expect(() => {
41
+ cli(config)
42
+ }).not.toThrowError();
43
+ })
44
+ it('when mode is outbound and inputFiles is provided should not throw an error', async () => {
45
+ const config = {
46
+ "mode": "outbound",
47
+ "inputFiles": "test"
48
+ }
49
+ spyExit.mockImplementationOnce(jest.fn())
50
+ expect(() => {
51
+ cli(config)
52
+ }).not.toThrowError();
53
+ })
54
+ it('when mode is outbound, inputFiles and environmentFile is provided should not throw an error', async () => {
55
+ const config = {
56
+ "mode": "outbound",
57
+ "inputFiles": "test",
58
+ "environmentFile": "test"
59
+ }
60
+ spyExit.mockImplementationOnce(jest.fn())
61
+ expect(() => {
62
+ cli(config)
63
+ }).not.toThrowError();
64
+ })
65
+ it('when mode is outbound and inputFile was not provided should not throw an error', async () => {
66
+ const config = {
67
+ "mode": "outbound"
68
+ }
69
+ spyExit.mockImplementationOnce(jest.fn())
70
+ expect(() => {
71
+ cli(config)
72
+ }).not.toThrowError();
73
+ })
74
+ it('when mode is testcaseDefinitionReport and inputFile was provided should not throw an error', async () => {
75
+ const config = {
76
+ "mode": "testcaseDefinitionReport",
77
+ "inputFiles": "test"
78
+ }
79
+ spyExit.mockImplementationOnce(jest.fn())
80
+ expect(() => {
81
+ cli(config)
82
+ }).not.toThrowError();
83
+ })
84
+ it('when mode is testcaseDefinitionReport and inputFile was not provided should throw an error', async () => {
85
+ const config = {
86
+ "mode": "testcaseDefinitionReport"
87
+ }
88
+ spyExit.mockImplementationOnce(jest.fn())
89
+ expect(() => {
90
+ cli(config)
91
+ }).not.toThrowError();
92
+ })
93
+ it('when mode is not supported should not throw an error', async () => {
94
+ const config = {
95
+ "mode": "unsupported"
96
+ }
97
+ spyExit.mockImplementationOnce(jest.fn())
98
+ expect(() => {
99
+ cli(config)
100
+ }).not.toThrowError();
101
+ })
102
+ it('when mode is not provided should not throw an error', async () => {
103
+ const config = {}
104
+ spyExit.mockImplementationOnce(jest.fn())
105
+ expect(() => {
106
+ cli(config)
107
+ }).not.toThrowError();
108
+ })
109
+ })
110
+ })
@@ -0,0 +1,119 @@
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
+
20
+ * ModusBox
21
+ * Georgi Logodazhki <georgi.logodazhki@modusbox.com> (Original Author)
22
+ --------------
23
+ ******/
24
+ 'use strict'
25
+
26
+ const SharedLib = require('@mojaloop/ml-testing-toolkit-shared-lib')
27
+ const Utils = require('../../src/utils/file-utils')
28
+
29
+ jest.mock('@mojaloop/ml-testing-toolkit-shared-lib')
30
+ jest.mock('../../src/utils/file-utils')
31
+
32
+ const TemplateGenerator = require('../../src/utils/templateGenerator')
33
+
34
+ describe('Cli client', () => {
35
+ describe('run template generator', () => {
36
+ it('when passing a file, template should be generated', async () => {
37
+ const fileList = ['test.json']
38
+
39
+ Utils.fileStatAsync.mockResolvedValueOnce({
40
+ isFile: () => true
41
+ })
42
+ Utils.readFileAsync.mockResolvedValueOnce(JSON.stringify({}))
43
+ SharedLib.FolderParser.getFolderData.mockReturnValueOnce({})
44
+ SharedLib.FolderParser.getTestCases.mockReturnValueOnce([])
45
+
46
+ await expect(TemplateGenerator.generateTemplate(fileList)).resolves.toBeDefined()
47
+ })
48
+ it('when passing a folder without master file and no selected labels, template should be generated', async () => {
49
+ const fileList = ['test-folder']
50
+
51
+ // fileList['test-folder']
52
+ Utils.fileStatAsync.mockResolvedValueOnce({
53
+ isFile: () => false,
54
+ isDirectory: () => true
55
+ })
56
+ Utils.readRecursiveAsync.mockResolvedValueOnce(["test.json"])
57
+
58
+ // fileList['test-folder']['test.json']
59
+ Utils.readFileAsync.mockResolvedValueOnce(JSON.stringify({}))
60
+ SharedLib.FolderParser.getFolderData.mockReturnValueOnce({})
61
+ SharedLib.FolderParser.getTestCases.mockReturnValueOnce([])
62
+
63
+ await expect(TemplateGenerator.generateTemplate(fileList)).resolves.toBeDefined()
64
+ })
65
+ it('when passing a folder with master file and selected labels, template should be generated', async () => {
66
+ const fileList = ['test-labels']
67
+ const selectedLabels = ["test"]
68
+
69
+ // fileList['test-labels']
70
+ Utils.fileStatAsync.mockResolvedValueOnce({
71
+ isFile: () => false,
72
+ isDirectory: () => true
73
+ })
74
+ Utils.readRecursiveAsync.mockResolvedValueOnce(["test.json", "test2.json", "master.json"])
75
+
76
+ // fileList['test-labels']['test.json']
77
+ Utils.readFileAsync.mockResolvedValueOnce(JSON.stringify({}))
78
+ SharedLib.FolderParser.getFolderData.mockReturnValueOnce({})
79
+ SharedLib.FolderParser.getTestCases.mockReturnValueOnce([])
80
+
81
+ // fileList['test-labels']['test2.json']
82
+ Utils.readFileAsync.mockResolvedValueOnce(JSON.stringify({}))
83
+ SharedLib.FolderParser.getFolderData.mockReturnValueOnce({})
84
+ SharedLib.FolderParser.getTestCases.mockReturnValueOnce()
85
+
86
+ // fileList['test-labels']['master.json']
87
+ Utils.readFileAsync.mockResolvedValueOnce(JSON.stringify({
88
+ order: [
89
+ {
90
+ name: "test.json",
91
+ type: "file",
92
+ labels: ["test"]
93
+ },
94
+ {
95
+ name: "test2.json",
96
+ type: "file"
97
+ }
98
+ ]
99
+ }))
100
+
101
+ await expect(TemplateGenerator.generateTemplate(fileList, selectedLabels)).resolves.toBeDefined()
102
+ })
103
+ it('when a file can not be read, template should not be generated', async () => {
104
+ Utils.fileStatAsync
105
+ .mockResolvedValueOnce({
106
+ isFile: () => true
107
+ })
108
+ Utils.readFileAsync
109
+ .mockRejectedValueOnce({})
110
+ SharedLib.FolderParser.sequenceTestCases
111
+ .mockImplementationOnce(() => {
112
+ throw new Error("expected error")
113
+ })
114
+
115
+ const fileList = ["test.json"]
116
+ await expect(TemplateGenerator.generateTemplate(fileList)).resolves.toBeDefined()
117
+ })
118
+ })
119
+ })
@@ -0,0 +1,72 @@
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
+
20
+ * ModusBox
21
+ * Georgi Logodazhki <georgi.logodazhki@modusbox.com> (Original Author)
22
+ --------------
23
+ ******/
24
+ 'use strict'
25
+
26
+ const spyReport = jest.spyOn(require('../../src/utils/report'), 'testcaseDefinition')
27
+ const spyExit = jest.spyOn(process, 'exit')
28
+ const spyReadFileAsync = jest.spyOn(require('../../src/utils/file-utils'), 'readFileAsync')
29
+ const objectStore = require('../../src/objectStore')
30
+
31
+ const testcaseDefinitionReport = require('../../src/modes/testcaseDefinitionReport')
32
+ const spyGenerateTemplate = jest.spyOn(require('../../src/utils/templateGenerator'), 'generateTemplate')
33
+
34
+ describe('Cli client', () => {
35
+
36
+ describe('run testcaseDefinitionReport', () => {
37
+ it('when download is successful should not throw an error', async () => {
38
+ const config = {
39
+ inputFiles: "sample-cli.json",
40
+ labels: "p2p"
41
+ }
42
+ spyGenerateTemplate.mockResolvedValueOnce({
43
+ "test_cases": [
44
+ {
45
+ "requests": []
46
+ }
47
+ ]
48
+ })
49
+ objectStore.set('config', config)
50
+
51
+ spyReport.mockResolvedValueOnce({})
52
+ spyExit.mockReturnValueOnce({})
53
+ await expect(testcaseDefinitionReport.download()).resolves.toBe(undefined)
54
+ })
55
+ it('when download is not successful should throw an error', async () => {
56
+ spyReadFileAsync.mockResolvedValueOnce(JSON.stringify({
57
+ "inputValues": {}
58
+ }))
59
+ const config = {
60
+ inputFiles: "sample-cli.json",
61
+ environmentFile: "sample-environement.json"
62
+ }
63
+ spyGenerateTemplate.mockResolvedValueOnce({})
64
+
65
+ objectStore.set('config', config)
66
+
67
+ spyReport.mockRejectedValueOnce({})
68
+ spyExit.mockReturnValueOnce({})
69
+ await expect(testcaseDefinitionReport.download()).resolves.toBe(undefined)
70
+ })
71
+ })
72
+ })
@@ -0,0 +1,38 @@
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
+
20
+ * ModusBox
21
+ * Vijaya Kumar Guthi <vijaya.guthi@modusbox.com> (Original Author)
22
+ --------------
23
+ ******/
24
+
25
+ const RC = require('parse-strings-in-object')(require('rc')('TOOLKIT', require('../../config/default.json')))
26
+ const defaultConfig = require('../src/lib/config')
27
+
28
+ /**
29
+ * testConfig extends ./src/lib/config.js with test-specific
30
+ * environment variable config
31
+ */
32
+
33
+ module.exports = {
34
+ /* Test Config */
35
+ TEST_TOOLKIT_HOST: RC.TEST_TOOLKIT_HOST,
36
+
37
+ ...defaultConfig
38
+ }