@adobe/aio-cli-plugin-api-mesh 1.5.0 → 2.1.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.
@@ -73,8 +73,126 @@ describe('update command tests', () => {
73
73
  });
74
74
  });
75
75
 
76
- afterEach(() => {
77
- jest.restoreAllMocks();
76
+ test('should pass with valid args', async () => {
77
+ const runResult = await UpdateCommand.run();
78
+
79
+ expect(runResult).toMatchInlineSnapshot(`
80
+ {
81
+ "status": "success",
82
+ }
83
+ `);
84
+ expect(initRequestId).toHaveBeenCalled();
85
+ expect(initSdk).toHaveBeenCalledWith({
86
+ ignoreCache: true,
87
+ });
88
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
89
+ [
90
+ [
91
+ "******************************************************************************************************",
92
+ ],
93
+ [
94
+ "Your mesh is being provisioned. Wait a few minutes before checking the status of your mesh %s",
95
+ "mesh_id",
96
+ ],
97
+ [
98
+ "To check the status of your mesh, run:",
99
+ ],
100
+ [
101
+ "aio api-mesh:status",
102
+ ],
103
+ [
104
+ "******************************************************************************************************",
105
+ ],
106
+ ]
107
+ `);
108
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
109
+ });
110
+
111
+ test('should pass with valid args and ignoreCache flag', async () => {
112
+ parseSpy.mockResolvedValueOnce({
113
+ args: { file: 'valid_file_name' },
114
+ flags: {
115
+ ignoreCache: Promise.resolve(true),
116
+ autoConfirmAction: mockAutoApproveAction,
117
+ },
118
+ });
119
+
120
+ const runResult = await UpdateCommand.run();
121
+
122
+ expect(runResult).toMatchInlineSnapshot(`
123
+ {
124
+ "status": "success",
125
+ }
126
+ `);
127
+ expect(initRequestId).toHaveBeenCalled();
128
+ expect(initSdk).toHaveBeenCalledWith({
129
+ ignoreCache: true,
130
+ });
131
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
132
+ [
133
+ [
134
+ "******************************************************************************************************",
135
+ ],
136
+ [
137
+ "Your mesh is being provisioned. Wait a few minutes before checking the status of your mesh %s",
138
+ "mesh_id",
139
+ ],
140
+ [
141
+ "To check the status of your mesh, run:",
142
+ ],
143
+ [
144
+ "aio api-mesh:status",
145
+ ],
146
+ [
147
+ "******************************************************************************************************",
148
+ ],
149
+ ]
150
+ `);
151
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
152
+ });
153
+
154
+ test('should pass with valid args if autoConfirmAction flag is set', async () => {
155
+ parseSpy.mockResolvedValueOnce({
156
+ args: { file: 'valid_file_name' },
157
+ flags: {
158
+ ignoreCache: mockIgnoreCacheFlag,
159
+ autoConfirmAction: Promise.resolve(true),
160
+ },
161
+ });
162
+
163
+ const runResult = await UpdateCommand.run();
164
+
165
+ expect(runResult).toMatchInlineSnapshot(`
166
+ {
167
+ "status": "success",
168
+ }
169
+ `);
170
+ expect(initRequestId).toHaveBeenCalled();
171
+ expect(promptConfirm).not.toHaveBeenCalled();
172
+ expect(initSdk).toHaveBeenCalledWith({
173
+ ignoreCache: true,
174
+ });
175
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
176
+ [
177
+ [
178
+ "******************************************************************************************************",
179
+ ],
180
+ [
181
+ "Your mesh is being provisioned. Wait a few minutes before checking the status of your mesh %s",
182
+ "mesh_id",
183
+ ],
184
+ [
185
+ "To check the status of your mesh, run:",
186
+ ],
187
+ [
188
+ "aio api-mesh:status",
189
+ ],
190
+ [
191
+ "******************************************************************************************************",
192
+ ],
193
+ ]
194
+ `);
195
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
78
196
  });
79
197
 
80
198
  test('should fail if mesh id is missing', async () => {
@@ -84,10 +202,10 @@ describe('update command tests', () => {
84
202
  await expect(runResult).rejects.toMatchInlineSnapshot(
85
203
  `[Error: Unable to update. No mesh found for Org(1234) -> Project(5678) -> Workspace(123456789). Please check the details and try again.]`,
86
204
  );
87
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
205
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`[]`);
88
206
  expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
89
- Array [
90
- Array [
207
+ [
208
+ [
91
209
  "Unable to update. No mesh found for Org(1234) -> Project(5678) -> Workspace(123456789). Please check the details and try again.",
92
210
  ],
93
211
  ]
@@ -101,16 +219,46 @@ describe('update command tests', () => {
101
219
  await expect(runResult).rejects.toMatchInlineSnapshot(
102
220
  `[Error: Unable to get mesh ID. Please check the details and try again. RequestId: dummy_request_id]`,
103
221
  );
104
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
222
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`[]`);
105
223
  expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
106
- Array [
107
- Array [
224
+ [
225
+ [
108
226
  "Unable to get mesh ID. Please check the details and try again. RequestId: dummy_request_id",
109
227
  ],
110
228
  ]
111
229
  `);
112
230
  });
