@mojaloop/ml-testing-toolkit-client-lib 1.7.0 → 1.8.0-snapshot.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mojaloop/ml-testing-toolkit-client-lib",
3
3
  "description": "Testing Toolkit Client Library",
4
- "version": "1.7.0",
4
+ "version": "1.8.0-snapshot.1",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Vijaya Kumar Guthi, ModusBox Inc. ",
7
7
  "contributors": [
package/src/client.js CHANGED
@@ -47,6 +47,7 @@ program
47
47
  .option('--report-auto-filename-enable <reportAutoFilenameEnable>', 'default: false, if true the file name will be generated by the backend')
48
48
  .option('--report-target <reportTarget>', 'default: "file://<file_name_genrated_by_backend>" --- supported targets: "file://path_to_file", "s3://<bucket_name>[/<file_path>]"')
49
49
  .option('--slack-webhook-url <slackWebhookUrl>', 'default: "Disabled" --- supported formats: "https://....."')
50
+ .option('--slack-webhook-url-for-failed <slackWebhookUrl>', 'default: "Disabled" --- supported formats: "https://....."')
50
51
  .option('--extra-summary-information <Comma separated values in the format key:value>', 'default: none --- example: "Testcase Name:something,Environment:Dev1"')
51
52
  .option('--brief-summary-prefix <Prefix to use for a brief summary in Slack>', 'default: none --- example: "environment name, test name"')
52
53
  .on('--help', () => { // Extra information on help message
@@ -171,10 +171,13 @@ const generateSlackBlocks = (progress, reportURL) => {
171
171
  }
172
172
 
173
173
  const sendSlackNotification = async (progress, reportURL = 'http://localhost/') => {
174
+ console.log('runtimeInformation: ', progress.runtimeInformation)
175
+
176
+ let blocks
174
177
  if (config.slackWebhookUrl) {
175
178
  const url = config.slackWebhookUrl
176
179
  const webhook = new IncomingWebhook(url)
177
- const blocks = generateSlackBlocks(progress, reportURL)
180
+ blocks = generateSlackBlocks(progress, reportURL)
178
181
 
179
182
  try {
180
183
  // console.log(JSON.stringify(slackBlocks, null, 2))
@@ -187,8 +190,33 @@ const sendSlackNotification = async (progress, reportURL = 'http://localhost/')
187
190
  console.log('ERROR: Sending slack notification failed. ', err.message)
188
191
  }
189
192
  }
193
+
194
+ if (needToNotifyFailed(config, progress)) {
195
+ const url = config.slackWebhookUrlForFailed
196
+ const webhook = new IncomingWebhook(url)
197
+
198
+ if (!blocks) blocks = generateSlackBlocks(progress, reportURL)
199
+
200
+ try {
201
+ // console.log(JSON.stringify(slackBlocks, null, 2))
202
+ await webhook.send({
203
+ text: 'Failed Tests Report',
204
+ blocks
205
+ })
206
+ console.log('Slack notification sent.')
207
+ } catch (err) {
208
+ console.log('ERROR: Sending slack notification failed. ', err.message)
209
+ }
210
+ }
211
+ }
212
+
213
+ const needToNotifyFailed = (conf, totalResult) => {
214
+ return conf.slackWebhookUrlForFailed && (!totalResult?.runtimeInformation?.totalAssertions
215
+ ? true
216
+ : totalResult.runtimeInformation.totalPassedAssertions !== totalResult.runtimeInformation.totalAssertions)
190
217
  }
191
218
 
192
219
  module.exports = {
193
- sendSlackNotification
220
+ sendSlackNotification,
221
+ needToNotifyFailed
194
222
  }
package/src/router.js CHANGED
@@ -63,6 +63,7 @@ const cli = (commanderOptions) => {
63
63
  reportAutoFilenameEnable: commanderOptions.reportAutoFilenameEnable === 'true' || configFile.reportAutoFilenameEnable === true,
64
64
  reportTarget: commanderOptions.reportTarget || configFile.reportTarget,
65
65
  slackWebhookUrl: commanderOptions.slackWebhookUrl || configFile.slackWebhookUrl,
66
+ slackWebhookUrlForFailed: commanderOptions.slackWebhookUrlForFailed || configFile.slackWebhookUrlForFailed,
66
67
  slackPassedImage: configFile.slackPassedImage,
67
68
  slackFailedImage: configFile.slackFailedImage,
68
69
  baseURL: commanderOptions.baseUrl || configFile.baseURL,
@@ -134,4 +134,60 @@ describe('Cli client', () => {
134
134
  }))
135
135
  })
136
136
  })
