@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.
@@ -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', () => {
@@ -93,15 +105,15 @@ describe('create command tests', () => {
93
105
  `"Create a mesh with the given config."`,
94
106
  );
95
107
  expect(CreateCommand.args).toMatchInlineSnapshot(`
96
- Array [
97
- Object {
108
+ [
109
+ {
98
110
  "name": "file",
99
111
  },
100
112
  ]
101
113
  `);
102
114
  expect(CreateCommand.flags).toMatchInlineSnapshot(`
103
- Object {
104
- "autoConfirmAction": Object {
115
+ {
116
+ "autoConfirmAction": {
105
117
  "allowNo": false,
106
118
  "char": "c",
107
119
  "default": false,
@@ -109,7 +121,7 @@ describe('create command tests', () => {
109
121
  "parse": [Function],
110
122
  "type": "boolean",
111
123
  },
112
- "ignoreCache": Object {
124
+ "ignoreCache": {
113
125
  "allowNo": false,
114
126
  "char": "i",
115
127
  "default": false,
@@ -117,7 +129,7 @@ describe('create command tests', () => {
117
129
  "parse": [Function],
118
130
  "type": "boolean",
119
131
  },
120
- "json": Object {
132
+ "json": {
121
133
  "allowNo": false,
122
134
  "default": false,
123
135
  "description": "Output JSON",
@@ -126,7 +138,132 @@ describe('create command tests', () => {
126
138
  },
127
139
  }
128
140
  `);
129
- expect(CreateCommand.aliases).toMatchInlineSnapshot(`Array []`);
141
+ expect(CreateCommand.aliases).toMatchInlineSnapshot(`[]`);
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(`[]`);
130
267
  });
131
268
 
