@adobe/aio-cli-plugin-api-mesh 2.0.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.
@@ -1 +1 @@
1
- {"version":"2.0.0","commands":{"PLUGINNAME":{"id":"PLUGINNAME","description":"Your description here","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio PLUGINNAME:some_command"],"flags":{"someflag":{"name":"someflag","type":"option","char":"f","description":"this is some flag"}},"args":[]},"api-mesh:create":{"id":"api-mesh:create","description":"Create a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false},"json":{"name":"json","type":"boolean","description":"Output JSON","allowNo":false}},"args":[{"name":"file"}]},"api-mesh:delete":{"id":"api-mesh:delete","description":"Delete the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false}},"args":[]},"api-mesh:describe":{"id":"api-mesh:describe","description":"Get details of a mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[]},"api-mesh:get":{"id":"api-mesh:get","description":"Get the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[{"name":"file"}]},"api-mesh:status":{"id":"api-mesh:status","description":"Get a mesh status with a given meshid.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[]},"api-mesh:update":{"id":"api-mesh:update","description":"Update a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false}},"args":[{"name":"file"}]},"api-mesh:source:discover":{"id":"api-mesh:source:discover","description":"Return the list of avaliable sources","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm install action prompt. CLI will not check ask user to install source.","allowNo":false}},"args":[]},"api-mesh:source:get":{"id":"api-mesh:source:get","description":"Command returns the content of a specific source.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio api-mesh:source:get -s=<version>@<source_name>","$ aio api-mesh:source:get -s<source_name>","$ aio api-mesh:source:get -m"],"flags":{"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm print action prompt. CLI will not check ask user to print source.","allowNo":false},"source":{"name":"source","type":"option","char":"s","description":"Source name"},"multiple":{"name":"multiple","type":"boolean","char":"m","description":"Select multiple sources","allowNo":false}},"args":[]},"api-mesh:source:install":{"id":"api-mesh:source:install","description":"Command to install the source to your API mesh.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio api-mesh:source:install <version>@<source_name>","$ aio api-mesh:source:install <source_name> -v <variable_name>=<variable_value>","$ aio api-mesh:source:install <source_name> -f <path_to_variables_file>"],"flags":{"source":{"name":"source","type":"option","char":"s","description":"Source name"},"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm override action prompt. CLI will not check ask user to override source.","allowNo":false},"variable":{"name":"variable","type":"option","char":"v","description":"Variables required for the source"},"variable-file":{"name":"variable-file","type":"option","char":"f","description":"Variables file path"},"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[{"name":"source"}]}}}
1
+ {"version":"2.1.0","commands":{"PLUGINNAME":{"id":"PLUGINNAME","description":"Your description here","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio PLUGINNAME:some_command"],"flags":{"someflag":{"name":"someflag","type":"option","char":"f","description":"this is some flag"}},"args":[]},"api-mesh:create":{"id":"api-mesh:create","description":"Create a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false},"json":{"name":"json","type":"boolean","description":"Output JSON","allowNo":false}},"args":[{"name":"file"}]},"api-mesh:delete":{"id":"api-mesh:delete","description":"Delete the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false}},"args":[]},"api-mesh:describe":{"id":"api-mesh:describe","description":"Get details of a mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[]},"api-mesh:get":{"id":"api-mesh:get","description":"Get the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[{"name":"file"}]},"api-mesh:status":{"id":"api-mesh:status","description":"Get a mesh status with a given meshid.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[]},"api-mesh:update":{"id":"api-mesh:update","description":"Update a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false}},"args":[{"name":"file"}]},"api-mesh:source:discover":{"id":"api-mesh:source:discover","description":"Return the list of avaliable sources","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm install action prompt. CLI will not check ask user to install source.","allowNo":false}},"args":[]},"api-mesh:source:get":{"id":"api-mesh:source:get","description":"Command returns the content of a specific source.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio api-mesh:source:get -s=<version>@<source_name>","$ aio api-mesh:source:get -s<source_name>","$ aio api-mesh:source:get -m"],"flags":{"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm print action prompt. CLI will not check ask user to print source.","allowNo":false},"source":{"name":"source","type":"option","char":"s","description":"Source name"},"multiple":{"name":"multiple","type":"boolean","char":"m","description":"Select multiple sources","allowNo":false}},"args":[]},"api-mesh:source:install":{"id":"api-mesh:source:install","description":"Command to install the source to your API mesh.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio api-mesh:source:install <version>@<source_name>","$ aio api-mesh:source:install <source_name> -v <variable_name>=<variable_value>","$ aio api-mesh:source:install <source_name> -f <path_to_variables_file>"],"flags":{"source":{"name":"source","type":"option","char":"s","description":"Source name"},"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm override action prompt. CLI will not check ask user to override source.","allowNo":false},"variable":{"name":"variable","type":"option","char":"v","description":"Variables required for the source"},"variable-file":{"name":"variable-file","type":"option","char":"f","description":"Variables file path"},"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[{"name":"source"}]}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/aio-cli-plugin-api-mesh",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "engines": {
53
53
  "npm": ">=8.0.0",
54
- "node": ">=18.0.0"
54
+ "node": "^16.13 || >=18.0.0"
55
55
  },
