@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,502 @@
1
+ # CircleCI v2 Config
2
+ version: 2.1
3
+
4
+ ##
5
+ # orbs
6
+ #
7
+ # Orbs used in this pipeline
8
+ ##
9
+ orbs:
10
+ slack: circleci/slack@4.9.3 # Ref: https://github.com/mojaloop/ci-config/tree/master/slack-templates
11
+ pr-tools: mojaloop/pr-tools@0.1.10 # Ref: https://github.com/mojaloop/ci-config/
12
+ gh: circleci/github-cli@2.1.0
13
+
14
+ ##
15
+ # defaults
16
+ #
17
+ # YAML defaults templates, in alphabetical order
18
+ ##
19
+ defaults_Dependencies: &defaults_Dependencies |
20
+ apk --no-cache add git
21
+ apk --no-cache add ca-certificates
22
+ apk --no-cache add curl
23
+ apk --no-cache add openssh-client
24
+ apk add --no-cache -t build-dependencies make gcc g++ python3 libtool autoconf automake jq
25
+ npm config set unsafe-perm true
26
+ npm install -g node-gyp
27
+
28
+ defaults_awsCliDependencies: &defaults_awsCliDependencies |
29
+ apk --no-cache add aws-cli
30
+
31
+ defaults_license_scanner: &defaults_license_scanner
32
+ name: Install and set up license-scanner
33
+ command: |
34
+ git clone https://github.com/mojaloop/license-scanner /tmp/license-scanner
35
+ cd /tmp/license-scanner && make build default-files set-up
36
+
37
+ defaults_npm_auth: &defaults_npm_auth
38
+ name: Update NPM registry auth token
39
+ command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
40
+
41
+
42
+ defaults_npm_publish_release: &defaults_npm_publish_release
43
+ name: Publish NPM $RELEASE_TAG artifact
44
+ command: |
45
+ source $BASH_ENV
46
+ echo "Publishing tag $RELEASE_TAG"
47
+ npm publish --tag $RELEASE_TAG --access public
48
+
49
+ defaults_export_version_from_package: &defaults_export_version_from_package
50
+ name: Format the changelog into the github release body and get release tag
51
+ command: |
52
+ git diff --no-indent-heuristic master~1 HEAD CHANGELOG.md | sed -n '/^+[^+]/ s/^+//p' > /tmp/changes
53
+ echo 'export RELEASE_CHANGES=`cat /tmp/changes`' >> $BASH_ENV
54
+ echo 'export RELEASE_TAG=`cat package-lock.json | jq -r .version`' >> $BASH_ENV
55
+
56
+ defaults_configure_git: &defaults_configure_git
57
+ name: Configure git
58
+ command: |
59
+ git config user.email ${GIT_CI_EMAIL}
60
+ git config user.name ${GIT_CI_USER}
61
+
62
+ ##
63
+ # Executors
64
+ #
65
+ # CircleCI Executors
66
+ ##
67
+ executors:
68
+ default-docker:
69
+ working_directory: &WORKING_DIR /home/circleci/project
70
+ docker:
71
+ - image: node:16.15.0-alpine
72
+
73
+ default-machine:
74
+ working_directory: *WORKING_DIR
75
+ machine:
76
+ image: ubuntu-2004:current
77
+
78
+ jobs:
79
+ setup:
80
+ executor: default-docker
81
+ steps:
82
+ - run:
83
+ name: Install general dependencies
84
+ command: *defaults_Dependencies
85
+ - checkout
86
+ - run:
87
+ name: Update NPM install
88
+ command: npm ci
89
+ - save_cache:
90
+ key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
91
+ paths:
92
+ - node_modules
93
+
94
+ test-unit:
95
+ executor: default-docker
96
+ steps:
97
+ - run:
98
+ name: Install general dependencies
99
+ command: *defaults_Dependencies
100
+ - checkout
101
+ - restore_cache:
102
+ key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
103
+ - run:
104
+ name: Create dir for test results
105
+ command: mkdir -p ./test/results
106
+ - run:
107
+ name: Execute unit tests
108
+ command: |
109
+ export NODE_OPTIONS=--max_old_space_size=4096
110
+ npm run test:unit --silent -- --json --maxWorkers=2 --outputFile ./test/results/unit.json
111
+ - store_artifacts:
112
+ path: ./test/results
113
+ prefix: test
114
+ - store_test_results:
115
+ path: ./test/results
116
+
117
+ test-dependencies:
118
+ executor: default-docker
119
+ steps:
120
+ - run:
121
+ name: Install general dependencies
122
+ command: *defaults_Dependencies
123
+ - checkout
124
+ - restore_cache:
125
+ key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
126
+ - run:
127
+ name: Execute dependency tests
128
+ command: npm run dep:check
129
+
130
+ test-lint:
131
+ executor: default-docker
132
+ steps:
133
+ - run:
134
+ name: Install general dependencies
135
+ command: *defaults_Dependencies
136
+ - checkout
137
+ - restore_cache:
138
+ key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
139
+ - run:
140
+ name: Execute lint tests
141
+ command: npm run lint
142
+
143
+ test-coverage:
144
+ executor: default-docker
145
+ steps:
146
+ - run:
147
+ name: Install general dependencies
148
+ command: *defaults_Dependencies
149
+ - run:
150
+ name: Install AWS CLI dependencies
151
+ command: *defaults_awsCliDependencies
152
+ - checkout
153
+ - restore_cache:
154
+ key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
155
+ - run:
156
+ name: Execute code coverage check
157
+ command: |
158
+ export NODE_OPTIONS=--max_old_space_size=4096
159
+ npm -s run test:coverage-check -- --maxWorkers=2
160
+ - store_artifacts:
161
+ path: coverage
162
+ prefix: test
163
+ - store_test_results:
164
+ path: coverage
165
+ - run:
166
+ name: Copy code coverage to SonarQube
167
+ command: |
168
+ if [ "${CIRCLE_BRANCH}" == "master" ];
169
+ then
170
+ echo "Sending lcov.info to SonarQube..."
171
+ aws s3 cp coverage/lcov.info $AWS_S3_DIR_SONARQUBE/${CIRCLE_PROJECT_REPONAME}/lcov.info
172
+ else
173
+ echo "Not a release (env CIRCLE_BRANCH != 'master'), skipping sending lcov.info to SonarQube."
174
+ fi
175
+
176
+ vulnerability-check:
177
+ executor: default-docker
178
+ steps:
179
+ - run:
180
+ name: Install general dependencies
181
+ command: *defaults_Dependencies
182
+ - checkout
183
+ - restore_cache:
184
+ key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
185
+ - run:
186
+ name: Create dir for test results
187
+ command: mkdir -p ./audit/results
188
+ - run:
189
+ name: Check for new npm vulnerabilities
190
+ command: npm run audit:check --silent -- --json > ./audit/results/auditResults.json
191
+ - store_artifacts:
192
+ path: ./audit/results
193
+ prefix: audit
194
+
195
+ audit-licenses:
196
+ executor: default-docker
197
+ steps:
198
+ - run:
199
+ name: Install general dependencies
200
+ command: *defaults_Dependencies
201
+ - run:
202
+ <<: *defaults_license_scanner
203
+ - checkout
204
+ - restore_cache:
205
+ key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
206
+ - run:
207
+ name: Prune non-production packages before running license-scanner
208
+ command: npm prune --production
209
+ - run:
210
+ name: Run the license-scanner
211
+ command: cd /tmp/license-scanner && pathToRepo=$CIRCLE_WORKING_DIRECTORY make run
212
+ - store_artifacts:
213
+ path: /tmp/license-scanner/results
214
+ prefix: licenses
215
+
216
+ release:
217
+ executor: default-docker
218
+ steps:
219
+ - run:
220
+ name: Install general dependencies
221
+ command: *defaults_Dependencies
222
+ - checkout
223
+ - restore_cache:
224
+ keys:
225
+ - dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
226
+ - run:
227
+ <<: *defaults_configure_git
228
+ - run:
229
+ name: Setup Slack config
230
+ command: |
231
+ echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
232
+ echo "export SLACK_RELEASE_TYPE='GitHub Release'" >> $BASH_ENV
233
+ echo "export SLACK_RELEASE_TAG='${RELEASE_TAG} on ${CIRCLE_BRANCH} branch'" >> $BASH_ENV
234
+ echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
235
+ echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
236
+ - run:
237
+ name: Generate changelog and bump package version
238
+ command: npm run release -- --no-verify
239
+ - run:
240
+ name: Push the release
241
+ command: git push --follow-tags origin ${CIRCLE_BRANCH}
242
+ - slack/notify:
243
+ event: fail
244
+ template: SLACK_TEMP_RELEASE_FAILURE
245
+
246
+ github-release:
247
+ executor: default-machine
248
+ steps:
249
+ - run:
250
+ name: Install git
251
+ command: |
252
+ sudo apt-get update && sudo apt-get install -y git
253
+ - gh/install
254
+ - checkout
255
+ - run:
256
+ <<: *defaults_configure_git
257
+ - run:
258
+ name: Fetch updated release branch
259
+ command: |
260
+ git fetch origin
261
+ git checkout origin/${CIRCLE_BRANCH}
262
+ - run:
263
+ <<: *defaults_export_version_from_package
264
+ - run:
265
+ name: Check the release changes
266
+ command: |
267
+ echo "Changes are: ${RELEASE_CHANGES}"
268
+ - run:
269
+ name: Setup Slack config
270
+ command: |
271
+ echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
272
+ echo "export SLACK_RELEASE_TYPE='Github Release'" >> $BASH_ENV
273
+ echo "export SLACK_RELEASE_TAG=v${RELEASE_TAG}" >> $BASH_ENV
274
+ echo "export SLACK_RELEASE_URL=https://github.com/mojaloop/${CIRCLE_PROJECT_REPONAME}/releases/tag/v${RELEASE_TAG}" >> $BASH_ENV
275
+ echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
276
+ echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
277
+ - run:
278
+ name: Create Release
279
+ command: |
280
+ gh release create "v${RELEASE_TAG}" --title "v${RELEASE_TAG} Release" --draft=false --notes "${RELEASE_CHANGES}" ./CHANGELOG.md
281
+ - slack/notify:
282
+ event: pass
283
+ template: SLACK_TEMP_RELEASE_SUCCESS
284
+ - slack/notify:
285
+ event: fail
286
+ template: SLACK_TEMP_RELEASE_FAILURE
287
+
288
+ publish:
289
+ executor: default-docker
290
+ steps:
291
+ - run:
292
+ name: Install general dependencies
293
+ command: *defaults_Dependencies
294
+ - checkout
295
+ - restore_cache:
296
+ key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
297
+ - run:
298
+ name: Setup for LATEST release
299
+ command: |
300
+ echo "export RELEASE_TAG=$RELEASE_TAG_PROD" >> $BASH_ENV
301
+ echo "RELEASE_TAG=$RELEASE_TAG_PROD"
302
+
303
+ PACKAGE_VERSION=$(cat package-lock.json | jq -r .version)
304
+ echo "export PACKAGE_VERSION=${PACKAGE_VERSION}" >> $BASH_ENV
305
+ echo "PACKAGE_VERSION=${PACKAGE_VERSION}"
306
+ - run:
307
+ name: Setup Slack config
308
+ command: |
309
+ echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
310
+ echo "export SLACK_RELEASE_TYPE='NPM Release'" >> $BASH_ENV
311
+ echo "export SLACK_RELEASE_TAG=v${CIRCLE_TAG:1}" >> $BASH_ENV
312
+ echo "export SLACK_RELEASE_URL=https://www.npmjs.com/package/@mojaloop/${CIRCLE_PROJECT_REPONAME}/v/${CIRCLE_TAG:1}" >> $BASH_ENV
313
+ echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
314
+ echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
315
+ - run:
316
+ <<: *defaults_npm_auth
317
+ - run:
318
+ <<: *defaults_npm_publish_release
319
+ - slack/notify:
320
+ event: pass
321
+ template: SLACK_TEMP_RELEASE_SUCCESS
322
+ - slack/notify:
323
+ event: fail
324
+ template: SLACK_TEMP_RELEASE_FAILURE
325
+
326
+ publish-snapshot:
327
+ executor: default-docker
328
+ steps:
329
+ - run:
330
+ name: Install general dependencies
331
+ command: *defaults_Dependencies
332
+ - checkout
333
+ - restore_cache:
334
+ key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
335
+ - run:
336
+ name: Setup for SNAPSHOT release
337
+ command: |
338
+ echo "export RELEASE_TAG=${RELEASE_TAG_SNAPSHOT}" >> $BASH_ENV
339
+ echo "RELEASE_TAG=${RELEASE_TAG_SNAPSHOT}"
340
+
341
+ echo "Override package version: ${CIRCLE_TAG:1}"
342
+ npx standard-version --skip.tag --skip.commit --skip.changelog --release-as ${CIRCLE_TAG:1}
343
+
344
+ PACKAGE_VERSION=$(cat package-lock.json | jq -r .version)
345
+ echo "export PACKAGE_VERSION=${PACKAGE_VERSION}" >> $BASH_ENV
346
+ echo "PACKAGE_VERSION=${PACKAGE_VERSION}"
347
+ - run:
348
+ name: Setup Slack config
349
+ command: |
350
+ echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
351
+ echo "export SLACK_RELEASE_TYPE='NPM Snapshot'" >> $BASH_ENV
352
+ echo "export SLACK_RELEASE_TAG=v${CIRCLE_TAG:1}" >> $BASH_ENV
353
+ echo "export SLACK_RELEASE_URL=https://www.npmjs.com/package/@mojaloop/${CIRCLE_PROJECT_REPONAME}/v/${CIRCLE_TAG:1}" >> $BASH_ENV
354
+ echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
355
+ echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
356
+ - run:
357
+ <<: *defaults_npm_auth
358
+ - run:
359
+ <<: *defaults_npm_publish_release
360
+ - slack/notify:
361
+ event: pass
362
+ template: SLACK_TEMP_RELEASE_SUCCESS
363
+ - slack/notify:
364
+ event: fail
365
+ template: SLACK_TEMP_RELEASE_FAILURE
366
+
367
+ workflows:
368
+ version: 2
369
+ build_and_test:
370
+ jobs:
371
+ - pr-tools/pr-title-check:
372
+ context: org-global
373
+ - setup:
374
+ context: org-global
375
+ filters:
376
+ tags:
377
+ only: /.*/
378
+ branches:
379
+ ignore:
380
+ - /feature*/
381
+ - /bugfix*/
382
+ # - test-dependencies:
383
+ # context: org-global
384
+ # requires:
385
+ # - setup
386
+ # filters:
387
+ # tags:
388
+ # only: /.*/
389
+ # branches:
390
+ # ignore:
391
+ # - /feature*/
392
+ # - /bugfix*/
393
+ - test-lint:
394
+ context: org-global
395
+ requires:
396
+ - setup
397
+ filters:
398
+ tags:
399
+ only: /.*/
400
+ branches:
401
+ ignore:
402
+ - /feature*/
403
+ - /bugfix*/
404
+ - test-unit:
405
+ context: org-global
406
+ requires:
407
+ - setup
408
+ filters:
409
+ tags:
410
+ only: /.*/
411
+ branches:
412
+ ignore:
413
+ - /feature*/
414
+ - /bugfix*/
415
+ - test-coverage:
416
+ context: org-global
417
+ requires:
418
+ - setup
419
+ filters:
420
+ tags:
421
+ only: /.*/
422
+ branches:
423
+ ignore:
424
+ - /feature*/
425
+ - /bugfix*/
426
+ - vulnerability-check:
427
+ context: org-global
428
+ requires:
429
+ - setup
430
+ filters:
431
+ tags:
432
+ only: /.*/
433
+ branches:
434
+ ignore:
435
+ - /feature*/
436
+ - /bugfix*/
437
+ - audit-licenses:
438
+ context: org-global
439
+ requires:
440
+ - setup
441
+ filters:
442
+ tags:
443
+ only: /.*/
444
+ branches:
445
+ ignore:
446
+ - /feature*/
447
+ - /bugfix*/
448
+ # New commits to master release automatically
449
+ - release:
450
+ context: org-global
451
+ requires:
452
+ - pr-tools/pr-title-check
453
+ # - test-dependencies
454
+ - test-lint
455
+ - test-unit
456
+ - test-coverage
457
+ - vulnerability-check
458
+ - audit-licenses
459
+ filters:
460
+ branches:
461
+ only:
462
+ - master
463
+ - /release\/v.*/
464
+ - github-release:
465
+ context: org-global
466
+ requires:
467
+ - release
468
+ filters:
469
+ branches:
470
+ only:
471
+ - master
472
+ - /release\/v.*/
473
+ - publish:
474
+ context: org-global
475
+ requires:
476
+ - pr-tools/pr-title-check
477
+ - test-lint
478
+ - test-unit
479
+ - test-coverage
480
+ - vulnerability-check
481
+ - audit-licenses
482
+ filters:
483
+ tags:
484
+ only: /v[0-9]+(\.[0-9]+)*/
485
+ branches:
486
+ ignore:
487
+ - /.*/
488
+ - publish-snapshot:
489
+ context: org-global
490
+ requires:
491
+ - pr-tools/pr-title-check
492
+ - test-lint
493
+ - test-unit
494
+ - test-coverage
495
+ - vulnerability-check
496
+ - audit-licenses
497
+ filters:
498
+ tags:
499
+ only: /v[0-9]+(\.[0-9]+)*\-snapshot+((\.[0-9]+)?)/
500
+ branches:
501
+ ignore:
502
+ - /.*/
package/.dockerignore ADDED
@@ -0,0 +1,10 @@
1
+ coverage/
2
+ node_modules/
3
+ .dockerignore
4
+ .eslintignore
5
+ .git/
6
+ .gitignore
7
+ Dockerfile
8
+ LICENSE
9
+ README.md
10
+ .circleci/
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 16.15.0
package/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
+
5
+ ### 0.0.2 (2022-05-31)
package/Dockerfile ADDED
@@ -0,0 +1,25 @@
1
+ FROM node:16.15.0-alpine as builder
2
+ WORKDIR /opt/app
3
+
4
+ RUN apk add --no-cache -t build-dependencies make gcc g++ python3 libtool libressl-dev openssl-dev autoconf automake \
5
+ && cd $(npm root -g)/npm \
6
+ && npm config set unsafe-perm true \
7
+ && npm install -g node-gyp
8
+
9
+ COPY package.json package-lock.json* /opt/app/
10
+
11
+ RUN npm install
12
+
13
+ COPY src /opt/app/src
14
+
15
+ FROM node:16.15.0-alpine
16
+ WORKDIR /opt/app
17
+
18
+ # Create a non-root user: ml-user
19
+ RUN adduser -D ml-user
20
+ USER ml-user
21
+
22
+ COPY --chown=ml-user --from=builder /opt/app .
23
+ RUN npm prune --production
24
+
25
+ CMD ["npm", "run", "cli"]
package/LICENSE.md ADDED
@@ -0,0 +1,10 @@
1
+ # LICENSE
2
+
3
+ Copyright © 2020 Mojaloop Foundation
4
+
5
+ The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0
6
+ (the "License") and you may not use these files except in compliance with the [License](http://www.apache.org/licenses/LICENSE-2.0).
7
+
8
+ You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
9
+
10
+ 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](http://www.apache.org/licenses/LICENSE-2.0).