@mojaloop/ml-testing-toolkit-shared-lib 12.0.2 → 13.0.0
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/.ncurc.yaml +6 -0
- package/.nvmrc +1 -0
- package/CHANGELOG.md +16 -0
- package/CODEOWNERS +30 -0
- package/README.md +41 -0
- package/audit-ci.jsonc +10 -0
- package/jest.config.js +4 -4
- package/package.json +51 -28
- package/src/lib/openApiMockGenerator.js +36 -3
- package/src/lib/testcase-folder/folder-parser.js +113 -70
- package/.circleci/config.yml +0 -301
- package/audit-resolve.json +0 -22
- package/test/samples/api_spec_async.yaml +0 -2157
- package/test/samples/api_spec_sync.yaml +0 -529
- package/test/samples/api_spec_sync_empty.yaml +0 -7
- package/test/unit/index.test.js +0 -44
- package/test/unit/lib/openApiMockGenerator.test.js +0 -136
- package/test/unit/lib/testcase-folder/folder-parser.test.js +0 -451
- package/test/unit/lib/traceHeaderUtils.test.js +0 -91
|
@@ -1,136 +0,0 @@
|
|
|
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>
|
|
22
|
-
* Vijaya Kumar Guthi <vijaya.guthi@modusbox.com> (Original Author)
|
|
23
|
-
--------------
|
|
24
|
-
******/
|
|
25
|
-
|
|
26
|
-
'use strict'
|
|
27
|
-
const fs = require('fs')
|
|
28
|
-
|
|
29
|
-
const OpenApiMockGenerator = require('../../../src/lib/openApiMockGenerator')
|
|
30
|
-
const mockGenerator = new OpenApiMockGenerator()
|
|
31
|
-
const specFilePrefix = 'test/samples/'
|
|
32
|
-
|
|
33
|
-
const jsfRef = [
|
|
34
|
-
{
|
|
35
|
-
"id": "quoteId"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"id": "id"
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"id": "state",
|
|
42
|
-
"pattern": "Created|Closed"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"id": "reason",
|
|
46
|
-
"pattern": "Created|Closed"
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
{
|
|
50
|
-
"id": "Content-Length",
|
|
51
|
-
"pattern": "123"
|
|
52
|
-
}
|
|
53
|
-
]
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
describe('OpenApiMockGenerator', () => {
|
|
57
|
-
describe('load a async api file', () => {
|
|
58
|
-
it('Load method should not throw error', async () => {
|
|
59
|
-
await expect(mockGenerator.load(specFilePrefix + 'api_spec_async.yaml')).resolves.toBeUndefined()
|
|
60
|
-
})
|
|
61
|
-
it('generateRequestBody should generate a request body', async () => {
|
|
62
|
-
const result = await mockGenerator.generateRequestBody( '/quotes', 'post', jsfRef)
|
|
63
|
-
expect(result).toHaveProperty('quoteId')
|
|
64
|
-
})
|
|
65
|
-
it('generateRequestHeaders should generate a request headers', async () => {
|
|
66
|
-
const result = await mockGenerator.generateRequestHeaders( '/quotes', 'post', jsfRef)
|
|
67
|
-
expect(result).toHaveProperty('Accept')
|
|
68
|
-
expect(result).toHaveProperty('Content-Type')
|
|
69
|
-
expect(result).toHaveProperty('Date')
|
|
70
|
-
})
|
|
71
|
-
it('generateRequestHeaders should generate a request headers', async () => {
|
|
72
|
-
const result = await mockGenerator.generateRequestHeaders( '/transfers', 'post')
|
|
73
|
-
})
|
|
74
|
-
})
|
|
75
|
-
describe('load a sync api file', () => {
|
|
76
|
-
it('Load method should not throw error', async () => {
|
|
77
|
-
await expect(mockGenerator.load(specFilePrefix + 'api_spec_sync_empty.yaml')).resolves.toBeUndefined()
|
|
78
|
-
})
|
|
79
|
-
it('Load method should not throw error', async () => {
|
|
80
|
-
await expect(mockGenerator.load(specFilePrefix + 'api_spec_sync.yaml')).resolves.toBeUndefined()
|
|
81
|
-
})
|
|
82
|
-
it('generateRequestBody should generate a request body', async () => {
|
|
83
|
-
const result = await mockGenerator.generateRequestBody( '/settlements', 'post', jsfRef)
|
|
84
|
-
expect(result).toHaveProperty('reason')
|
|
85
|
-
expect(result).toHaveProperty('settlementWindows')
|
|
86
|
-
})
|
|
87
|
-
it('generateRequestBody should generate a request body', async () => {
|
|
88
|
-
const result = await mockGenerator.generateRequestBody( '/settlements', 'post')
|
|
89
|
-
expect(result).toHaveProperty('reason')
|
|
90
|
-
expect(result).toHaveProperty('settlementWindows')
|
|
91
|
-
})
|
|
92
|
-
it('generateResponseBody should generate a request body', async () => {
|
|
93
|
-
const result = await mockGenerator.generateResponseBody( '/settlements', 'get', jsfRef)
|
|
94
|
-
expect(result).toHaveProperty('body')
|
|
95
|
-
expect(result).toHaveProperty('status')
|
|
96
|
-
})
|
|
97
|
-
it('generateResponseBody should generate a request body', async () => {
|
|
98
|
-
const result = await mockGenerator.generateResponseBody( '/settlements', 'get')
|
|
99
|
-
expect(result).toHaveProperty('body')
|
|
100
|
-
expect(result).toHaveProperty('status')
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('generateResponseBody should generate a request body if response type is array', async () => {
|
|
104
|
-
const result = await mockGenerator.generateResponseBody( '/settlementWindows', 'get', jsfRef)
|
|
105
|
-
expect(result).toStrictEqual({})
|
|
106
|
-
})
|
|
107
|
-
it('generateResponseBody should generate a request body if response type is object', async () => {
|
|
108
|
-
const result = await mockGenerator.generateResponseBody( '/settlementWindows/{id}', 'get', jsfRef)
|
|
109
|
-
expect(result.status).toBe('200')
|
|
110
|
-
})
|
|
111
|
-
it('generateRequestQueryParams should generate query params', async () => {
|
|
112
|
-
const result = await mockGenerator.generateRequestQueryParams( '/settlementWindows', 'get')
|
|
113
|
-
expect(result).toHaveProperty('fromDateTime')
|
|
114
|
-
expect(result).toHaveProperty('participantId')
|
|
115
|
-
expect(result).toHaveProperty('state')
|
|
116
|
-
})
|
|
117
|
-
it('generateRequestQueryParams should generate query params', async () => {
|
|
118
|
-
const jsfRefNew = [
|
|
119
|
-
...jsfRef,
|
|
120
|
-
{
|
|
121
|
-
"id": "participantId",
|
|
122
|
-
"pattern": "123"
|
|
123
|
-
}
|
|
124
|
-
]
|
|
125
|
-
const result = await mockGenerator.generateRequestQueryParams( '/settlementWindows', 'get', jsfRef)
|
|
126
|
-
console.log(result)
|
|
127
|
-
expect(result).toHaveProperty('fromDateTime')
|
|
128
|
-
expect(result).toHaveProperty('participantId')
|
|
129
|
-
expect(result).toHaveProperty('state')
|
|
130
|
-
})
|
|
131
|
-
it('generateRequestQueryParams should generate query params', async () => {
|
|
132
|
-
const result = await mockGenerator.generateRequestQueryParams( '/settlementWindows/{id}', 'get', jsfRef)
|
|
133
|
-
expect(result).toEqual({})
|
|
134
|
-
})
|
|
135
|
-
})
|
|
136
|
-
})
|
|
@@ -1,451 +0,0 @@
|
|
|
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
|
-
'use strict'
|
|
26
|
-
|
|
27
|
-
const FolderParser = require('../../../../src/lib/testcase-folder/folder-parser')
|
|
28
|
-
|
|
29
|
-
const sampleTestCase = {
|
|
30
|
-
id: 1,
|
|
31
|
-
name: 'Test Case Name',
|
|
32
|
-
requests: []
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const sampleFolderRawData = [
|
|
36
|
-
{
|
|
37
|
-
name: 'name1',
|
|
38
|
-
path: 'path1',
|
|
39
|
-
size: 123,
|
|
40
|
-
modified: 'modified1',
|
|
41
|
-
content: { name: 'template1', test_cases: [ sampleTestCase ] }
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: 'name2',
|
|
45
|
-
path: 'path2',
|
|
46
|
-
size: 123,
|
|
47
|
-
modified: 'modified2',
|
|
48
|
-
content: { name: 'template2', test_cases: [ sampleTestCase ] }
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: 'name3',
|
|
52
|
-
path: 'path3/name3',
|
|
53
|
-
size: 123,
|
|
54
|
-
modified: 'modified3',
|
|
55
|
-
content: { name: 'template3', test_cases: [ sampleTestCase ] }
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
name: 'name4',
|
|
59
|
-
path: 'path3/name4',
|
|
60
|
-
size: 123,
|
|
61
|
-
modified: 'modified4',
|
|
62
|
-
content: { name: 'template4', test_cases: [ sampleTestCase ] }
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
name: 'master.json',
|
|
66
|
-
path: 'path3/master.json',
|
|
67
|
-
size: 123,
|
|
68
|
-
modified: 'modified4',
|
|
69
|
-
content: {
|
|
70
|
-
order: [
|
|
71
|
-
{
|
|
72
|
-
name: 'name4',
|
|
73
|
-
type: 'file'
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: 'name3',
|
|
77
|
-
type: 'file'
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
name: 'name1',
|
|
81
|
-
type: 'fileRef',
|
|
82
|
-
path: '../path1'
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
name: 'name3',
|
|
86
|
-
type: 'fileRef',
|
|
87
|
-
path: '../path3/name3'
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
name: 'name4',
|
|
91
|
-
type: 'fileRef',
|
|
92
|
-
path: './name4'
|
|
93
|
-
}
|
|
94
|
-
]
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
]
|
|
98
|
-
|
|
99
|
-
const sampleFolderRawDataWithMultipleFolderLevels = [
|
|
100
|
-
{
|
|
101
|
-
name: 'name1',
|
|
102
|
-
path: 'path1',
|
|
103
|
-
size: 123,
|
|
104
|
-
modified: 'modified1',
|
|
105
|
-
content: { name: 'template1', test_cases: [ sampleTestCase ] }
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
name: 'name2',
|
|
109
|
-
path: 'path2/subpath21/name2',
|
|
110
|
-
size: 123,
|
|
111
|
-
modified: 'modified2',
|
|
112
|
-
content: { name: 'template2', test_cases: [ sampleTestCase ] }
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
name: 'name3',
|
|
116
|
-
path: 'path2/subpath22/name3',
|
|
117
|
-
size: 123,
|
|
118
|
-
modified: 'modified3',
|
|
119
|
-
content: { name: 'template3', test_cases: [ sampleTestCase ] }
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
name: 'name4',
|
|
123
|
-
path: 'path2/name4',
|
|
124
|
-
size: 123,
|
|
125
|
-
modified: 'modified4',
|
|
126
|
-
content: { name: 'template4', test_cases: [ sampleTestCase ] }
|
|
127
|
-
}
|
|
128
|
-
]
|
|
129
|
-
|
|
130
|
-
const sampleWrongFolderRawDataWithoutTestCases = [
|
|
131
|
-
{
|
|
132
|
-
name: 'name1',
|
|
133
|
-
path: 'path1',
|
|
134
|
-
size: 123,
|
|
135
|
-
modified: 'modified1',
|
|
136
|
-
content: { name: 'template1' }
|
|
137
|
-
}
|
|
138
|
-
]
|
|
139
|
-
const sampleWrongFolderRawDataWithWrongFileRef = [
|
|
140
|
-
{
|
|
141
|
-
name: 'name1',
|
|
142
|
-
path: 'path1',
|
|
143
|
-
size: 123,
|
|
144
|
-
modified: 'modified1',
|
|
145
|
-
content: { name: 'template1', test_cases: [ sampleTestCase ] }
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
name: 'name2',
|
|
149
|
-
path: 'path2',
|
|
150
|
-
size: 123,
|
|
151
|
-
modified: 'modified2',
|
|
152
|
-
content: { name: 'template2', test_cases: [ sampleTestCase ] }
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
name: 'master.json',
|
|
156
|
-
path: 'master.json',
|
|
157
|
-
size: 123,
|
|
158
|
-
modified: 'modified3',
|
|
159
|
-
content: {
|
|
160
|
-
order: [
|
|
161
|
-
{
|
|
162
|
-
name: 'name1',
|
|
163
|
-
type: 'file'
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
name: 'name2',
|
|
167
|
-
type: 'file'
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
name: 'name1',
|
|
171
|
-
type: 'fileRef',
|
|
172
|
-
path: 'path3'
|
|
173
|
-
}
|
|
174
|
-
]
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
]
|
|
178
|
-
|
|
179
|
-
const sampleWrongFolderRawDataWithFileRefWrongRelativePath = [
|
|
180
|
-
{
|
|
181
|
-
name: 'name1',
|
|
182
|
-
path: 'path1',
|
|
183
|
-
size: 123,
|
|
184
|
-
modified: 'modified1',
|
|
185
|
-
content: { name: 'template1', test_cases: [ sampleTestCase ] }
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
name: 'master.json',
|
|
189
|
-
path: 'master.json',
|
|
190
|
-
size: 123,
|
|
191
|
-
modified: 'modified3',
|
|
192
|
-
content: {
|
|
193
|
-
order: [
|
|
194
|
-
{
|
|
195
|
-
name: 'name1',
|
|
196
|
-
type: 'file'
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
name: 'name1',
|
|
200
|
-
type: 'fileRef',
|
|
201
|
-
path: '../path1'
|
|
202
|
-
}
|
|
203
|
-
]
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
]
|
|
207
|
-
|
|
208
|
-
const sampleWrongFolderRawDataWithWithUnknownType = [
|
|
209
|
-
{
|
|
210
|
-
name: 'name1',
|
|
211
|
-
path: 'name1',
|
|
212
|
-
size: 123,
|
|
213
|
-
modified: 'modified1',
|
|
214
|
-
content: { name: 'template1', test_cases: [ sampleTestCase ] }
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
name: 'master.json',
|
|
218
|
-
path: 'master.json',
|
|
219
|
-
size: 123,
|
|
220
|
-
modified: 'modified3',
|
|
221
|
-
content: {
|
|
222
|
-
order: [
|
|
223
|
-
{
|
|
224
|
-
name: 'name1',
|
|
225
|
-
type: 'unknown'
|
|
226
|
-
}
|
|
227
|
-
]
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
]
|
|
231
|
-
|
|
232
|
-
const sampleSelectedFiles = [
|
|
233
|
-
'path1'
|
|
234
|
-
]
|
|
235
|
-
|
|
236
|
-
const sampleSelectedFilesWrongPath = [
|
|
237
|
-
'wrongpath'
|
|
238
|
-
]
|
|
239
|
-
|
|
240
|
-
describe('FolderParser', () => {
|
|
241
|
-
describe('getFolderData', () => {
|
|
242
|
-
it('FolderParser should export getFolderData', async () => {
|
|
243
|
-
expect(FolderParser).toHaveProperty('getFolderData')
|
|
244
|
-
})
|
|
245
|
-
it('getFolderData should return proper folder data', async () => {
|
|
246
|
-
const folderData = FolderParser.getFolderData(sampleFolderRawData)
|
|
247
|
-
expect(Array.isArray(folderData)).toBe(true)
|
|
248
|
-
expect(folderData.length).toEqual(3)
|
|
249
|
-
// Validate the first node
|
|
250
|
-
expect(folderData[0].key).toEqual('path1')
|
|
251
|
-
expect(folderData[0].title).toEqual('path1')
|
|
252
|
-
expect(folderData[0].isLeaf).toBeTruthy()
|
|
253
|
-
expect(folderData[0].extraInfo).toHaveProperty('type')
|
|
254
|
-
expect(folderData[0].extraInfo.type).toEqual('file')
|
|
255
|
-
expect(folderData[0].content).toHaveProperty('name')
|
|
256
|
-
expect(folderData[0].content.name).toEqual('template1')
|
|
257
|
-
|
|
258
|
-
// Validate the second node
|
|
259
|
-
expect(folderData[1].key).toEqual('path2')
|
|
260
|
-
expect(folderData[1].title).toEqual('path2')
|
|
261
|
-
expect(folderData[1].isLeaf).toBeTruthy()
|
|
262
|
-
expect(folderData[1].extraInfo).toHaveProperty('type')
|
|
263
|
-
expect(folderData[1].extraInfo.type).toEqual('file')
|
|
264
|
-
expect(folderData[1].content).toHaveProperty('name')
|
|
265
|
-
expect(folderData[1].content.name).toEqual('template2')
|
|
266
|
-
|
|
267
|
-
// Validate the third node
|
|
268
|
-
expect(folderData[2].key).toEqual('path3')
|
|
269
|
-
expect(folderData[2].title).toEqual('path3')
|
|
270
|
-
expect(folderData[2].isLeaf).not.toBeTruthy()
|
|
271
|
-
expect(folderData[2].extraInfo).toHaveProperty('type')
|
|
272
|
-
expect(folderData[2].extraInfo.type).toEqual('folder')
|
|
273
|
-
expect(folderData[2]).toHaveProperty('children')
|
|
274
|
-
expect(Array.isArray(folderData[2].children)).toBe(true)
|
|
275
|
-
expect(folderData[2].children.length).toEqual(5)
|
|
276
|
-
|
|
277
|
-
// Validate the child nodes, here the order should be according to master.json file. So name4 comes first.
|
|
278
|
-
const child1 = folderData[2].children[0]
|
|
279
|
-
// Validate the third node child 1
|
|
280
|
-
expect(child1.key).toEqual('path3/name4')
|
|
281
|
-
expect(child1.title).toEqual('name4')
|
|
282
|
-
expect(child1.isLeaf).toBeTruthy()
|
|
283
|
-
expect(child1.extraInfo).toHaveProperty('type')
|
|
284
|
-
expect(child1.extraInfo.type).toEqual('file')
|
|
285
|
-
expect(child1.content).toHaveProperty('name')
|
|
286
|
-
expect(child1.content.name).toEqual('template4')
|
|
287
|
-
|
|
288
|
-
const child2 = folderData[2].children[1]
|
|
289
|
-
// Validate the third node child 2
|
|
290
|
-
expect(child2.key).toEqual('path3/name3')
|
|
291
|
-
expect(child2.title).toEqual('name3')
|
|
292
|
-
expect(child2.isLeaf).toBeTruthy()
|
|
293
|
-
expect(child2.extraInfo).toHaveProperty('type')
|
|
294
|
-
expect(child2.extraInfo.type).toEqual('file')
|
|
295
|
-
expect(child2.content).toHaveProperty('name')
|
|
296
|
-
expect(child2.content.name).toEqual('template3')
|
|
297
|
-
|
|
298
|
-
const child3 = folderData[2].children[2]
|
|
299
|
-
// Validate the third node child 3
|
|
300
|
-
expect(child3.key).toEqual('path3/name1')
|
|
301
|
-
expect(child3.title).toEqual('name1')
|
|
302
|
-
expect(child3.isLeaf).toBeTruthy()
|
|
303
|
-
expect(child3.extraInfo).toHaveProperty('type')
|
|
304
|
-
expect(child3.extraInfo.type).toEqual('fileRef')
|
|
305
|
-
})
|
|
306
|
-
it('getFolderData should return proper folder data with multple subfolder levels', async () => {
|
|
307
|
-
const folderData = FolderParser.getFolderData(sampleFolderRawDataWithMultipleFolderLevels)
|
|
308
|
-
expect(Array.isArray(folderData)).toBe(true)
|
|
309
|
-
expect(folderData.length).toEqual(2)
|
|
310
|
-
// Validate the first node
|
|
311
|
-
expect(folderData[0].key).toEqual('path1')
|
|
312
|
-
expect(folderData[0].title).toEqual('path1')
|
|
313
|
-
expect(folderData[0].isLeaf).toBeTruthy()
|
|
314
|
-
expect(folderData[0].extraInfo).toHaveProperty('type')
|
|
315
|
-
expect(folderData[0].extraInfo.type).toEqual('file')
|
|
316
|
-
expect(folderData[0].content).toHaveProperty('name')
|
|
317
|
-
expect(folderData[0].content.name).toEqual('template1')
|
|
318
|
-
|
|
319
|
-
// Validate the second node
|
|
320
|
-
expect(folderData[1].key).toEqual('path2')
|
|
321
|
-
expect(folderData[1].title).toEqual('path2')
|
|
322
|
-
expect(folderData[1].isLeaf).not.toBeTruthy()
|
|
323
|
-
expect(folderData[1].extraInfo).toHaveProperty('type')
|
|
324
|
-
expect(folderData[1].extraInfo.type).toEqual('folder')
|
|
325
|
-
expect(folderData[1]).toHaveProperty('children')
|
|
326
|
-
expect(Array.isArray(folderData[1].children)).toBe(true)
|
|
327
|
-
expect(folderData[1].children.length).toEqual(3)
|
|
328
|
-
|
|
329
|
-
// Validate the child nodes
|
|
330
|
-
const child1 = folderData[1].children[0]
|
|
331
|
-
// Validate the second node child 1
|
|
332
|
-
expect(child1.key).toEqual('path2/subpath21')
|
|
333
|
-
expect(child1.title).toEqual('subpath21')
|
|
334
|
-
expect(child1.isLeaf).not.toBeTruthy()
|
|
335
|
-
expect(child1.extraInfo).toHaveProperty('type')
|
|
336
|
-
expect(child1.extraInfo.type).toEqual('folder')
|
|
337
|
-
expect(child1).toHaveProperty('children')
|
|
338
|
-
|
|
339
|
-
// Validate the sub child nodes
|
|
340
|
-
const subChild1 = child1.children[0]
|
|
341
|
-
// Validate the second node child 1
|
|
342
|
-
expect(subChild1.key).toEqual('path2/subpath21/name2')
|
|
343
|
-
expect(subChild1.title).toEqual('name2')
|
|
344
|
-
expect(subChild1.isLeaf).toBeTruthy()
|
|
345
|
-
expect(subChild1.extraInfo).toHaveProperty('type')
|
|
346
|
-
expect(subChild1.extraInfo.type).toEqual('file')
|
|
347
|
-
|
|
348
|
-
})
|
|
349
|
-
})
|
|
350
|
-
|
|
351
|
-
describe('getFolderData negative scenarios', () => {
|
|
352
|
-
it('getFolderData should not throw any error when unknown type specified in master.json', async () => {
|
|
353
|
-
const folderData = FolderParser.getFolderData(sampleWrongFolderRawDataWithWithUnknownType)
|
|
354
|
-
expect(Array.isArray(folderData)).toBe(true)
|
|
355
|
-
expect(folderData.length).toEqual(0)
|
|
356
|
-
})
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
describe('getTestCases', () => {
|
|
360
|
-
it('FolderParser should export getTestCases', async () => {
|
|
361
|
-
expect(FolderParser).toHaveProperty('getTestCases')
|
|
362
|
-
})
|
|
363
|
-
it('getTestCases should return proper test cases', async () => {
|
|
364
|
-
// First get the folderData
|
|
365
|
-
const folderData = FolderParser.getFolderData(sampleFolderRawData)
|
|
366
|
-
const testCases = FolderParser.getTestCases(folderData)
|
|
367
|
-
expect(Array.isArray(testCases)).toBe(true)
|
|
368
|
-
expect(testCases.length).toEqual(7)
|
|
369
|
-
// Validate the first test case
|
|
370
|
-
expect(testCases[0]).toHaveProperty('id')
|
|
371
|
-
expect(testCases[0].id).toEqual(1)
|
|
372
|
-
expect(testCases[0]).toHaveProperty('name')
|
|
373
|
-
expect(testCases[0].name).toEqual('Test Case Name')
|
|
374
|
-
|
|
375
|
-
// Validate the second test case
|
|
376
|
-
expect(testCases[1]).toHaveProperty('id')
|
|
377
|
-
expect(testCases[1].id).toEqual(1)
|
|
378
|
-
expect(testCases[1]).toHaveProperty('name')
|
|
379
|
-
expect(testCases[1].name).toEqual('Test Case Name')
|
|
380
|
-
})
|
|
381
|
-
it('getTestCases with selected files should return proper test cases', async () => {
|
|
382
|
-
// First get the folderData
|
|
383
|
-
const folderData = FolderParser.getFolderData(sampleFolderRawData)
|
|
384
|
-
const testCases = FolderParser.getTestCases(folderData, sampleSelectedFiles)
|
|
385
|
-
expect(Array.isArray(testCases)).toBe(true)
|
|
386
|
-
expect(testCases.length).toEqual(1)
|
|
387
|
-
// Validate the first test case
|
|
388
|
-
expect(testCases[0]).toHaveProperty('id')
|
|
389
|
-
expect(testCases[0].id).toEqual(1)
|
|
390
|
-
expect(testCases[0]).toHaveProperty('name')
|
|
391
|
-
expect(testCases[0].name).toEqual('Test Case Name')
|
|
392
|
-
})
|
|
393
|
-
})
|
|
394
|
-
|
|
395
|
-
describe('sequenceTestCases', () => {
|
|
396
|
-
it('FolderParser should export sequenceTestCases', async () => {
|
|
397
|
-
expect(FolderParser).toHaveProperty('sequenceTestCases')
|
|
398
|
-
})
|
|
399
|
-
it('sequenceTestCases should return the same number of test cases', async () => {
|
|
400
|
-
// First get the folderData
|
|
401
|
-
const folderData = FolderParser.getFolderData(sampleFolderRawData)
|
|
402
|
-
// Get the test cases
|
|
403
|
-
const testCases = FolderParser.getTestCases(folderData)
|
|
404
|
-
// Sequence them
|
|
405
|
-
FolderParser.sequenceTestCases(testCases)
|
|
406
|
-
// Validate the modified test cases
|
|
407
|
-
expect(Array.isArray(testCases)).toBe(true)
|
|
408
|
-
expect(testCases.length).toEqual(7)
|
|
409
|
-
})
|
|
410
|
-
})
|
|
411
|
-
|
|
412
|
-
describe('getTestCases negative scenarios', () => {
|
|
413
|
-
it('getTestCases should not throw error when a template content is supplied without test cases', async () => {
|
|
414
|
-
// First get the folderData
|
|
415
|
-
const folderData = FolderParser.getFolderData(sampleWrongFolderRawDataWithoutTestCases)
|
|
416
|
-
const testCases = FolderParser.getTestCases(folderData)
|
|
417
|
-
expect(Array.isArray(testCases)).toBe(true)
|
|
418
|
-
expect(testCases.length).toEqual(0)
|
|
419
|
-
})
|
|
420
|
-
it('getTestCases should not throw error when a file ref is provided with a path not exists', async () => {
|
|
421
|
-
// First get the folderData
|
|
422
|
-
const folderData = FolderParser.getFolderData(sampleWrongFolderRawDataWithWrongFileRef)
|
|
423
|
-
const testCases = FolderParser.getTestCases(folderData)
|
|
424
|
-
expect(Array.isArray(testCases)).toBe(true)
|
|
425
|
-
expect(testCases.length).toEqual(0)
|
|
426
|
-
})
|
|
427
|
-
it('getTestCases should not throw error when a file ref is provided with wrong relative path', async () => {
|
|
428
|
-
// First get the folderData
|
|
429
|
-
const folderData = FolderParser.getFolderData(sampleWrongFolderRawDataWithFileRefWrongRelativePath)
|
|
430
|
-
const testCases = FolderParser.getTestCases(folderData)
|
|
431
|
-
expect(Array.isArray(testCases)).toBe(true)
|
|
432
|
-
expect(testCases.length).toEqual(0)
|
|
433
|
-
})
|
|
434
|
-
it('getTestCases with wrong selected files should not return any test cases', async () => {
|
|
435
|
-
// First get the folderData
|
|
436
|
-
const folderData = FolderParser.getFolderData(sampleFolderRawData)
|
|
437
|
-
const testCases = FolderParser.getTestCases(folderData, sampleSelectedFilesWrongPath)
|
|
438
|
-
expect(Array.isArray(testCases)).toBe(true)
|
|
439
|
-
expect(testCases.length).toEqual(0)
|
|
440
|
-
})
|
|
441
|
-
it('getTestCases with wrong folderData should not return any test cases', async () => {
|
|
442
|
-
// First get the folderData
|
|
443
|
-
const folderData = FolderParser.getFolderData(sampleFolderRawData)
|
|
444
|
-
// Chnage the folder data
|
|
445
|
-
folderData[0].title = 'wrongtitle'
|
|
446
|
-
const testCases = FolderParser.getTestCases(folderData, [ 'path3/name1' ])
|
|
447
|
-
expect(Array.isArray(testCases)).toBe(true)
|
|
448
|
-
expect(testCases.length).toEqual(0)
|
|
449
|
-
})
|
|
450
|
-
})
|
|
451
|
-
})
|
|
@@ -1,91 +0,0 @@
|
|
|
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
|
-
'use strict'
|
|
26
|
-
|
|
27
|
-
const TraceHeaderUtils = require('../../../src/lib/traceHeaderUtils')
|
|
28
|
-
|
|
29
|
-
describe('TraceHeaderUtils', () => {
|
|
30
|
-
describe('isCustomTraceID', () => {
|
|
31
|
-
const customTraceID = 'aabb14d5b207d3ba722c6c0fdcd44c61'
|
|
32
|
-
const nonCustomTraceID = '664314d5b207d3ba722c6c0fdcd44c61'
|
|
33
|
-
it('Result must be false for non custom traceIDs', () => {
|
|
34
|
-
const result = TraceHeaderUtils.isCustomTraceID(nonCustomTraceID)
|
|
35
|
-
expect(result).toBe(false)
|
|
36
|
-
})
|
|
37
|
-
it('Result must be true for custom traceIDs', () => {
|
|
38
|
-
const result = TraceHeaderUtils.isCustomTraceID(customTraceID)
|
|
39
|
-
expect(result).toBe(true)
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
describe('getEndToEndID', () => {
|
|
43
|
-
const traceID1 = 'aabb14d5b207d3ba722c6c0fdcd44c61'
|
|
44
|
-
const traceID2 = 'aabb14d5b207d3ba722c6c0fdcd41234'
|
|
45
|
-
it('Should get the end to end properly', () => {
|
|
46
|
-
const result = TraceHeaderUtils.getEndToEndID(traceID1)
|
|
47
|
-
expect(result).toEqual('4c61')
|
|
48
|
-
})
|
|
49
|
-
it('Should get the end to end properly', () => {
|
|
50
|
-
const result = TraceHeaderUtils.getEndToEndID(traceID2)
|
|
51
|
-
expect(result).toEqual('1234')
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
describe('getSessionID', () => {
|
|
55
|
-
const traceID = 'aabb14d5b207d3ba722c6c0fdcd44c61'
|
|
56
|
-
it('Should get the session ID properly', () => {
|
|
57
|
-
const result = TraceHeaderUtils.getSessionID(traceID)
|
|
58
|
-
expect(result).toEqual('14d5b207d3ba722c6c0fdcd4')
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
describe('getTraceIdPrefix', () => {
|
|
62
|
-
it('Should get the session ID properly', () => {
|
|
63
|
-
const result = TraceHeaderUtils.getTraceIdPrefix()
|
|
64
|
-
expect(result).toBeDefined()
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
describe('getTraceParentHeader', () => {
|
|
68
|
-
it('Should get the session ID properly', () => {
|
|
69
|
-
const result = TraceHeaderUtils.getTraceParentHeader('aabb')
|
|
70
|
-
expect(result).toBeDefined()
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
describe('generateRandTraceId', () => {
|
|
74
|
-
it('Should get the random trace ID properly', () => {
|
|
75
|
-
const result = TraceHeaderUtils.generateRandTraceId(4)
|
|
76
|
-
expect(result).toBeDefined()
|
|
77
|
-
})
|
|
78
|
-
})
|
|
79
|
-
describe('generateSessionId', () => {
|
|
80
|
-
it('Should get the random session ID properly', () => {
|
|
81
|
-
const result = TraceHeaderUtils.generateSessionId()
|
|
82
|
-
expect(result).toBeDefined()
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
describe('generateEndToEndId', () => {
|
|
86
|
-
it('Should get the random endToEnd ID properly', () => {
|
|
87
|
-
const result = TraceHeaderUtils.generateEndToEndId()
|
|
88
|
-
expect(result).toBeDefined()
|
|
89
|
-
})
|
|
90
|
-
})
|
|
91
|
-
})
|