113
231
 
232
+ test('should fail if updateMesh method failed', async () => {
233
+ updateMesh.mockRejectedValueOnce(new Error('dummy_error'));
234
+
235
+ const runResult = UpdateCommand.run();
236
+
237
+ // await expect(runResult).rejects.toEqual(
238
+ // new Error(
239
+ // 'Unable to update the mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: dummy_request_id',
240
+ // ),
241
+ // );
242
+
243
+ await expect(runResult).rejects.toMatchInlineSnapshot(
244
+ `[Error: Unable to update the mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: dummy_request_id]`,
245
+ );
246
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
247
+ [
248
+ [
249
+ "dummy_error",
250
+ ],
251
+ ]
252
+ `);
253
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
254
+ [
255
+ [
256
+ "Unable to update the mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: dummy_request_id",
257
+ ],
258
+ ]
259
+ `);
260
+ });
261
+
114
262
  test('should fail if update file path is missing', async () => {
115
263
  parseSpy.mockResolvedValueOnce({
116
264
  args: { file: null },
@@ -124,10 +272,10 @@ describe('update command tests', () => {
124
272
  await expect(runResult).rejects.toEqual(
125
273
  new Error('Missing required args. Run aio api-mesh update --help for more info.'),
126
274
  );
127
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
275
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`[]`);
128
276
  expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
129
- Array [
130
- Array [
277
+ [
278
+ [
131
279
  "Missing required args. Run aio api-mesh update --help for more info.",
132
280
  ],
133
281
  ]
@@ -144,15 +292,15 @@ describe('update command tests', () => {
144
292
  ),
145
293
  );
146
294
  expect(logSpy.mock.calls).toMatchInlineSnapshot(`
147
- Array [
148
- Array [
295
+ [
296
+ [
149
297
  "File not found",
150
298
  ],
151
299
  ]
152
300
  `);
153
301
  expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
154
- Array [
155
- Array [
302
+ [
303
+ [
156
304
  "Unable to read the mesh configuration file provided. Please check the file and try again.",
157
305
  ],
158
306
  ]
@@ -166,124 +314,12 @@ describe('update command tests', () => {
166
314
 
167
315
  expect(runResult).toMatchInlineSnapshot(`"Update cancelled"`);
168
316
  expect(logSpy.mock.calls).toMatchInlineSnapshot(`
169
- Array [
170
- Array [
317
+ [
318
+ [
171
319
  "Update cancelled",
172
320
  ],
173
321
  ]
174
322
  `);
175
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
176
- });
177
-
178
- test('should fail if updateMesh method failed', async () => {
179
- updateMesh.mockRejectedValueOnce(new Error('dummy_error'));
180
-
181
- const runResult = UpdateCommand.run();
182
-
183
- await expect(runResult).rejects.toEqual(
184
- new Error(
185
- 'Unable to update the mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: dummy_request_id',
186
- ),
187
- );
188
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`
189
- Array [
190
- Array [
191
- "dummy_error",
192
- ],
193
- ]
194
- `);
195
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
196
- Array [
197
- Array [
198
- "Unable to update the mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: dummy_request_id",
199
- ],
200
- ]
201
- `);
202
- });
203
-
204
- test('should pass with valid args', async () => {
205
- const runResult = await UpdateCommand.run();
206
-
207
- expect(runResult).toMatchInlineSnapshot(`
208
- Object {
209
- "status": "success",
210
- }
211
- `);
212
- expect(initRequestId).toHaveBeenCalled();
213
- expect(initSdk).toHaveBeenCalledWith({
214
- ignoreCache: true,
215
- });
216
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`
217
- Array [
218
- Array [
219
- "Successfully updated the mesh with the id: %s",
220
- "mesh_id",
221
- ],
222
- ]
223
- `);
224
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
225
- });
226
-
227
- test('should pass with valid args and ignoreCache flag', async () => {
228
- parseSpy.mockResolvedValueOnce({
229
- args: { file: 'valid_file_name' },
230
- flags: {
231
- ignoreCache: Promise.resolve(true),
232
- autoConfirmAction: mockAutoApproveAction,
233
- },
234
- });
235
-
236
- const runResult = await UpdateCommand.run();
237
-
238
- expect(runResult).toMatchInlineSnapshot(`
239
- Object {
240
- "status": "success",
241
- }
242
- `);
243
- expect(initRequestId).toHaveBeenCalled();
244
- expect(initSdk).toHaveBeenCalledWith({
245
- ignoreCache: true,
246
- });
247
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`
248
- Array [
249
- Array [
250
- "Successfully updated the mesh with the id: %s",
251
- "mesh_id",
252
- ],
253
- ]
254
- `);
255
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
256
- });
257
-
258
- test('should pass with valid args if autoConfirmAction flag is set', async () => {
259
- parseSpy.mockResolvedValueOnce({
260
- args: { file: 'valid_file_name' },
261
- flags: {
262
- ignoreCache: mockIgnoreCacheFlag,
263
- autoConfirmAction: Promise.resolve(true),
264
- },
265
- });
266
-
267
- const runResult = await UpdateCommand.run();
268
-
269
- expect(runResult).toMatchInlineSnapshot(`
270
- Object {
271
- "status": "success",
272
- }
273
- `);
274
- expect(initRequestId).toHaveBeenCalled();
275
- expect(promptConfirm).not.toHaveBeenCalled();
276
- expect(initSdk).toHaveBeenCalledWith({
277
- ignoreCache: true,
278
- });
279
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`
280
- Array [
281
- Array [
282
- "Successfully updated the mesh with the id: %s",
283
- "mesh_id",
284
- ],
285
- ]
286
- `);
287
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
323
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
288
324
  });
289
325
  });
@@ -31,10 +31,10 @@ class CreateCommand extends Command {
31
31
  static flags = {
32
32
  ignoreCache: ignoreCacheFlag,
33
33
  autoConfirmAction: autoConfirmActionFlag,
34
- json: jsonFlag
34
+ json: jsonFlag,
35
35
  };
36
36
 
37
- static enableJsonFlag = true
37
+ static enableJsonFlag = true;
38
38
 
39
39
  async run() {
40
40
  await initRequestId();
@@ -81,8 +81,19 @@ class CreateCommand extends Command {
81
81
  let sdkList = [];
82
82
 
83
83
  if (mesh) {
84
- this.log('Successfully created mesh %s', mesh.meshId);
85
- this.log(JSON.stringify(mesh, null, 2));
84
+ this.log(
85
+ '******************************************************************************************************',
86
+ );
87
+ this.log(
88
+ 'Your mesh is being provisioned. Wait a few minutes before checking the status of your mesh %s',
89
+ mesh.meshId,
90
+ );
91
+ this.log('To check the status of your mesh, run:');
92
+ this.log('aio api-mesh:status');
93
+ this.log(
94
+ '******************************************************************************************************',
95
+ );
96
+
86
97
  // create API key credential
87
98
  const adobeIdIntegrationsForWorkspace = await createAPIMeshCredentials(
88
99
  imsOrgId,
@@ -119,12 +130,12 @@ class CreateCommand extends Command {
119
130
  } else {
120
131
  this.log('Unable to create API Key');
121
132
  }
122
- // Do not remove or rename return values.
133
+ // Do not remove or rename return values.
123
134
  // Template adobe/generator-app-api-mesh relies on "mesh" & "adobeIdIntegrationsForWorkspace" obj structure
124
135
  return {
125
136
  adobeIdIntegrationsForWorkspace,
126
137
  sdkList,
127
- mesh
138
+ mesh,
128
139
  };
129
140
  } else {
130
141
  this.error(`Unable to create a mesh. Please try again. RequestId: ${global.requestId}`, {
@@ -62,7 +62,7 @@ class DescribeCommand extends Command {
62
62
 
63
63
  return meshDetails;
64
64
  } else {
65
- this.error(
65
+ logger.error(
66
66
  `Unable to get mesh details. Please check the details and try again. RequestId: ${global.requestId}`,
67
67
  { exit: false },
68
68
  );
@@ -70,7 +70,7 @@ class GetCommand extends Command {
70
70
 
71
71
  return mesh;
72
72
  } else {
73
- this.error(
73
+ logger.error(
74
74
  `Unable to get mesh with the ID ${meshId}. Please check the mesh ID and try again. RequestId: ${global.requestId}`,
75
75
  { exit: false },
76
76
  );
@@ -41,4 +41,4 @@
41
41
  }
42
42
  ]
43
43
  }
44
- }
44
+ }
@@ -41,4 +41,4 @@
41
41
  }
42
42
  ]
43
43
  }
44
- }
44
+ }
@@ -37,7 +37,7 @@ describe('source:discover command tests', () => {
37
37
  expect(DiscoverCommand.description).toMatchInlineSnapshot(
38
38
  `"Return the list of avaliable sources"`,
39
39
  );
40
- expect(DiscoverCommand.aliases).toMatchInlineSnapshot(`Array []`);
40
+ expect(DiscoverCommand.aliases).toMatchInlineSnapshot(`[]`);
41
41
  });
42
42
  test('Check table render is executed', async () => {
43
43
  await DiscoverCommand.run([]);
@@ -46,7 +46,7 @@ describe('source:discover command tests', () => {
46
46
  test('Check that "source:install" command is called', async () => {
47
47
  InstallCommand.run = jest.fn().mockImplementation(() => 'source:install');
48
48
  promptConfirm.mockResolvedValue(true);
49
- promptMultiselect.mockResolvedValue([mockMetadataFixture['test-01']])
49
+ promptMultiselect.mockResolvedValue([mockMetadataFixture['test-01']]);
50
50
  await DiscoverCommand.run([]);
51
51
  expect(InstallCommand.run).toHaveBeenCalledTimes(1);
52
52
  });
@@ -31,8 +31,11 @@ const expectedResultForSuccessScenarios = JSON.stringify(
31
31
  4,
32
32
  );
33
33
  const normalizeAssertString = str => {
34
- return str.replace(/[\r\t]/gm, '').replace(/[\r\n]/gm, '').replace(/ +/g, ' ')
35
- }
34
+ return str
35
+ .replace(/[\r\t]/gm, '')
36
+ .replace(/[\r\n]/gm, '')
37
+ .replace(/ +/g, ' ');
38
+ };
36
39
  mockAdapter.mockImplementation(() => ({
37
40
  get: jest
38
41
  .fn()
@@ -56,8 +59,8 @@ describe('source:get command tests', () => {
56
59
  `"Command returns the content of a specific source."`,
57
60
  );
58
61
  expect(GetCommand.flags).toMatchInlineSnapshot(`
59
- Object {
60
- "confirm": Object {
62
+ {
63
+ "confirm": {
61
64
  "allowNo": false,
62
65
  "char": "c",
63
66
  "default": false,
@@ -65,37 +68,39 @@ describe('source:get command tests', () => {
65
68
  "parse": [Function],
66
69
  "type": "boolean",
67
70
  },
68
- "multiple": Object {
71
+ "multiple": {
69
72
  "allowNo": false,
70
73
  "char": "m",
71
74
  "description": "Select multiple sources",
72
- "exclusive": Array [
75
+ "exclusive": [
73
76
  "name",
74
77
  ],
75
78
  "parse": [Function],
76
79
  "type": "boolean",
77
80
  },
78
- "source": Object {
81
+ "source": {
79
82
  "char": "s",
80
83
  "description": "Source name",
81
- "input": Array [],
84
+ "input": [],
82
85
  "multiple": true,
83
86
  "parse": [Function],
84
87
  "type": "option",
85
88
  },
86
89
  }
87
90
  `);
88
- expect(GetCommand.aliases).toMatchInlineSnapshot(`Array []`);
91
+ expect(GetCommand.aliases).toMatchInlineSnapshot(`[]`);
89
92
  });
90
93
  test('Check executing without parameters', async () => {
91
94
  await GetCommand.run([]).catch(err => {
92
95
  expect(normalizeAssertString(err.message)).toEqual(
93
- normalizeAssertString(`Something went wrong with "get" command. Please try again later.` +
94
- `Error: \nThe "aio api-mesh:source:get" command requires additional parameters` +
95
- `Use "aio api-mesh:source:get --help" to see parameters information.`)
96
+ normalizeAssertString(
97
+ `Something went wrong with "get" command. Please try again later.` +
98
+ `Error: \nThe "aio api-mesh:source:get" command requires additional parameters` +
99
+ `Use "aio api-mesh:source:get --help" to see parameters information.`,
100
+ ),
96
101
  );
97
102
  });
98
- });
103
+ });
99
104
  test('Check executing success with provided name and version, copied to clipboard and logged to console', async () => {
100
105
  await GetCommand.run(['-s=test-01@0.0.1', '-s=test-02@0.0.1']);
101
106
  expect(ncp.readSync()).toEqual(expectedResultForSuccessScenarios);
@@ -109,9 +114,7 @@ describe('source:get command tests', () => {
109
114
  test('Check executing failed due to requested source does not exist', async () => {
110
115
  const name = 'test-99';
111
116
  await GetCommand.run([`-s=${name}`]).catch(err => {
112
- expect(err.message).toContain(
113
- chalk.red(`The source with the name "test-99" doesn't exist.`),
114
- );
117
+ expect(err.message).toContain(chalk.red(`The source with the name "test-99" doesn't exist.`));
115
118
  });
116
119
  });
117
120
  test('Check executing failed due to requested version does not exist', async () => {
@@ -11,11 +11,10 @@ governing permissions and limitations under the License.
11
11
  */
12
12
 
13
13
  const mockMetadataFixture = require('../__fixtures__/connectors-metadata.json');
14
- const mockSourceTest01v1Fixture = require('../__fixtures__/0.0.1-test-01.json');
15
- const mockSourceTest02v1Fixture = require('../__fixtures__/0.0.1-test-02.json');
16
14
  const mockSourceTest03v1Fixture = require('../__fixtures__/0.0.1-test-03.json');
17
15
  const mockAdapter = require('source-registry-storage-adapter');
18
16
  const chalk = require('chalk');
17
+ const path = require('path');
19
18
  const { initSdk, initRequestId, promptInput } = require('../../../../helpers');
20
19
  const mockSources = { '0.0.1-test-03': mockSourceTest03v1Fixture };
21
20
  jest.mock('source-registry-storage-adapter');
@@ -50,8 +49,8 @@ describe('source:install command tests', () => {
50
49
  `"Command to install the source to your API mesh."`,
51
50
  );
52
51
  expect(InstallCommand.flags).toMatchInlineSnapshot(`
53
- Object {
54
- "confirm": Object {
52
+ {
53
+ "confirm": {
55
54
  "allowNo": false,
56
55
  "char": "c",
57
56
  "default": false,
@@ -59,7 +58,7 @@ describe('source:install command tests', () => {
59
58
  "parse": [Function],
60
59
  "type": "boolean",
61
60
  },
62
- "ignoreCache": Object {
61
+ "ignoreCache": {
63
62
  "allowNo": false,
64
63
  "char": "i",
65
64
  "default": false,
@@ -67,33 +66,33 @@ describe('source:install command tests', () => {
67
66
  "parse": [Function],
68
67
  "type": "boolean",
69
68
  },
70
- "source": Object {
69
+ "source": {
71
70
  "char": "s",
72
71
  "description": "Source name",
73
- "input": Array [],
72
+ "input": [],
74
73
  "multiple": true,
75
74
  "parse": [Function],
76
75
  "type": "option",
77
76
  },
78
- "variable": Object {
77
+ "variable": {
79
78
  "char": "v",
80
79
  "description": "Variables required for the source",
81
- "input": Array [],
80
+ "input": [],
82
81
  "multiple": true,
83
82
  "parse": [Function],
84
83
  "type": "option",
85
84
  },
86
- "variable-file": Object {
85
+ "variable-file": {
87
86
  "char": "f",
88
87
  "description": "Variables file path",
89
- "input": Array [],
88
+ "input": [],
90
89
  "multiple": false,
91
90
  "parse": [Function],
92
91
  "type": "option",
93
92
  },
94
93
  }
95
94
  `);
96
- expect(InstallCommand.aliases).toMatchInlineSnapshot(`Array []`);
95
+ expect(InstallCommand.aliases).toMatchInlineSnapshot(`[]`);
97
96
  });
98
97
  test('Check executing without parameters', async () => {
99
98
  await InstallCommand.run([]).catch(err => {
@@ -112,8 +111,9 @@ describe('source:install command tests', () => {
112
111
  });
113
112
  });
114
113
  test('Check executing with invalid variable type', async () => {
115
- const path = `-f=${__dirname}/../__fixtures__/variables-file-invalid.json`;
116
- await InstallCommand.run(['test-03', path]).catch(err => {
114
+ const newPath = path.join(__dirname, '/../__fixtures__/variables-file-invalid.json');
115
+ const runPath = `-f=${newPath}`;
116
+ await InstallCommand.run(['test-03', runPath]).catch(err => {
117
117
  expect(err.message).toEqual(
118
118
  chalk.red(
119
119
  `The next variables has invalid type.\nVariable: ENDPOINT_URL\nRequested type: string`,