132
269
  test('should fail if mesh config file arg is missing', async () => {
@@ -142,10 +279,10 @@ describe('create command tests', () => {
142
279
  await expect(runResult).rejects.toEqual(
143
280
  new Error('Missing file path. Run aio api-mesh create --help for more info.'),
144
281
  );
145
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
282
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`[]`);
146
283
  expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
147
- Array [
148
- Array [
284
+ [
285
+ [
149
286
  "Missing file path. Run aio api-mesh create --help for more info.",
150
287
  ],
151
288
  ]
@@ -168,49 +305,23 @@ describe('create command tests', () => {
168
305
  ),
169
306
  );
170
307
  expect(logSpy.mock.calls).toMatchInlineSnapshot(`
171
- Array [
172
- Array [
308
+ [
309
+ [
173
310
  "ENOENT: no such file or directory, open 'dummy_file_path'",
174
311
  ],
175
312
  ]
176
313
  `);
177
314
  expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
178
- Array [
179
- Array [
315
+ [
316
+ [
180
317
  "Unable to read the mesh configuration file provided. Please check the file and try again.",
181
318
  ],
182
319
  ]
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
- Array [
198
- Array [
199
- "create mesh api failed",
200
- ],
201
- ]
202
- `);
203
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
204
- Array [
205
- Array [
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
 
@@ -220,36 +331,31 @@ describe('create command tests', () => {
220
331
  ),
221
332
  );
222
333
  expect(logSpy.mock.calls).toMatchInlineSnapshot(`
223
- Array [
224
- Array [
225
- "Successfully created mesh %s",
334
+ [
335
+ [
336
+ "******************************************************************************************************",
337
+ ],
338
+ [
339
+ "Your mesh is being provisioned. Wait a few minutes before checking the status of your mesh %s",
226
340
  "dummy_mesh_id",
227
341
  ],
228
- Array [
229
- "{
230
- \\"meshId\\": \\"dummy_mesh_id\\",
231
- \\"meshConfig\\": {
232
- \\"sources\\": [
233
- {
234
- \\"name\\": \\"<api_name>\\",
235
- \\"handler\\": {
236
- \\"graphql\\": {
237
- \\"endpoint\\": \\"<gql_endpoint>\\"
238
- }
239
- }
240
- }
241
- ]
242
- }
243
- }",
244
- ],
245
- Array [
342
+ [
343
+ "To check the status of your mesh, run:",
344
+ ],
345
+ [
346
+ "aio api-mesh:status",
347
+ ],
348
+ [
349
+ "******************************************************************************************************",
350
+ ],
351
+ [
246
352
  "create api credential api failed",
247
353
  ],
248
354
  ]
249
355
  `);
250
356
  expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
251
- Array [
252
- Array [
357
+ [
358
+ [
253
359
  "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",
254
360
  ],
255
361
  ]
@@ -269,153 +375,41 @@ describe('create command tests', () => {
269
375
  ),
270
376
  );
271
377
  expect(logSpy.mock.calls).toMatchInlineSnapshot(`
272
- Array [
273
- Array [
274
- "Successfully created mesh %s",
378
+ [
379
+ [
380
+ "******************************************************************************************************",
381
+ ],
382
+ [
383
+ "Your mesh is being provisioned. Wait a few minutes before checking the status of your mesh %s",
275
384
  "dummy_mesh_id",
276
385
  ],
277
- Array [
278
- "{
279
- \\"meshId\\": \\"dummy_mesh_id\\",
280
- \\"meshConfig\\": {
281
- \\"sources\\": [
282
- {
283
- \\"name\\": \\"<api_name>\\",
284
- \\"handler\\": {
285
- \\"graphql\\": {
286
- \\"endpoint\\": \\"<gql_endpoint>\\"
287
- }
288
- }
289
- }
290
- ]
291
- }
292
- }",
293
- ],
294
- Array [
386
+ [
387
+ "To check the status of your mesh, run:",
388
+ ],
389
+ [
390
+ "aio api-mesh:status",
391
+ ],
392
+ [
393
+ "******************************************************************************************************",
394
+ ],
395
+ [
295
396
  "Successfully created API Key %s",
296
397
  "dummy_api_key",
297
398
  ],
298
- Array [
399
+ [
299
400
  "subscribe credential to mesh service api failed",
300
401
  ],
301
402
  ]
302
403
  `);
303
404
  expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
304
- Array [
305
- Array [
405
+ [
406
+ [
306
407
  "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",
307
408
  ],
308
409
  ]
309
410
  `);
310
411
  });
311
412
 
312
- test('should create if a valid mesh config file is provided', async () => {
313
- const runResult = await CreateCommand.run();
314
-
315
- expect(initRequestId).toHaveBeenCalled();
316
- expect(createMesh.mock.calls[0]).toMatchInlineSnapshot(`
317
- Array [
318
- "1234",
319
- "5678",
320
- "123456789",
321
- Object {
322
- "meshConfig": Object {
323
- "sources": Array [
324
- Object {
325
- "handler": Object {
326
- "graphql": Object {
327
- "endpoint": "<gql_endpoint>",
328
- },
329
- },
330
- "name": "<api_name>",
331
- },
332
- ],
333
- },
334
- },
335
- ]
336
- `);
337
- expect(createAPIMeshCredentials.mock.calls[0]).toMatchInlineSnapshot(`
338
- Array [
339
- "1234",
340
- "5678",
341
- "123456789",
342
- ]
343
- `);
344
- expect(subscribeCredentialToMeshService.mock.calls[0]).toMatchInlineSnapshot(`
345
- Array [
346
- "1234",
347
- "5678",
348
- "123456789",
349
- "dummy_id",
350
- ]
351
- `);
352
- expect(runResult).toMatchInlineSnapshot(`
353
- Object {
354
- "adobeIdIntegrationsForWorkspace": Object {
355
- "apiKey": "dummy_api_key",
356
- "id": "dummy_id",
357
- },
358
- "mesh": Object {
359
- "meshConfig": Object {
360
- "sources": Array [
361
- Object {
362
- "handler": Object {
363
- "graphql": Object {
364
- "endpoint": "<gql_endpoint>",
365
- },
366
- },
367
- "name": "<api_name>",
368
- },
369
- ],
370
- },
371
- "meshId": "dummy_mesh_id",
372
- },
373
- "sdkList": Array [
374
- "dummy_service",
375
- ],
376
- }
377
- `);
378
- expect(logSpy.mock.calls).toMatchInlineSnapshot(`
379
- Array [
380
- Array [
381
- "Successfully created mesh %s",
382
- "dummy_mesh_id",
383
- ],
384
- Array [
385
- "{
386
- \\"meshId\\": \\"dummy_mesh_id\\",
387
- \\"meshConfig\\": {
388
- \\"sources\\": [
389
- {
390
- \\"name\\": \\"<api_name>\\",
391
- \\"handler\\": {
392
- \\"graphql\\": {
393
- \\"endpoint\\": \\"<gql_endpoint>\\"
394
- }
395
- }
396
- }
397
- ]
398
- }
399
- }",
400
- ],
401
- Array [
402
- "Successfully created API Key %s",
403
- "dummy_api_key",
404
- ],
405
- Array [
406
- "Successfully subscribed API Key %s to API Mesh service",
407
- "dummy_api_key",
408
- ],
409
- Array [
410
- "Mesh Endpoint: %s
411
- ",
412
- "https://graph.adobe.io/api/dummy_mesh_id/graphql?api_key=dummy_api_key",
413
- ],
414
- ]
415
- `);
416
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
417
- });
418
-
419
413
  test('should not ask for confirmation if autoConfirmAction is provided', async () => {
420
414
  parseSpy.mockResolvedValueOnce({
421
415
  args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
@@ -433,44 +427,39 @@ describe('create command tests', () => {
433
427
  ignoreCache: true,
434
428
  });
435
429
  expect(logSpy.mock.calls).toMatchInlineSnapshot(`
436
- Array [
437
- Array [
438
- "Successfully created mesh %s",
430
+ [
431
+ [
432
+ "******************************************************************************************************",
433
+ ],
434
+ [
435
+ "Your mesh is being provisioned. Wait a few minutes before checking the status of your mesh %s",
439
436
  "dummy_mesh_id",
440
437
  ],
441
- Array [
442
- "{
443
- \\"meshId\\": \\"dummy_mesh_id\\",
444
- \\"meshConfig\\": {
445
- \\"sources\\": [
446
- {
447
- \\"name\\": \\"<api_name>\\",
448
- \\"handler\\": {
449
- \\"graphql\\": {
450
- \\"endpoint\\": \\"<gql_endpoint>\\"
451
- }
452
- }
453
- }
454
- ]
455
- }
456
- }",
457
- ],
458
- Array [
438
+ [
439
+ "To check the status of your mesh, run:",
440
+ ],
441
+ [
442
+ "aio api-mesh:status",
443
+ ],
444
+ [
445
+ "******************************************************************************************************",
446
+ ],
447
+ [
459
448
  "Successfully created API Key %s",
460
449
  "dummy_api_key",
461
450
  ],
462
- Array [
451
+ [
463
452
  "Successfully subscribed API Key %s to API Mesh service",
464
453
  "dummy_api_key",
465
454
  ],
466
- Array [
455
+ [
467
456
  "Mesh Endpoint: %s
468
457
  ",
469
458
  "https://graph.adobe.io/api/dummy_mesh_id/graphql?api_key=dummy_api_key",
470
459
  ],
471
460
  ]
472
461
  `);
473
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
462
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
474
463
  });
475
464
 
476
465
  test('should stop creation if user declines confirmation', async () => {
@@ -484,26 +473,12 @@ describe('create command tests', () => {
484
473
  ignoreCache: true,
485
474
  });
486
475
  expect(logSpy.mock.calls).toMatchInlineSnapshot(`
487
- Array [
488
- Array [
476
+ [
477
+ [
489
478
  "Create cancelled",
490
479
  ],
491
480
  ]
492
481
  `);
493
- expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
494
- });
495
-
496
- test('must return proper object structure used by adobe/generator-app-api-mesh', async () => {
497
- parseSpy.mockResolvedValueOnce({
498
- args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
499
- flags: {
500
- json: Promise.resolve(true)
501
- },
502
- });
503
- const output = await CreateCommand.run()
504
- expect(output).toHaveProperty('mesh')
505
- expect(output).toHaveProperty('adobeIdIntegrationsForWorkspace')
506
- expect(output.mesh).toEqual(expect.objectContaining({ meshId: 'dummy_mesh_id' }));
507
- expect(output.adobeIdIntegrationsForWorkspace).toEqual(expect.objectContaining({ apiKey: 'dummy_api_key' }));
482
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
508
483
  });
509
484
  });