@adobe/aio-cli-plugin-api-mesh 1.0.1-beta → 1.0.4-beta
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/README.md +30 -7
- package/oclif.manifest.json +1 -1
- package/package.json +3 -1
- package/src/commands/api-mesh/__tests__/create.test.js +445 -33
- package/src/commands/api-mesh/__tests__/delete.test.js +275 -38
- package/src/commands/api-mesh/__tests__/describe.test.js +249 -0
- package/src/commands/api-mesh/__tests__/get.test.js +299 -39
- package/src/commands/api-mesh/__tests__/update.test.js +251 -39
- package/src/commands/api-mesh/create.js +98 -18
- package/src/commands/api-mesh/delete.js +78 -14
- package/src/commands/api-mesh/describe.js +85 -0
- package/src/commands/api-mesh/get.js +48 -22
- package/src/commands/api-mesh/update.js +60 -15
- package/src/constants.js +21 -0
- package/src/helpers.js +190 -47
- package/src/lib/devConsole.js +746 -0
- package/src/utils.js +18 -1
- package/src/classes/SchemaServiceClient.js +0 -365
|
@@ -10,73 +10,310 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
jest.mock('axios');
|
|
13
14
|
jest.mock('@adobe/aio-lib-env');
|
|
15
|
+
jest.mock('@adobe/aio-lib-ims');
|
|
14
16
|
jest.mock('@adobe/aio-cli-lib-console');
|
|
17
|
+
jest.mock('@adobe/aio-cli-lib-console', () => ({
|
|
18
|
+
init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
|
|
19
|
+
cleanStdOut: jest.fn(),
|
|
20
|
+
}));
|
|
21
|
+
jest.mock('../../../helpers', () => ({
|
|
22
|
+
initSdk: jest.fn().mockResolvedValue({}),
|
|
23
|
+
initRequestId: jest.fn().mockResolvedValue({}),
|
|
24
|
+
promptConfirm: jest.fn().mockResolvedValue(true),
|
|
25
|
+
}));
|
|
26
|
+
jest.mock('../../../lib/devConsole');
|
|
15
27
|
|
|
16
28
|
const mockConsoleCLIInstance = {};
|
|
17
29
|
|
|
18
|
-
const orgs = [{ id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' }];
|
|
19
30
|
const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
|
|
20
31
|
|
|
21
|
-
const projects = [{ id: '5678', title: 'Project01' }];
|
|
22
32
|
const selectedProject = { id: '5678', title: 'Project01' };
|
|
23
33
|
|
|
24
|
-
const workspaces = [{ id: '123456789', title: 'Workspace01' }];
|
|
25
34
|
const selectedWorkspace = { id: '123456789', title: 'Workspace01' };
|
|
26
35
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
const DeleteCommand = require('../delete');
|
|
37
|
+
const { initSdk, initRequestId, promptConfirm } = require('../../../helpers');
|
|
38
|
+
const {
|
|
39
|
+
getMeshId,
|
|
40
|
+
deleteMesh,
|
|
41
|
+
getApiKeyCredential,
|
|
42
|
+
unsubscribeCredentialFromMeshService,
|
|
43
|
+
} = require('../../../lib/devConsole');
|
|
30
44
|
|
|
31
|
-
|
|
32
|
-
|
|
45
|
+
let logSpy = null;
|
|
46
|
+
let errorLogSpy = null;
|
|
33
47
|
|
|
34
|
-
|
|
35
|
-
mockConsoleCLIInstance.promptForSelectProject = jest.fn().mockResolvedValue(selectedProject);
|
|
48
|
+
let parseSpy = null;
|
|
36
49
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
jest.mock('@adobe/aio-cli-lib-console', () => ({
|
|
42
|
-
init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
|
|
43
|
-
cleanStdOut: jest.fn(),
|
|
44
|
-
}));
|
|
45
|
-
jest.mock('@adobe/aio-lib-ims');
|
|
46
|
-
|
|
47
|
-
const DeleteCommand = require('../delete');
|
|
48
|
-
const { SchemaServiceClient } = require('../../../classes/SchemaServiceClient');
|
|
50
|
+
const mockIgnoreCacheFlag = Promise.resolve(true);
|
|
51
|
+
const mockAutoApproveAction = Promise.resolve(false);
|
|
49
52
|
|
|
50
53
|
describe('delete command tests', () => {
|
|
51
54
|
beforeEach(() => {
|
|
52
|
-
|
|
55
|
+
initSdk.mockResolvedValue({
|
|
56
|
+
imsOrgId: selectedOrg.id,
|
|
57
|
+
projectId: selectedProject.id,
|
|
58
|
+
workspaceId: selectedWorkspace.id,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
global.requestId = 'dummy_request_id';
|
|
62
|
+
|
|
63
|
+
logSpy = jest.spyOn(DeleteCommand.prototype, 'log');
|
|
64
|
+
errorLogSpy = jest.spyOn(DeleteCommand.prototype, 'error');
|
|
65
|
+
|
|
66
|
+
getMeshId.mockResolvedValue('mesh_id');
|
|
67
|
+
deleteMesh.mockResolvedValue({ status: 'success' });
|
|
68
|
+
getApiKeyCredential.mockResolvedValue({
|
|
69
|
+
id_integration: 'dummy_integration_id',
|
|
70
|
+
client_id: 'dummy_client_id',
|
|
71
|
+
});
|
|
72
|
+
unsubscribeCredentialFromMeshService.mockResolvedValue(['dummy_service']);
|
|
73
|
+
|
|
74
|
+
parseSpy = jest.spyOn(DeleteCommand.prototype, 'parse');
|
|
75
|
+
parseSpy.mockResolvedValue({
|
|
76
|
+
args: {},
|
|
77
|
+
flags: {
|
|
78
|
+
ignoreCache: mockIgnoreCacheFlag,
|
|
79
|
+
autoConfirmAction: mockAutoApproveAction,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
53
82
|
});
|
|
54
83
|
|
|
55
84
|
afterEach(() => {
|
|
56
85
|
jest.restoreAllMocks();
|
|
57
86
|
});
|
|
58
87
|
|
|
59
|
-
test('delete
|
|
60
|
-
|
|
88
|
+
test('snapshot delete command description', () => {
|
|
89
|
+
expect(DeleteCommand.description).toMatchInlineSnapshot(`"Delete the config of a given mesh"`);
|
|
90
|
+
expect(DeleteCommand.args).toMatchInlineSnapshot(`undefined`);
|
|
91
|
+
expect(DeleteCommand.flags).toMatchInlineSnapshot(`
|
|
92
|
+
Object {
|
|
93
|
+
"autoConfirmAction": Object {
|
|
94
|
+
"allowNo": false,
|
|
95
|
+
"char": "c",
|
|
96
|
+
"default": false,
|
|
97
|
+
"description": "Auto confirm action prompt. CLI will not check for user approval before executing the action.",
|
|
98
|
+
"parse": [Function],
|
|
99
|
+
"type": "boolean",
|
|
100
|
+
},
|
|
101
|
+
"ignoreCache": Object {
|
|
102
|
+
"allowNo": false,
|
|
103
|
+
"char": "i",
|
|
104
|
+
"default": false,
|
|
105
|
+
"description": "Ignore cache and force manual org -> project -> workspace selection",
|
|
106
|
+
"parse": [Function],
|
|
107
|
+
"type": "boolean",
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
`);
|
|
111
|
+
expect(DeleteCommand.aliases).toMatchInlineSnapshot(`Array []`);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('should fail if mesh id is missing', async () => {
|
|
115
|
+
getMeshId.mockResolvedValue(null);
|
|
116
|
+
const runResult = DeleteCommand.run();
|
|
61
117
|
|
|
62
118
|
return runResult.catch(err => {
|
|
63
|
-
expect(err).
|
|
64
|
-
|
|
65
|
-
expect.stringMatching(
|
|
66
|
-
/^Unable to delete mesh\. Please check the details and try again\. If the error persists please contact support\. RequestId: [a-z A-Z 0-9 -_]+/,
|
|
67
|
-
),
|
|
119
|
+
expect(err.message).toMatchInlineSnapshot(
|
|
120
|
+
`"Unable to delete. No mesh found for Org(1234) -> Project(5678) -> Workspace(123456789). Please check the details and try again."`,
|
|
68
121
|
);
|
|
122
|
+
expect(logSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
|
|
123
|
+
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
|
|
124
|
+
Array [
|
|
125
|
+
Array [
|
|
126
|
+
"Unable to delete. No mesh found for Org(1234) -> Project(5678) -> Workspace(123456789). Please check the details and try again.",
|
|
127
|
+
],
|
|
128
|
+
]
|
|
129
|
+
`);
|
|
69
130
|
});
|
|
70
131
|
});
|
|
71
132
|
|
|
72
|
-
test('delete
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
133
|
+
test('should not delete if user prompt returns false', async () => {
|
|
134
|
+
promptConfirm.mockResolvedValueOnce(false);
|
|
135
|
+
|
|
136
|
+
const runResult = await DeleteCommand.run();
|
|
137
|
+
|
|
138
|
+
expect(runResult).toBe('Delete cancelled');
|
|
139
|
+
expect(logSpy.mock.calls).toMatchInlineSnapshot(`
|
|
140
|
+
Array [
|
|
141
|
+
Array [
|
|
142
|
+
"Delete cancelled",
|
|
143
|
+
],
|
|
144
|
+
]
|
|
145
|
+
`);
|
|
146
|
+
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('should not ask for prompt if autoConfirmAction is set', async () => {
|
|
150
|
+
parseSpy.mockResolvedValue({
|
|
151
|
+
args: {},
|
|
152
|
+
flags: {
|
|
153
|
+
ignoreCache: mockIgnoreCacheFlag,
|
|
154
|
+
autoConfirmAction: Promise.resolve(true),
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const runResult = await DeleteCommand.run();
|
|
159
|
+
|
|
160
|
+
expect(runResult).toMatchInlineSnapshot(`
|
|
161
|
+
Object {
|
|
162
|
+
"status": "success",
|
|
163
|
+
}
|
|
164
|
+
`);
|
|
165
|
+
expect(promptConfirm).not.toHaveBeenCalled();
|
|
166
|
+
expect(logSpy.mock.calls).toMatchInlineSnapshot(`
|
|
167
|
+
Array [
|
|
168
|
+
Array [
|
|
169
|
+
"Successfully deleted mesh %s",
|
|
170
|
+
"mesh_id",
|
|
171
|
+
],
|
|
172
|
+
Array [
|
|
173
|
+
"Successfully unsubscribed API Key %s",
|
|
174
|
+
"dummy_client_id",
|
|
175
|
+
],
|
|
176
|
+
]
|
|
177
|
+
`);
|
|
178
|
+
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('should fail if mesh delete fails', async () => {
|
|
182
|
+
deleteMesh.mockRejectedValueOnce(new Error('mesh delete failed'));
|
|
183
|
+
|
|
184
|
+
const runResult = DeleteCommand.run();
|
|
185
|
+
|
|
186
|
+
await expect(runResult).rejects.toEqual(
|
|
187
|
+
new Error(
|
|
188
|
+
'Unable to delete mesh. Please check the details and try again. If the error persists please contact support. RequestId: dummy_request_id',
|
|
189
|
+
),
|
|
190
|
+
);
|
|
191
|
+
expect(logSpy.mock.calls).toMatchInlineSnapshot(`
|
|
192
|
+
Array [
|
|
193
|
+
Array [
|
|
194
|
+
"mesh delete failed",
|
|
195
|
+
],
|
|
196
|
+
]
|
|
197
|
+
`);
|
|
198
|
+
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
|
|
199
|
+
Array [
|
|
200
|
+
Array [
|
|
201
|
+
"Unable to delete mesh. Please check the details and try again. If the error persists please contact support. RequestId: dummy_request_id",
|
|
202
|
+
],
|
|
203
|
+
]
|
|
204
|
+
`);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test('should delete mesh but fail to unsubscribe if unable to get api key', async () => {
|
|
208
|
+
getApiKeyCredential.mockRejectedValueOnce(new Error('unable to get api key'));
|
|
209
|
+
|
|
210
|
+
const runResult = DeleteCommand.run();
|
|
211
|
+
|
|
212
|
+
await expect(runResult).rejects.toEqual(
|
|
213
|
+
new Error(
|
|
214
|
+
'Unable to delete mesh. Please check the details and try again. If the error persists please contact support. RequestId: dummy_request_id',
|
|
215
|
+
),
|
|
216
|
+
);
|
|
217
|
+
expect(logSpy.mock.calls).toMatchInlineSnapshot(`
|
|
218
|
+
Array [
|
|
219
|
+
Array [
|
|
220
|
+
"Successfully deleted mesh %s",
|
|
221
|
+
"mesh_id",
|
|
222
|
+
],
|
|
223
|
+
Array [
|
|
224
|
+
"unable to get api key",
|
|
225
|
+
],
|
|
226
|
+
]
|
|
227
|
+
`);
|
|
228
|
+
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
|
|
229
|
+
Array [
|
|
230
|
+
Array [
|
|
231
|
+
"Unable to delete mesh. Please check the details and try again. If the error persists please contact support. RequestId: dummy_request_id",
|
|
232
|
+
],
|
|
233
|
+
]
|
|
234
|
+
`);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('should delete mesh but fail to unsubscribe if unsubscribe api failed', async () => {
|
|
238
|
+
unsubscribeCredentialFromMeshService.mockRejectedValueOnce(new Error('unsubscribe api failed'));
|
|
239
|
+
|
|
240
|
+
const runResult = DeleteCommand.run();
|
|
241
|
+
|
|
242
|
+
await expect(runResult).rejects.toEqual(
|
|
243
|
+
new Error(
|
|
244
|
+
'Unable to delete mesh. Please check the details and try again. If the error persists please contact support. RequestId: dummy_request_id',
|
|
245
|
+
),
|
|
246
|
+
);
|
|
247
|
+
expect(logSpy.mock.calls).toMatchInlineSnapshot(`
|
|
248
|
+
Array [
|
|
249
|
+
Array [
|
|
250
|
+
"Successfully deleted mesh %s",
|
|
251
|
+
"mesh_id",
|
|
252
|
+
],
|
|
253
|
+
Array [
|
|
254
|
+
"unsubscribe api failed",
|
|
255
|
+
],
|
|
256
|
+
]
|
|
257
|
+
`);
|
|
258
|
+
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
|
|
259
|
+
Array [
|
|
260
|
+
Array [
|
|
261
|
+
"Unable to delete mesh. Please check the details and try again. If the error persists please contact support. RequestId: dummy_request_id",
|
|
262
|
+
],
|
|
263
|
+
]
|
|
264
|
+
`);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test('should delete mesh and unsubscribe if correct args are provided', async () => {
|
|
268
|
+
const runResult = await DeleteCommand.run();
|
|
79
269
|
|
|
80
|
-
|
|
270
|
+
expect(initRequestId).toHaveBeenCalled();
|
|
271
|
+
expect(runResult).toMatchInlineSnapshot(`
|
|
272
|
+
Object {
|
|
273
|
+
"status": "success",
|
|
274
|
+
}
|
|
275
|
+
`);
|
|
276
|
+
expect(deleteMesh.mock.calls).toMatchInlineSnapshot(`
|
|
277
|
+
Array [
|
|
278
|
+
Array [
|
|
279
|
+
"1234",
|
|
280
|
+
"5678",
|
|
281
|
+
"123456789",
|
|
282
|
+
"mesh_id",
|
|
283
|
+
],
|
|
284
|
+
]
|
|
285
|
+
`);
|
|
286
|
+
expect(getApiKeyCredential.mock.calls).toMatchInlineSnapshot(`
|
|
287
|
+
Array [
|
|
288
|
+
Array [
|
|
289
|
+
"1234",
|
|
290
|
+
"5678",
|
|
291
|
+
"123456789",
|
|
292
|
+
],
|
|
293
|
+
]
|
|
294
|
+
`);
|
|
295
|
+
expect(unsubscribeCredentialFromMeshService.mock.calls).toMatchInlineSnapshot(`
|
|
296
|
+
Array [
|
|
297
|
+
Array [
|
|
298
|
+
"1234",
|
|
299
|
+
"5678",
|
|
300
|
+
"123456789",
|
|
301
|
+
"dummy_integration_id",
|
|
302
|
+
],
|
|
303
|
+
]
|
|
304
|
+
`);
|
|
305
|
+
expect(logSpy.mock.calls).toMatchInlineSnapshot(`
|
|
306
|
+
Array [
|
|
307
|
+
Array [
|
|
308
|
+
"Successfully deleted mesh %s",
|
|
309
|
+
"mesh_id",
|
|
310
|
+
],
|
|
311
|
+
Array [
|
|
312
|
+
"Successfully unsubscribed API Key %s",
|
|
313
|
+
"dummy_client_id",
|
|
314
|
+
],
|
|
315
|
+
]
|
|
316
|
+
`);
|
|
317
|
+
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
|
|
81
318
|
});
|
|
82
319
|
});
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2021 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const mockConsoleCLIInstance = {};
|
|
14
|
+
|
|
15
|
+
jest.mock('axios');
|
|
16
|
+
jest.mock('@adobe/aio-lib-env');
|
|
17
|
+
jest.mock('@adobe/aio-cli-lib-console');
|
|
18
|
+
jest.mock('@adobe/aio-lib-ims');
|
|
19
|
+
jest.mock('../../../helpers', () => ({
|
|
20
|
+
initSdk: jest.fn().mockResolvedValue({}),
|
|
21
|
+
initRequestId: jest.fn().mockResolvedValue({}),
|
|
22
|
+
}));
|
|
23
|
+
jest.mock('@adobe/aio-cli-lib-console', () => ({
|
|
24
|
+
init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
|
|
25
|
+
cleanStdOut: jest.fn(),
|
|
26
|
+
}));
|
|
27
|
+
jest.mock('../../../lib/devConsole');
|
|
28
|
+
|
|
29
|
+
const DescribeCommand = require('../describe');
|
|
30
|
+
const { initSdk, initRequestId } = require('../../../helpers');
|
|
31
|
+
const { describeMesh } = require('../../../lib/devConsole');
|
|
32
|
+
|
|
33
|
+
const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
|
|
34
|
+
const selectedProject = { id: '5678', title: 'Project01' };
|
|
35
|
+
const selectedWorkspace = { id: '123456789', title: 'Workspace01' };
|
|
36
|
+
|
|
37
|
+
let logSpy = null;
|
|
38
|
+
let errorLogSpy = null;
|
|
39
|
+
let parseSpy = null;
|
|
40
|
+
|
|
41
|
+
const mockIgnoreCacheFlag = jest.fn().mockResolvedValue(true);
|
|
42
|
+
|
|
43
|
+
describe('describe command tests', () => {
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
describeMesh.mockResolvedValue({
|
|
46
|
+
meshId: 'dummy_meshId',
|
|
47
|
+
apiKey: 'dummy_apiKey',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
initSdk.mockResolvedValue({
|
|
51
|
+
imsOrgId: selectedOrg.id,
|
|
52
|
+
projectId: selectedProject.id,
|
|
53
|
+
workspaceId: selectedWorkspace.id,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
global.requestId = 'dummy_request_id';
|
|
57
|
+
|
|
58
|
+
logSpy = jest.spyOn(DescribeCommand.prototype, 'log');
|
|
59
|
+
errorLogSpy = jest.spyOn(DescribeCommand.prototype, 'error');
|
|
60
|
+
|
|
61
|
+
parseSpy = jest.spyOn(DescribeCommand.prototype, 'parse');
|
|
62
|
+
parseSpy.mockResolvedValue({
|
|
63
|
+
flags: {
|
|
64
|
+
ignoreCache: mockIgnoreCacheFlag,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
afterEach(() => {
|
|
70
|
+
jest.restoreAllMocks();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('snapshot describe command description', () => {
|
|
74
|
+
expect(DescribeCommand.description).toMatchInlineSnapshot(`"Get details of a mesh"`);
|
|
75
|
+
expect(DescribeCommand.args).toMatchInlineSnapshot(`undefined`);
|
|
76
|
+
expect(DescribeCommand.flags).toMatchInlineSnapshot(`
|
|
77
|
+
Object {
|
|
78
|
+
"ignoreCache": Object {
|
|
79
|
+
"allowNo": false,
|
|
80
|
+
"char": "i",
|
|
81
|
+
"default": false,
|
|
82
|
+
"description": "Ignore cache and force manual org -> project -> workspace selection",
|
|
83
|
+
"parse": [Function],
|
|
84
|
+
"type": "boolean",
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
`);
|
|
88
|
+
expect(DescribeCommand.aliases).toMatchInlineSnapshot(`Array []`);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('should error if describe api has failed', async () => {
|
|
92
|
+
describeMesh.mockRejectedValueOnce(new Error('describe api failed'));
|
|
93
|
+
|
|
94
|
+
const runResult = DescribeCommand.run();
|
|
95
|
+
|
|
96
|
+
await expect(runResult).rejects.toEqual(
|
|
97
|
+
new Error(
|
|
98
|
+
'Unable to get mesh details. Please check the details and try again. If the error persists please contact support. RequestId: dummy_request_id',
|
|
99
|
+
),
|
|
100
|
+
);
|
|
101
|
+
expect(logSpy.mock.calls).toMatchInlineSnapshot(`
|
|
102
|
+
Array [
|
|
103
|
+
Array [
|
|
104
|
+
"describe api failed",
|
|
105
|
+
],
|
|
106
|
+
]
|
|
107
|
+
`);
|
|
108
|
+
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
|
|
109
|
+
Array [
|
|
110
|
+
Array [
|
|
111
|
+
"Unable to get mesh details. Please check the details and try again. If the error persists please contact support. RequestId: dummy_request_id",
|
|
112
|
+
],
|
|
113
|
+
]
|
|
114
|
+
`);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('should error if mesh details is missing from describe api response', async () => {
|
|
118
|
+
describeMesh.mockResolvedValueOnce(null);
|
|
119
|
+
|
|
120
|
+
const runResult = DescribeCommand.run();
|
|
121
|
+
|
|
122
|
+
await expect(runResult).rejects.toEqual(
|
|
123
|
+
new Error(
|
|
124
|
+
'Unable to get mesh details. Please check the details and try again. If the error persists please contact support. RequestId: dummy_request_id',
|
|
125
|
+
),
|
|
126
|
+
);
|
|
127
|
+
expect(logSpy.mock.calls).toMatchInlineSnapshot(`
|
|
128
|
+
Array [
|
|
129
|
+
Array [
|
|
130
|
+
"Unable to get mesh details",
|
|
131
|
+
],
|
|
132
|
+
]
|
|
133
|
+
`);
|
|
134
|
+
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
|
|
135
|
+
Array [
|
|
136
|
+
Array [
|
|
137
|
+
"Unable to get mesh details. Please check the details and try again. If the error persists please contact support. RequestId: dummy_request_id",
|
|
138
|
+
],
|
|
139
|
+
]
|
|
140
|
+
`);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('should error if mesh id is missing from describe api response', async () => {
|
|
144
|
+
describeMesh.mockResolvedValueOnce({});
|
|
145
|
+
|
|
146
|
+
const runResult = await DescribeCommand.run();
|
|
147
|
+
|
|
148
|
+
expect(runResult).toBe(undefined);
|
|
149
|
+
expect(logSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
|
|
150
|
+
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
|
|
151
|
+
Array [
|
|
152
|
+
Array [
|
|
153
|
+
"Unable to get mesh details. Please check the details and try again. RequestId: dummy_request_id",
|
|
154
|
+
Object {
|
|
155
|
+
"exit": false,
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
]
|
|
159
|
+
`);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('should not fail if api key is missing from mesh details', async () => {
|
|
163
|
+
describeMesh.mockResolvedValueOnce({ meshId: 'dummy_meshId' });
|
|
164
|
+
|
|
165
|
+
const runResult = await DescribeCommand.run();
|
|
166
|
+
|
|
167
|
+
expect(runResult).toMatchInlineSnapshot(`
|
|
168
|
+
Object {
|
|
169
|
+
"meshId": "dummy_meshId",
|
|
170
|
+
}
|
|
171
|
+
`);
|
|
172
|
+
expect(logSpy.mock.calls).toMatchInlineSnapshot(`
|
|
173
|
+
Array [
|
|
174
|
+
Array [
|
|
175
|
+
"Successfully retrieved mesh details
|
|
176
|
+
",
|
|
177
|
+
],
|
|
178
|
+
Array [
|
|
179
|
+
"Org ID: %s",
|
|
180
|
+
"1234",
|
|
181
|
+
],
|
|
182
|
+
Array [
|
|
183
|
+
"Project ID: %s",
|
|
184
|
+
"5678",
|
|
185
|
+
],
|
|
186
|
+
Array [
|
|
187
|
+
"Workspace ID: %s",
|
|
188
|
+
"123456789",
|
|
189
|
+
],
|
|
190
|
+
Array [
|
|
191
|
+
"Mesh ID: %s",
|
|
192
|
+
"dummy_meshId",
|
|
193
|
+
],
|
|
194
|
+
]
|
|
195
|
+
`);
|
|
196
|
+
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('should succeed if valid details are provided', async () => {
|
|
200
|
+
const runResult = await DescribeCommand.run();
|
|
201
|
+
|
|
202
|
+
expect(initRequestId).toHaveBeenCalled();
|
|
203
|
+
expect(describeMesh).toHaveBeenCalledWith(
|
|
204
|
+
selectedOrg.id,
|
|
205
|
+
selectedProject.id,
|
|
206
|
+
selectedWorkspace.id,
|
|
207
|
+
);
|
|
208
|
+
expect(runResult).toMatchInlineSnapshot(`
|
|
209
|
+
Object {
|
|
210
|
+
"apiKey": "dummy_apiKey",
|
|
211
|
+
"meshId": "dummy_meshId",
|
|
212
|
+
}
|
|
213
|
+
`);
|
|
214
|
+
expect(logSpy.mock.calls).toMatchInlineSnapshot(`
|
|
215
|
+
Array [
|
|
216
|
+
Array [
|
|
217
|
+
"Successfully retrieved mesh details
|
|
218
|
+
",
|
|
219
|
+
],
|
|
220
|
+
Array [
|
|
221
|
+
"Org ID: %s",
|
|
222
|
+
"1234",
|
|
223
|
+
],
|
|
224
|
+
Array [
|
|
225
|
+
"Project ID: %s",
|
|
226
|
+
"5678",
|
|
227
|
+
],
|
|
228
|
+
Array [
|
|
229
|
+
"Workspace ID: %s",
|
|
230
|
+
"123456789",
|
|
231
|
+
],
|
|
232
|
+
Array [
|
|
233
|
+
"Mesh ID: %s",
|
|
234
|
+
"dummy_meshId",
|
|
235
|
+
],
|
|
236
|
+
Array [
|
|
237
|
+
"API Key: %s",
|
|
238
|
+
"dummy_apiKey",
|
|
239
|
+
],
|
|
240
|
+
Array [
|
|
241
|
+
"Mesh Endpoint: %s
|
|
242
|
+
",
|
|
243
|
+
"https://graph.adobe.io/api/dummy_meshId/graphql?api_key=dummy_apiKey",
|
|
244
|
+
],
|
|
245
|
+
]
|
|
246
|
+
`);
|
|
247
|
+
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
|
|
248
|
+
});
|
|
249
|
+
});
|