56
56
  "files": [
57
57
  "/oclif.manifest.json",
@@ -84,8 +84,20 @@ describe('create command tests', () => {
84
84
  });
85
85
  });
86
86
 
87
- afterEach(() => {
88
- jest.restoreAllMocks();
87
+ test('must return proper object structure used by adobe/generator-app-api-mesh', async () => {
88
+ parseSpy.mockResolvedValueOnce({
89
+ args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
90
+ flags: {
91
+ json: Promise.resolve(true),
92
+ },
93
+ });
94
+ const output = await CreateCommand.run();
95
+ expect(output).toHaveProperty('mesh');
96
+ expect(output).toHaveProperty('adobeIdIntegrationsForWorkspace');
97
+ expect(output.mesh).toEqual(expect.objectContaining({ meshId: 'dummy_mesh_id' }));
98
+ expect(output.adobeIdIntegrationsForWorkspace).toEqual(
99
+ expect.objectContaining({ apiKey: 'dummy_api_key' }),
100
+ );
89
101
  });
90
102
 
91
103
  test('snapshot create command description', () => {
@@ -128,6 +140,131 @@ describe('create command tests', () => {
128
140
  `);
129
141
  expect(CreateCommand.aliases).toMatchInlineSnapshot(`[]`);
130
142
  });
143
+ test('should fail if create mesh api has failed', async () => {
144
+ createMesh.mockRejectedValueOnce(new Error('create mesh api failed'));
145
+
146
+ const runResult = CreateCommand.run();
147
+ await expect(runResult).rejects.toEqual(
148
+ new Error(
149
+ 'Unable to create a mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: dummy_request_id',
150
+ ),
151
+ );
152
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
153
+ [
154
+ [
155
+ "create mesh api failed",
156
+ ],
157
+ ]
158
+ `);
159
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
160
+ [
161
+ [
162
+ "Unable to create a mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: dummy_request_id",
163
+ ],
164
+ ]
165
+ `);
166
+ });
167
+ test('should create if a valid mesh config file is provided', async () => {
168
+ const runResult = await CreateCommand.run();
169
+
170
+ expect(initRequestId).toHaveBeenCalled();
171
+ expect(createMesh.mock.calls[0]).toMatchInlineSnapshot(`
172
+ [
173
+ "1234",
174
+ "5678",
175
+ "123456789",
176
+ {
177
+ "meshConfig": {
178
+ "sources": [
179
+ {
180
+ "handler": {
181
+ "graphql": {
182
+ "endpoint": "<gql_endpoint>",
183
+ },
184
+ },
185
+ "name": "<api_name>",
186
+ },
187
+ ],
188
+ },
189
+ },
190
+ ]
191
+ `);
192
+ expect(createAPIMeshCredentials.mock.calls[0]).toMatchInlineSnapshot(`
193
+ [
194
+ "1234",
195
+ "5678",
196
+ "123456789",
197
+ ]
198
+ `);
199
+ expect(subscribeCredentialToMeshService.mock.calls[0]).toMatchInlineSnapshot(`
200
+ [
201
+ "1234",
202
+ "5678",
203
+ "123456789",
204
+ "dummy_id",
205
+ ]
206
+ `);
207
+ expect(runResult).toMatchInlineSnapshot(`
208
+ {
209
+ "adobeIdIntegrationsForWorkspace": {
210
+ "apiKey": "dummy_api_key",
211
+ "id": "dummy_id",
212
+ },
213
+ "mesh": {
214
+ "meshConfig": {
215
+ "sources": [
216
+ {
217
+ "handler": {
218
+ "graphql": {
219
+ "endpoint": "<gql_endpoint>",
220
+ },
221
+ },
222
+ "name": "<api_name>",
223
+ },
224
+ ],
225
+ },
226
+ "meshId": "dummy_mesh_id",
227
+ },
228
+ "sdkList": [
229
+ "dummy_service",
230
+ ],
231
+ }
232
+ `);
233
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
234
+ [
235
+ [
236
+ "******************************************************************************************************",
237
+ ],
238
+ [
239
+ "Your mesh is being provisioned. Wait a few minutes before checking the status of your mesh %s",
240
+ "dummy_mesh_id",
241
+ ],
242
+ [
243
+ "To check the status of your mesh, run:",
244
+ ],
245
+ [
246
+ "aio api-mesh:status",
247
+ ],
248
+ [
249
+ "******************************************************************************************************",
250
+ ],
251
+ [
252
+ "Successfully created API Key %s",
253
+ "dummy_api_key",
254
+ ],
255
+ [
256
+ "Successfully subscribed API Key %s to API Mesh service",
257
+ "dummy_api_key",
258
+ ],
259
+ [
260
+ "Mesh Endpoint: %s
261
+ ",
262
+ "https://graph.adobe.io/api/dummy_mesh_id/graphql?api_key=dummy_api_key",
263
+ ],
264
+ ]
265
+ `);
266
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
267
+ });
131
268
 
132
269
  test('should fail if mesh config file arg is missing', async () => {
133
270
  parseSpy.mockResolvedValueOnce({
@@ -183,34 +320,8 @@ describe('create command tests', () => {
183
320
  `);
184
321
  });
185
322
 
186
- test('should fail if create mesh api has failed', async () => {
187
- createMesh.mockRejectedValueOnce(new Error('create mesh api failed'));
188
-
189
- const runResult = CreateCommand.run();
190
-
191
- await expect(runResult).rejects.toEqual(
192
- new Error(
193
- 'Unable to create a mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: dummy_request_id',
194
- ),
195
- );
196
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`
197
- [
198
- [
199
- "create mesh api failed",
200
- ],
201
- ]
202
- `);
203
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
204
- [
205
- [
206
- "Unable to create a mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: dummy_request_id",
207
- ],
208
- ]
209
- `);
210
- });
211
-
212
323
  test('should fail if create api credential api has failed', async () => {
213
- createAPIMeshCredentials.mockRejectedValueOnce(new Error('create api credential api failed'));
324
+ createAPIMeshCredentials.mockRejectedValue(new Error('create api credential api failed'));
214
325
 
215
326
  const runResult = CreateCommand.run();
216
327
 
@@ -299,108 +410,6 @@ describe('create command tests', () => {
299
410
  `);
300
411
  });
301
412
 
302
- test('should create if a valid mesh config file is provided', async () => {
303
- const runResult = await CreateCommand.run();
304
-
305
- expect(initRequestId).toHaveBeenCalled();
306
- expect(createMesh.mock.calls[0]).toMatchInlineSnapshot(`
307
- [
308
- "1234",
309
- "5678",
310
- "123456789",
311
- {
312
- "meshConfig": {
313
- "sources": [
314
- {
315
- "handler": {
316
- "graphql": {
317
- "endpoint": "<gql_endpoint>",
318
- },
319
- },
320
- "name": "<api_name>",
321
- },
322
- ],
323
- },
324
- },
325
- ]
326
- `);
327
- expect(createAPIMeshCredentials.mock.calls[0]).toMatchInlineSnapshot(`
328
- [
329
- "1234",
330
- "5678",
331
- "123456789",
332
- ]
333
- `);
334
- expect(subscribeCredentialToMeshService.mock.calls[0]).toMatchInlineSnapshot(`
335
- [
336
- "1234",
337
- "5678",
338
- "123456789",
339
- "dummy_id",
340
- ]
341
- `);
342
- expect(runResult).toMatchInlineSnapshot(`
343
- {
344
- "adobeIdIntegrationsForWorkspace": {
345
- "apiKey": "dummy_api_key",
346
- "id": "dummy_id",
347
- },
348
- "mesh": {
349
- "meshConfig": {
350
- "sources": [
351
- {
352
- "handler": {
353
- "graphql": {
354
- "endpoint": "<gql_endpoint>",
355
- },
356
- },
357
- "name": "<api_name>",
358
- },
359
- ],
360
- },
361
- "meshId": "dummy_mesh_id",
362
- },
363
- "sdkList": [
364
- "dummy_service",
365
- ],
366
- }
367
- `);
368
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`
369
- [
370
- [
371
- "******************************************************************************************************",
372
- ],
373
- [
374
- "Your mesh is being provisioned. Wait a few minutes before checking the status of your mesh %s",
375
- "dummy_mesh_id",
376
- ],
377
- [
378
- "To check the status of your mesh, run:",
379
- ],
380
- [
381
- "aio api-mesh:status",
382
- ],
383
- [
384
- "******************************************************************************************************",
385
- ],
386
- [
387
- "Successfully created API Key %s",
388
- "dummy_api_key",
389
- ],
390
- [
391
- "Successfully subscribed API Key %s to API Mesh service",
392
- "dummy_api_key",
393
- ],
394
- [
395
- "Mesh Endpoint: %s
396
- ",
397
- "https://graph.adobe.io/api/dummy_mesh_id/graphql?api_key=dummy_api_key",
398
- ],
399
- ]
400
- `);
401
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
402
- });
403
-
404
413
  test('should not ask for confirmation if autoConfirmAction is provided', async () => {
405
414
  parseSpy.mockResolvedValueOnce({
406
415
  args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
@@ -472,20 +481,4 @@ describe('create command tests', () => {
472
481
  `);
473
482
  expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
474
483
  });
475
-
476
- test('must return proper object structure used by adobe/generator-app-api-mesh', async () => {
477
- parseSpy.mockResolvedValueOnce({
478
- args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
479
- flags: {
480
- json: Promise.resolve(true),
481
- },
482
- });
483
- const output = await CreateCommand.run();
484
- expect(output).toHaveProperty('mesh');
485
- expect(output).toHaveProperty('adobeIdIntegrationsForWorkspace');
486
- expect(output.mesh).toEqual(expect.objectContaining({ meshId: 'dummy_mesh_id' }));
487
- expect(output.adobeIdIntegrationsForWorkspace).toEqual(
488
- expect.objectContaining({ apiKey: 'dummy_api_key' }),
489
- );
490
- });
491
484
  });
@@ -81,9 +81,9 @@ describe('delete command tests', () => {
81
81
  });
82
82
  });
83
83
 
84
- afterEach(() => {
85
- jest.restoreAllMocks();
86
- });
84
+ // afterEach(() => {
85
+ // jest.restoreAllMocks();
86
+ // });
87
87
 
88
88
  test('snapshot delete command description', () => {
89
89
  expect(DeleteCommand.description).toMatchInlineSnapshot(`"Delete the config of a given mesh"`);
@@ -73,134 +73,6 @@ describe('update command tests', () => {
73
73
  });
74
74
  });
75
75
 
76
- afterEach(() => {
77
- jest.restoreAllMocks();
78
- });
79
-
80
- test('should fail if mesh id is missing', async () => {
81
- getMeshId.mockResolvedValue(null);
82
- const runResult = UpdateCommand.run();
83
-
84
- await expect(runResult).rejects.toMatchInlineSnapshot(
85
- `[Error: Unable to update. No mesh found for Org(1234) -> Project(5678) -> Workspace(123456789). Please check the details and try again.]`,
86
- );
87
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`[]`);
88
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
89
- [
90
- [
91
- "Unable to update. No mesh found for Org(1234) -> Project(5678) -> Workspace(123456789). Please check the details and try again.",
92
- ],
93
- ]
94
- `);
95
- });
96
-
97
- test('should fail if getMeshId api failed', async () => {
98
- getMeshId.mockRejectedValue(new Error('getMeshId api failed'));
99
- const runResult = UpdateCommand.run();
100
-
101
- await expect(runResult).rejects.toMatchInlineSnapshot(
102
- `[Error: Unable to get mesh ID. Please check the details and try again. RequestId: dummy_request_id]`,
103
- );
104
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`[]`);
105
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
106
- [
107
- [
108
- "Unable to get mesh ID. Please check the details and try again. RequestId: dummy_request_id",
109
- ],
110
- ]
111
- `);
112
- });
113
-
114
- test('should fail if update file path is missing', async () => {
115
- parseSpy.mockResolvedValueOnce({
116
- args: { file: null },
117
- flags: {
118
- ignoreCache: mockIgnoreCacheFlag,
119
- autoConfirmAction: mockAutoApproveAction,
120
- },
121
- });
122
- const runResult = UpdateCommand.run();
123
-
124
- await expect(runResult).rejects.toEqual(
125
- new Error('Missing required args. Run aio api-mesh update --help for more info.'),
126
- );
127
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`[]`);
128
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
129
- [
130
- [
131
- "Missing required args. Run aio api-mesh update --help for more info.",
132
- ],
133
- ]
134
- `);
135
- });
136
-
137
- test('should fail if dummy file path is provided', async () => {
138
- readFile.mockRejectedValueOnce(new Error('File not found'));
139
- const runResult = UpdateCommand.run();
140
-
141
- await expect(runResult).rejects.toEqual(
142
- new Error(
143
- 'Unable to read the mesh configuration file provided. Please check the file and try again.',
144
- ),
145
- );
146
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`
147
- [
148
- [
149
- "File not found",
150
- ],
151
- ]
152
- `);
153
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
154
- [
155
- [
156
- "Unable to read the mesh configuration file provided. Please check the file and try again.",
157
- ],
158
- ]
159
- `);
160
- });
161
-
162
- test('should not update if user prompt returns false', async () => {
163
- promptConfirm.mockResolvedValueOnce(false);
164
-
165
- const runResult = await UpdateCommand.run();
166
-
167
- expect(runResult).toMatchInlineSnapshot(`"Update cancelled"`);
168
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`
169
- [
170
- [
171
- "Update cancelled",
172
- ],
173
- ]
174
- `);
175
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
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
- [
190
- [
191
- "dummy_error",
192
- ],
193
- ]
194
- `);
195
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
196
- [
197
- [
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
76
  test('should pass with valid args', async () => {
205
77
  const runResult = await UpdateCommand.run();
206
78
 
@@ -322,4 +194,132 @@ describe('update command tests', () => {
322
194
  `);