137
+
138
+ describe.skip('needToNotify Tests -->', () => {
139
+ it('should not notify if slackWebhookUrl is not set', () => {
140
+ expect(slackBroadCast.needToNotify({})).toBeFalsy()
141
+ })
142
+
143
+ it('should notify if slackWebhookUrl is set and slackOnlyFailed not', () => {
144
+ const conf = { slackWebhookUrl: 'url' }
145
+ expect(slackBroadCast.needToNotify(conf)).toBe(true)
146
+ })
147
+
148
+ it('should notify if slackWebhookUrl is set and slackOnlyFailed is false', () => {
149
+ const conf = {
150
+ slackWebhookUrl: 'url',
151
+ slackOnlyFailed: false
152
+ }
153
+ expect(slackBroadCast.needToNotify(conf)).toBe(true)
154
+ })
155
+
156
+ it('should notify if slackOnlyFailed=true, and tests failed', () => {
157
+ const conf = {
158
+ slackWebhookUrl: 'url',
159
+ slackOnlyFailed: true
160
+ }
161
+ const totalResult = {
162
+ runtimeInformation: {
163
+ totalPassedAssertions: 0,
164
+ totalAssertion: 1
165
+ }
166
+ }
167
+ expect(slackBroadCast.needToNotify(conf, totalResult)).toBe(true)
168
+ })
169
+
170
+ it('should notify if slackOnlyFailed=true, and tests passed', () => {
171
+ const conf = {
172
+ slackWebhookUrl: 'url',
173
+ slackOnlyFailed: true
174
+ }
175
+ const totalResult = {
176
+ runtimeInformation: {
177
+ totalPassedAssertions: 1,
178
+ totalAssertion: 1
179
+ }
180
+ }
181
+ expect(slackBroadCast.needToNotify(conf, totalResult)).toBe(false)
182
+ })
183
+
184
+ it('should notify if slackOnlyFailed=true, but no totalResult.runtimeInformation', () => {
185
+ const conf = {
186
+ slackWebhookUrl: 'url',
187
+ slackOnlyFailed: true
188
+ }
189
+ const totalResult = {}
190
+ expect(slackBroadCast.needToNotify(conf, totalResult)).toBe(true)
191
+ })
192
+ })
137
193
  })
@@ -30,17 +30,19 @@
30
30
 
31
31
  const spyExit = jest.spyOn(process, 'exit')
32
32
  const { cli } = require('../../src/router')
33
+ // const objectStore = require('../../src/objectStore')
33
34
 
34
35
  jest.mock('../../src/utils/listeners')
35
36
  jest.mock('../../src/modes/outbound')
36
37
  jest.mock('../../src/modes/testcaseDefinitionReport')
38
+ // jest.mock('../../src/objectStore')
37
39
 
38
40
  describe('Cli client', () => {
39
41
  describe('running router', () => {
40
42
  it('when mode is monitoring should not throw an error', async () => {
41
43
  const config = {
42
44
  "mode": "monitoring"
43
- }
45
+ }
44
46
  spyExit.mockImplementationOnce(jest.fn())
45
47
  expect(() => {
46
48
  cli(config)
@@ -111,5 +113,14 @@ describe('Cli client', () => {
111
113
  cli(config)
112
114
  }).not.toThrowError();
113
115
  })
116
+ // it('should have default slackOnlyFailed value', async () => {
117
+ // spyExit.mockImplementationOnce(jest.fn())
118
+ // cli({
119
+ // mode: 'outbound',
120
+ // inputFiles: 'test',
121
+ // environmentFile: 'test'
122
+ // })
123
+ // expect(objectStore.set.mock.lastCall[1].slackOnlyFailed).toBe(false)
124
+ // })
114
125
  })
115
126
  })