@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
package/README.md ADDED
@@ -0,0 +1,213 @@
1
+ Mojaloop Testing Toolkit Client Library and Tools
2
+ =================================================
3
+
4
+ The **Mojaloop Testing Toolkit CLI** is a command line client for connecting to "Mojaloop Testing Toolkit" instead of using web interface.
5
+
6
+ For additional back ground information on the Self Testing Toolkit, please see [Mojaloop Testing Toolkit](/documents/Mojaloop-Testing-Toolkit.md). It would be to the particpant's benefit to familiarise themselves with the understanding of the [Architecture Diagram](/documents/MojaloopÂ-Testing-Tool.md#7-architecture) that explains the various components and related flows.
7
+
8
+
9
+ **Table of Contents**
10
+
11
+ 1. [Getting Started](#1-getting-started)
12
+ 2. [The Mojaloop Testing Toolkit CLI](#2-the-mojaloop-testing-toolkit)
13
+
14
+ 2.1. [Help screen](#21-at-first-glance)
15
+
16
+ 2.2. [Monitoring Mode](#22-monitoring-mode)
17
+
18
+ 2.3. [Outbound Mode](#23-outbound-mode)
19
+
20
+ 2.4. [AWS S3 Upload](#24-aws-s3-upload)
21
+
22
+ 2.5. [Slack Notification](#25-slack-notification)
23
+
24
+ ### 1. Getting Started
25
+
26
+ To get started, please follow the instructions in the [README](/README.md) document. This document covers the use-cases with the **Mojaloop Simulator**.
27
+
28
+ ### 2. CLI
29
+
30
+ #### 2.1 Help screen
31
+
32
+ The help screen allows you to see the usage, possible options and default values
33
+
34
+ command:
35
+
36
+ ```
37
+ node src/client -h
38
+ ```
39
+
40
+ output:
41
+
42
+ ```
43
+ Usage: client [options]
44
+
45
+ Options:
46
+ -v, --version output the version number
47
+ -c, --config <config> default configuration: {"mode": "outbound", "reportFormat": "json"}
48
+ -m, --mode <mode> default: "outbound" --- supported modes: "monitoring", "outbound"
49
+ -u, --base-url <baseUrl> default: "http://localhost:5050"
50
+ -i, --input-files <inputFiles> csv list of json files or directories; required when the mode is "outbound" --- supported formats: "json"
51
+ -e, --environment-file <environmentFile> required when the mode is "outbound" --- supported formats: "json"
52
+ --report-format <reportFormat> default: "json" --- supported formats: "json", "html", "printhtml"
53
+ --report-auto-filename-enable <reportAutoFilenameEnable> default: false, if true the file name will be generated by the backend
54
+ --report-target <reportTarget> default: "file://<file_name_genrated_by_backend>" --- supported targets: "file://path_to_file", "s3://<bucket_name>[/<file_path>]"
55
+ --slack-webhook-url <slackWebhookUrl> default: "Disabled" --- supported formats: "https://....."
56
+ -h, --help output usage information
57
+
58
+ *** If the option report-target is set to use AWS S3 service, the variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION) should be passed in environment
59
+ ```
60
+
61
+ #### 2.2 Monitoring Mode
62
+
63
+ The monitoring mode allows you to monitor _incoming_ requests from the **Mojaloop Simulator**.
64
+
65
+ Example:
66
+
67
+ command:
68
+
69
+ ```
70
+ node src/client -m monitoring
71
+ ```
72
+
73
+ output:
74
+
75
+ ```
76
+ Listening on newLog events...
77
+ 2020-05-12T12:23:32.988Z INFO (15892862129885sy33i) Request: post /bulkTransfers
78
+ {
79
+ "request": {
80
+ "uniqueId": "15892862129885sy33i",
81
+ "headers": {
82
+ "content-type": "application/vnd.interoperability.parties+json;version=1.0",
83
+ "accept": "application/vnd.interoperability.parties+json;version=1.0",
84
+ "fspiop-source": "testingtoolkitdfsp",
85
+ "date": "Tue, 12 May 2020 12:23:32 GMT",
86
+ "user-agent": "axios/0.19.2",
87
+ "content-length": "256",
88
+ "host": "localhost:5000",
89
+ "connection": "close"
90
+ },
91
+ "body": {
92
+ "bulkTransferId": "202137c6-2ca9-429d-b03b-41d5cf19258c",
93
+ "bulkQuoteId": "8823f09e-728c-4e04-b718-d17a24e55bb0",
94
+ "payerFsp": "string",
95
+ "payeeFsp": "string",
96
+ "expiration": "2020-01-01T10:10:10.000Z",
97
+ "extensionList": {
98
+ "extension": [
99
+ {
100
+ "key": "string",
101
+ "value": "string"
102
+ }
103
+ ]
104
+ }
105
+ }
106
+ }
107
+ }
108
+ ```
109
+
110
+ You could Send Transfer from postman or execute outbound mode with an example from examples/test-cases folder
111
+
112
+ #### 2.3 Outbound Mode
113
+
114
+ This sections will enable you to intiate requests from the cli to your DFSP implementation.
115
+
116
+ The user can create a collection of operations and add a number of assertions to these operations. The assertions can be setup and customized to support your testing requirements and verify both positive and negative requests and responses.
117
+
118
+ #### Default values
119
+
120
+ mode:
121
+ - outbound
122
+ reportFormat:
123
+ - json
124
+ reportName:
125
+ - when reportFormat is json: ${test-name}-${date-now}.json
126
+ - when reportFormat is html/printhtml format: value is generated by the service responsible for converting the json to the given format
127
+
128
+ #### Exit codes
129
+
130
+ The CLI tool is able to return the proper exit codes in case of success and failures. This will enable this tool to use in automation systems (CICD).
131
+
132
+ - 0: all assertions passed
133
+ - 1: there is at least 1 failed assertion
134
+
135
+ #### Example
136
+
137
+ command:
138
+
139
+ ```
140
+ node src/client -m outbound -i examples/collections/dfsp/p2p_happy_path.json -e examples/environments/dfsp_local_environment.json --report-format html
141
+ ```
142
+
143
+ output:
144
+
145
+ ```
146
+ Listening on outboundProgress events...
147
+ ████████████████████████████████████████ 100% | ETA: 0s | 3/3
148
+ --------------------TEST CASES--------------------
149
+ P2P Transfer Happy Path
150
+ Get party information - GET - /parties/{Type}/{ID} - [8/8]
151
+ Send quote - POST - /quotes - [11/11]
152
+ Send transfer - POST - /transfers - [9/9]
153
+ --------------------TEST CASES--------------------
154
+ ┌───────────────────────────────────────────────────────┐
155
+ │ SUMMARY │
156
+ ├───────────────────────┬───────────────────────────────┤
157
+ │ Total assertions │ 28 │
158
+ ├───────────────────────┼───────────────────────────────┤
159
+ │ Passed assertions │ 28 │
160
+ ├───────────────────────┼───────────────────────────────┤
161
+ │ Failed assertions │ 0 │
162
+ ├───────────────────────┼───────────────────────────────┤
163
+ │ Total requests │ 3 │
164
+ ├───────────────────────┼───────────────────────────────┤
165
+ │ Total test cases │ 1 │
166
+ ├───────────────────────┼───────────────────────────────┤
167
+ │ Passed percentage │ 100.00% │
168
+ ├───────────────────────┼───────────────────────────────┤
169
+ │ Started time │ Mon, 01 Jun 2020 14:46:20 GMT │
170
+ ├───────────────────────┼───────────────────────────────┤
171
+ │ Completed time │ Mon, 01 Jun 2020 14:46:21 GMT │
172
+ ├───────────────────────┼───────────────────────────────┤
173
+ │ Runtime duration │ 832 ms │
174
+ ├───────────────────────┼───────────────────────────────┤
175
+ │ Average response time │ NA │
176
+ └───────────────────────┴───────────────────────────────┘
177
+ TTK-Assertion-Report-dfsp-p2p-tests-2020-06-01T14:46:21.303Z.html was generated
178
+ Terminate with exit code 0
179
+ ```
180
+
181
+ You will find a report in the project folder - 'TTK-Assertion-Report-{collection-name}-{ISO-date}.{report-format}'
182
+
183
+ #### 2.4 AWS S3 Upload
184
+
185
+ You can choose to upload the generated report to AWS S3 at the end of tests execution.
186
+
187
+ Use the command line option **'--report-target'** to specify the target in the format `s3://<bucket_name>/<object_key>`
188
+
189
+ You can use the option **'--report-auto-filename-enable'** to replace the file name specified in the target with an auto generated file name.
190
+
191
+ To use AWS S3 service, the following environment variables should be set with proper credentials
192
+ - AWS_ACCESS_KEY_ID
193
+ - AWS_SECRET_ACCESS_KEY
194
+ - AWS_REGION
195
+
196
+ Example Command:
197
+
198
+ ```
199
+ node src/client -m outbound -i examples/collections/dfsp/p2p_happy_path.json -e examples/environments/dfsp_local_environment.json --report-format html --report-auto-filename-enable true --report-target s3://qa-reports-bucket/reports-folder/report-name.html
200
+ ```
201
+
202
+ #### 2.5 Slack Notification
203
+
204
+ You can choose to notify over a slack channel after a completed tests execution.
205
+ For this, you have to generate your `slack webhook` in slack portal and provide the webhook URL by the command line option **'--slack-webhook-url'**
206
+
207
+ If the S3 option is also set, then a link to the uploaded report will be sent in the slack notification.
208
+
209
+ Example Command:
210
+
211
+ ```
212
+ node src/client -m outbound -i examples/collections/dfsp/p2p_happy_path.json -e examples/environments/dfsp_local_environment.json --slack-webhook-url=https://hooks.slack.com/services/blablabla...
213
+ ```
@@ -0,0 +1,14 @@
1
+ {
2
+ "decisions": {
3
+ "1067560|swagmock>swagger-parser>z-schema>validator": {
4
+ "decision": "postpone",
5
+ "madeAt": 1653992416102
6
+ },
7
+ "1068118|socket.io>engine.io": {
8
+ "decision": "postpone",
9
+ "madeAt": 1653992430065
10
+ }
11
+ },
12
+ "rules": {},
13
+ "version": 1
14
+ }
package/bin/cli.js ADDED
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env node
2
+ require('../src/client')
package/jest.config.js ADDED
@@ -0,0 +1,16 @@
1
+ module.exports = {
2
+ verbose: true,
3
+ collectCoverageFrom: [
4
+ '**/src/**/**/*.js'
5
+ ],
6
+ coverageThreshold: {
7
+ global: {
8
+ statements: 90,
9
+ functions: 90,
10
+ branches: 80,
11
+ lines: 90
12
+ }
13
+ },
14
+ modulePathIgnorePatterns: ['spec_files'],
15
+ testEnvironment: 'node'
16
+ }
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+
3
+ reldir=`dirname $0`
4
+ cd $reldir
5
+ directory=`pwd`
6
+
7
+ ./ml-ttk
@@ -0,0 +1,57 @@
1
+ TTK_UI_TAG="v14.0.0"
2
+
3
+ HelpMessage () {
4
+ echo "Usage: $0 -platform [macos|linux|win] -arch [x64|x86|armv6|armv7]"
5
+ }
6
+
7
+ ARCH=""
8
+ PLATFORM=""
9
+
10
+ while [ $# -gt 0 ]
11
+ do
12
+ case $1 in
13
+ -platform) PLATFORM=$2 ;;
14
+ -arch) ARCH=$2 ;;
15
+ -h) HelpMessage; exit 1 ;;
16
+ -*) echo "$0: Invalid option $1" ; HelpMessage; exit 2 ;;
17
+ *) echo "$0: Invalid option $1" ; HelpMessage; exit 2 ;;
18
+ esac
19
+ shift
20
+ shift
21
+ done
22
+
23
+ if [ ! -d "node_modules" ]; then
24
+ echo "Folder node_modules doesn't exist"
25
+ exit 1
26
+ fi
27
+
28
+ if [ -z $ARCH ]; then
29
+ echo "arch is not specified"
30
+ exit 1
31
+ fi
32
+ if [ -z $PLATFORM ]; then
33
+ echo "platform is not specified"
34
+ exit 1
35
+ fi
36
+ ### Some tweak for postman-sandbox libray to be compatible for packaging
37
+ sed '/\"type\": \"module\"/d' node_modules/uvm/node_modules/flatted/package.json > node_modules/uvm/node_modules/flatted/package2.json
38
+ rm node_modules/uvm/node_modules/flatted/package.json
39
+ mv node_modules/uvm/node_modules/flatted/package2.json node_modules/uvm/node_modules/flatted/package.json
40
+ ### Start packaging
41
+ rm -rf out_native_bin/$PLATFORM-$ARCH
42
+ mkdir -p out_native_bin/$PLATFORM-$ARCH
43
+ pkg -t node12-$PLATFORM-$ARCH . -o out_native_bin/$PLATFORM-$ARCH/ml-ttk
44
+ cp -R spec_files out_native_bin/$PLATFORM-$ARCH
45
+ cp -R examples out_native_bin/$PLATFORM-$ARCH
46
+ ### Get the UI files from docker image
47
+ docker cp $(docker create --rm mojaloop/ml-testing-toolkit-ui:$TTK_UI_TAG):/usr/share/nginx/html ./public_html
48
+ if [ ! -d "public_html" ]; then
49
+ echo "Couldn't get the TTK UI from docker"
50
+ exit 1
51
+ fi
52
+ cp -R public_html out_native_bin/$PLATFORM-$ARCH
53
+
54
+ ### Copy files specific to platform
55
+ if [ "$PLATFORM" = "macos" ]; then
56
+ cp native-app-generation/assets/$PLATFORM/start.sh out_native_bin/$PLATFORM-$ARCH
57
+ fi
package/package.json ADDED
@@ -0,0 +1,132 @@
1
+ {
2
+ "name": "@mojaloop/ml-testing-toolkit-client-lib",
3
+ "description": "Testing Toolkit Client Library",
4
+ "version": "0.0.2",
5
+ "license": "Apache-2.0",
6
+ "author": "Vijaya Kumar Guthi, ModusBox Inc. ",
7
+ "contributors": [
8
+ "Georgi Logodazhki <georgi.logodazhki@modusbox.com>",
9
+ "Sam Kummary <sam@modusbox.com>",
10
+ "Steven Oderayi <steven.oderayi@modusbox.com>",
11
+ "Vijay Kumar <vijaya.guthi@modusbox.com>"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/mojaloop/ml-testing-toolkit-client-lib.git"
16
+ },
17
+ "bugs": "https://github.com/mojaloop/ml-testing-toolkit-client-lib/issues",
18
+ "config": {},
19
+ "bin": {
20
+ "ml-ttk-cli": "bin/cli.js"
21
+ },
22
+ "standard": {
23
+ "env": [
24
+ "jest"
25
+ ],
26
+ "ignore": [
27
+ "test",
28
+ "postman",
29
+ "documents",
30
+ "spec_files",
31
+ "simulator"
32
+ ]
33
+ },
34
+ "pre-commit": [
35
+ "standard"
36
+ ],
37
+ "scripts": {
38
+ "start": "node src/index.js",
39
+ "standard": "standard",
40
+ "standard:fix": "standard --fix",
41
+ "dev": "nodemon src/index.js",
42
+ "test": "npm run test:unit",
43
+ "test:unit": "jest --testMatch '**/test/unit/**/*.test.js'",
44
+ "test:int": "jest --reporters=default --reporters=jest-junit --testMatch '**/test/integration/**/*.test.js'",
45
+ "test:coverage": "jest --coverage --coverageThreshold='{}' --testMatch '**/test/unit/**/*.test.js'",
46
+ "test:coverage-check": "jest --coverage --testMatch '**/test/unit/**/*.test.js'",
47
+ "test:junit": "jest --reporters=default --reporters=jest-junit --testMatch '**/test/unit/**/*.test.js'",
48
+ "test:integration": "./test/integration-runner.sh ",
49
+ "cover": "npx nyc --all report --reporter=lcov npm run test",
50
+ "lint": "npx standard",
51
+ "lint:fix": "npx standard --fix",
52
+ "build": "docker build -t mojaloop-testing-toolkit:local -f ./Dockerfile .",
53
+ "run": "docker run -p 5000:5000 --rm ",
54
+ "generate-docs": "jsdoc -c jsdoc.json",
55
+ "audit:resolve": "SHELL=sh resolve-audit",
56
+ "audit:check": "SHELL=sh check-audit",
57
+ "dep:check": "npx ncu -e 2",
58
+ "dep:update": "npx ncu -u",
59
+ "genexec": "pkg -t node8-win .",
60
+ "cli": "node src/client.js",
61
+ "release": "npx standard-version --no-verify --releaseCommitMessageFormat 'chore(release): {{currentTag}} [skip ci]'",
62
+ "snapshot": "npx standard-version --no-verify --skip.changelog --prerelease snapshot --releaseCommitMessageFormat 'chore(snapshot): {{currentTag}}'"
63
+ },
64
+ "dependencies": {
65
+ "@mojaloop/central-services-logger": "^10.6.2",
66
+ "@mojaloop/ml-testing-toolkit-shared-lib": "^12.2.0",
67
+ "@mojaloop/sdk-standard-components": "10.2.0",
68
+ "@slack/webhook": "^6.0.0",
69
+ "@types/socket.io": "^2.1.4",
70
+ "adm-zip": "^0.4.14",
71
+ "atob": "2.1.2",
72
+ "aws-sdk": "^2.1009.0",
73
+ "axios": "^0.21.4",
74
+ "blipp": "4.0.1",
75
+ "cli-table3": "0.6.0",
76
+ "commander": "4.0.0",
77
+ "docdash": "1.1.1",
78
+ "dotenv": "^8.6.0",
79
+ "fs": "0.0.1-security",
80
+ "js-yaml": "^3.13.1",
81
+ "lodash": "^4.17.19",
82
+ "mv": "^2.1.1",
83
+ "node-dir": "0.1.17",
84
+ "node-strings": "^1.0.2",
85
+ "npm-run-all": "4.1.5",
86
+ "parse-strings-in-object": "1.2.0",
87
+ "path": "^0.12.7",
88
+ "rc": "1.2.8",
89
+ "request": "^2.88.2",
90
+ "request-promise-native": "1.0.8",
91
+ "selectn": "^1.1.2",
92
+ "socket.io": "^2.3.0",
93
+ "socket.io-client": "^2.3.0",
94
+ "uuid": "8.1.0",
95
+ "uuid4": "1.1.4",
96
+ "ws": "^7.5.5"
97
+ },
98
+ "devDependencies": {
99
+ "@types/jest": "24.0.22",
100
+ "eslint": "^8.0.1",
101
+ "eslint-plugin-import": "^2.25.2",
102
+ "get-port": "5.0.0",
103
+ "jest": "^27.3.0",
104
+ "jest-junit": "^13.0.0",
105
+ "jsdoc": "^3.6.10",
106
+ "nodemon": "^2.0.13",
107
+ "npm-audit-resolver": "3.0.0-7",
108
+ "npm-check-updates": "11.3.0",
109
+ "nyc": "^15.0.0",
110
+ "parse-strings-in-object": "1.2.0",
111
+ "pre-commit": "1.2.2",
112
+ "proxyquire": "2.1.3",
113
+ "sinon": "7.5.0",
114
+ "standard": "^16.0.4",
115
+ "supertest": "^4.0.2",
116
+ "swagmock": "1.0.0",
117
+ "tap-xunit": "2.4.1",
118
+ "standard-version": "^9.5.0"
119
+ },
120
+ "generator-swaggerize": {
121
+ "version": "4.1.0"
122
+ },
123
+ "pkg": {
124
+ "scripts": "src/**/custom-functions/*.js",
125
+ "options": [
126
+ "experimental-modules"
127
+ ]
128
+ },
129
+ "publishConfig": {
130
+ "registry": "https://registry.npmjs.org/"
131
+ }
132
+ }
package/src/client.js ADDED
@@ -0,0 +1,49 @@
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
+ const commander = require('commander')
25
+ const router = require('./router')
26
+
27
+ commander
28
+ .version('1.0.0', '-v, --version')
29
+ .option('-c, --config <config>', 'default configuration: {"mode": "outbound", "reportFormat": "json"}')
30
+ .option('-m, --mode <mode>', 'default: "outbound" --- supported modes: "monitoring", "outbound", "testcaseDefinitionReport"')
31
+ .option('-u, --base-url <baseUrl>', 'default: "http://localhost:5050"')
32
+ .option('-i, --input-files <inputFiles>', 'csv list of json files or directories; required when the mode is "outbound" --- supported formats: "json"')
33
+ .option('-e, --environment-file <environmentFile>', 'required when the mode is "outbound" --- supported formats: "json"')
34
+ .option('-l, --log-level <logLevel>', 'default: 0 --- supported levels: "0-Show only requests and assertion counts, 1-Show failed assertions only, 2-Show all assertions"')
35
+ .option('-b, --break-run-on-error <breakRunOnError>', 'default: false --- supported values: "false/true"')
36
+ .option('--labels <labels>', 'csv list of labels, examples: "p2p,settlements,quotes"')
37
+ .option('--report-format <reportFormat>', 'default: "json" --- supported formats: "json", "html", "printhtml"')
38
+ .option('--report-auto-filename-enable <reportAutoFilenameEnable>', 'default: false, if true the file name will be generated by the backend')
39
+ .option('--report-target <reportTarget>', 'default: "file://<file_name_genrated_by_backend>" --- supported targets: "file://path_to_file", "s3://<bucket_name>[/<file_path>]"')
40
+ .option('--slack-webhook-url <slackWebhookUrl>', 'default: "Disabled" --- supported formats: "https://....."')
41
+ .option('--extra-summary-information <Comma separated values in the format key:value>', 'default: none --- example: "Testcase Name:something,Environment:Dev1"')
42
+ .on('--help', () => { // Extra information on help message
43
+ console.log('')
44
+ console.log(' *** If the option report-target is set to use AWS S3 service, the variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION) should be passed in environment')
45
+ console.log(' ')
46
+ })
47
+ .parse(process.argv)
48
+
49
+ router.cli(commander)
@@ -0,0 +1,69 @@
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
+ * Vijay Kumar Guthi <vijaya.guthi@modusbox.com> (Original Author)
22
+ --------------
23
+ ******/
24
+ const AWS = require('aws-sdk')
25
+
26
+ // Set the region
27
+ AWS.config.update({ region: process.env.AWS_REGION })
28
+
29
+ const uploadFileDataToS3 = async (s3URL, fileData) => {
30
+ if (!AWS.config.credentials) {
31
+ console.log('ERROR: Upload to S3 failed. AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY not set')
32
+ return
33
+ }
34
+ if (!AWS.config.region) {
35
+ console.log('ERROR: Upload to S3 failed. AWS_REGION not set')
36
+ return
37
+ }
38
+
39
+ // Match with S3 regular expression
40
+ const s3Re = /s3:\/\/(.*)\/(.*)/g
41
+ const s3Arr = s3Re.exec(s3URL)
42
+ if (!s3Arr) {
43
+ return
44
+ }
45
+ const bucketName = s3Arr[1]
46
+ const objectKey = s3Arr[2]
47
+ // Create S3 service object
48
+ const s3 = new AWS.S3({ apiVersion: '2012-10-17' })
49
+ const additionalParams = {}
50
+ if (objectKey.endsWith('.html') || objectKey.endsWith('.htm')) {
51
+ additionalParams.ContentType = 'text/html'
52
+ }
53
+ // call S3 to retrieve upload file to specified bucket
54
+ const uploadParams = { Bucket: bucketName, Key: objectKey, Body: fileData, ...additionalParams }
55
+
56
+ try {
57
+ // call S3 to retrieve upload file to specified bucket
58
+ const result = await s3.upload(uploadParams).promise()
59
+ console.log('Successfully uploaded the file to S3. URL is ' + s3URL)
60
+ return result.Location
61
+ } catch (err) {
62
+ console.log('ERROR: Upload to S3 failed. ', err.message)
63
+ return null
64
+ }
65
+ }
66
+
67
+ module.exports = {
68
+ uploadFileDataToS3
69
+ }