323
195
  expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
324
196
  });
197
+
198
+ test('should fail if mesh id is missing', async () => {
199
+ getMeshId.mockResolvedValue(null);
200
+ const runResult = UpdateCommand.run();
201
+
202
+ await expect(runResult).rejects.toMatchInlineSnapshot(
203
+ `[Error: Unable to update. No mesh found for Org(1234) -> Project(5678) -> Workspace(123456789). Please check the details and try again.]`,
204
+ );
205
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`[]`);
206
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
207
+ [
208
+ [
209
+ "Unable to update. No mesh found for Org(1234) -> Project(5678) -> Workspace(123456789). Please check the details and try again.",
210
+ ],
211
+ ]
212
+ `);
213
+ });
214
+
215
+ test('should fail if getMeshId api failed', async () => {
216
+ getMeshId.mockRejectedValue(new Error('getMeshId api failed'));
217
+ const runResult = UpdateCommand.run();
218
+
219
+ await expect(runResult).rejects.toMatchInlineSnapshot(
220
+ `[Error: Unable to get mesh ID. Please check the details and try again. RequestId: dummy_request_id]`,
221
+ );
222
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`[]`);
223
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
224
+ [
225
+ [
226
+ "Unable to get mesh ID. Please check the details and try again. RequestId: dummy_request_id",
227
+ ],
228
+ ]
229
+ `);
230
+ });
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
+
262
+ test('should fail if update file path is missing', async () => {
263
+ parseSpy.mockResolvedValueOnce({
264
+ args: { file: null },
265
+ flags: {
266
+ ignoreCache: mockIgnoreCacheFlag,
267
+ autoConfirmAction: mockAutoApproveAction,
268
+ },
269
+ });
270
+ const runResult = UpdateCommand.run();
271
+
272
+ await expect(runResult).rejects.toEqual(
273
+ new Error('Missing required args. Run aio api-mesh update --help for more info.'),
274
+ );
275
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`[]`);
276
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
277
+ [
278
+ [
279
+ "Missing required args. Run aio api-mesh update --help for more info.",
280
+ ],
281
+ ]
282
+ `);
283
+ });
284
+
285
+ test('should fail if dummy file path is provided', async () => {
286
+ readFile.mockRejectedValueOnce(new Error('File not found'));
287
+ const runResult = UpdateCommand.run();
288
+
289
+ await expect(runResult).rejects.toEqual(
290
+ new Error(
291
+ 'Unable to read the mesh configuration file provided. Please check the file and try again.',
292
+ ),
293
+ );
294
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
295
+ [
296
+ [
297
+ "File not found",
298
+ ],
299
+ ]
300
+ `);
301
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
302
+ [
303
+ [
304
+ "Unable to read the mesh configuration file provided. Please check the file and try again.",
305
+ ],
306
+ ]
307
+ `);
308
+ });
309
+
310
+ test('should not update if user prompt returns false', async () => {
311
+ promptConfirm.mockResolvedValueOnce(false);
312
+
313
+ const runResult = await UpdateCommand.run();
314
+
315
+ expect(runResult).toMatchInlineSnapshot(`"Update cancelled"`);
316
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
317
+ [
318
+ [
319
+ "Update cancelled",
320
+ ],
321
+ ]
322
+ `);
323
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
324
+ });
325
325
  });