@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.
@@ -10,67 +10,327 @@ 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
- const mockConsoleCLIInstance = {};
13
+ jest.mock('axios');
14
14
  jest.mock('@adobe/aio-lib-env');
15
15
  jest.mock('@adobe/aio-cli-lib-console');
16
- const orgs = [{ id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' }];
17
- const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
16
+ jest.mock('fs/promises');
17
+ jest.mock('@adobe/aio-cli-lib-console', () => ({
18
+ init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
19
+ cleanStdOut: jest.fn(),
20
+ }));
21
+ jest.mock('@adobe/aio-lib-ims');
22
+ jest.mock('../../../helpers', () => ({
23
+ initSdk: jest.fn().mockResolvedValue({}),
24
+ initRequestId: jest.fn().mockResolvedValue({}),
25
+ }));
26
+ jest.mock('../../../lib/devConsole');
18
27
 
19
- const projects = [{ id: '5678', title: 'Project01' }];
28
+ const mockConsoleCLIInstance = {};
29
+ const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
20
30
  const selectedProject = { id: '5678', title: 'Project01' };
21
-
22
- const workspaces = [{ id: '123456789', title: 'Workspace01' }];
23
31
  const selectedWorkspace = { id: '123456789', title: 'Workspace01' };
24
32
 
25
- function setDefaultMockConsoleCLI() {
26
- mockConsoleCLIInstance.getToken = jest.fn().mockReturnValue('test_token');
27
- mockConsoleCLIInstance.getCliEnv = jest.fn().mockReturnValue('prod');
33
+ const { writeFile } = require('fs/promises');
34
+ const { initSdk, initRequestId } = require('../../../helpers');
35
+ const GetCommand = require('../get');
36
+ const mockGetMeshConfig = require('../../__fixtures__/sample_mesh.json');
37
+ const { getMeshId, getMesh } = require('../../../lib/devConsole');
28
38
 
29
- mockConsoleCLIInstance.getOrganizations = jest.fn().mockResolvedValue(orgs);
30
- mockConsoleCLIInstance.promptForSelectOrganization = jest.fn().mockResolvedValue(selectedOrg);
39
+ let logSpy = null;
40
+ let errorLogSpy = null;
31
41
 
32
- mockConsoleCLIInstance.getProjects = jest.fn().mockResolvedValue(projects);
33
- mockConsoleCLIInstance.promptForSelectProject = jest.fn().mockResolvedValue(selectedProject);
42
+ let parseSpy = null;
34
43
 
35
- mockConsoleCLIInstance.getWorkspaces = jest.fn().mockResolvedValue(workspaces);
36
- mockConsoleCLIInstance.promptForSelectWorkspace = jest.fn().mockResolvedValue(selectedWorkspace);
37
- }
38
-
39
- jest.mock('@adobe/aio-cli-lib-console', () => ({
40
- init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
41
- cleanStdOut: jest.fn(),
42
- }));
43
- jest.mock('@adobe/aio-lib-ims');
44
- const GetCommand = require('../get');
45
- const { SchemaServiceClient } = require('../../../classes/SchemaServiceClient');
46
- const mockGetMesh = require('../../__fixtures__/sample_mesh.json');
44
+ const mockIgnoreCacheFlag = Promise.resolve(true);
47
45
 
48
46
  describe('get command tests', () => {
49
47
  beforeEach(() => {
50
- setDefaultMockConsoleCLI();
48
+ initSdk.mockResolvedValue({
49
+ imsOrgId: selectedOrg.id,
50
+ projectId: selectedProject.id,
51
+ workspaceId: selectedWorkspace.id,
52
+ });
53
+
54
+ global.requestId = 'dummy_request_id';
55
+
56
+ logSpy = jest.spyOn(GetCommand.prototype, 'log');
57
+ errorLogSpy = jest.spyOn(GetCommand.prototype, 'error');
58
+
59
+ writeFile.mockResolvedValue(true);
60
+
61
+ getMeshId.mockResolvedValue('dummy_meshId');
62
+ getMesh.mockResolvedValue({
63
+ meshId: 'dummy_meshId',
64
+ mesh: mockGetMeshConfig,
65
+ });
66
+
67
+ parseSpy = jest.spyOn(GetCommand.prototype, 'parse');
68
+ parseSpy.mockResolvedValue({
69
+ args: { file: 'mesh.json' },
70
+ flags: {
71
+ ignoreCache: mockIgnoreCacheFlag,
72
+ },
73
+ });
51
74
  });
75
+
52
76
  afterEach(() => {
53
77
  jest.restoreAllMocks();
54
78
  });
55
79
 
56
- test('get-mesh-missing-meshId', async () => {
57
- const runResult = GetCommand.run([]);
80
+ test('snapshot get command', () => {
81
+ expect(GetCommand.description).toMatchInlineSnapshot(`"Get the config of a given mesh"`);
82
+ expect(GetCommand.args).toMatchInlineSnapshot(`
83
+ Array [
84
+ Object {
85
+ "name": "file",
86
+ },
87
+ ]
88
+ `);
89
+ expect(GetCommand.flags).toMatchInlineSnapshot(`
90
+ Object {
91
+ "ignoreCache": Object {
92
+ "allowNo": false,
93
+ "char": "i",
94
+ "default": false,
95
+ "description": "Ignore cache and force manual org -> project -> workspace selection",
96
+ "parse": [Function],
97
+ "type": "boolean",
98
+ },
99
+ }
100
+ `);
101
+ expect(GetCommand.aliases).toMatchInlineSnapshot(`Array []`);
102
+ });
103
+
104
+ test('should fail if mesh id is missing', async () => {
105
+ getMeshId.mockResolvedValue(null);
106
+ const runResult = GetCommand.run();
107
+
108
+ return runResult.catch(err => {
109
+ expect(err.message).toMatchInlineSnapshot(
110
+ `"Unable to get mesh config. No mesh found for Org(1234) -> Project(5678) -> Workspace(123456789). Please check the details and try again."`,
111
+ );
112
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
113
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
114
+ Array [
115
+ Array [
116
+ "Unable to get mesh config. No mesh found for Org(1234) -> Project(5678) -> Workspace(123456789). Please check the details and try again.",
117
+ ],
118
+ ]
119
+ `);
120
+ });
121
+ });
122
+
123
+ test('should fail if getMeshId failed', async () => {
124
+ getMeshId.mockRejectedValue(new Error('getMeshId failed'));
125
+ const runResult = GetCommand.run();
58
126
 
59
127
  return runResult.catch(err => {
60
- expect(err).toHaveProperty(
61
- 'message',
62
- expect.stringMatching(
63
- /^Unable to get mesh\. Please check the details and try again\. If the error persists please contact support\. RequestId: [a-z A-Z 0-9 -_]+/,
64
- ),
128
+ expect(err.message).toMatchInlineSnapshot(
129
+ `"Unable to get mesh ID. Please check the details and try again. RequestId: dummy_request_id"`,
65
130
  );
131
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
132
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
133
+ Array [
134
+ Array [
135
+ "Unable to get mesh ID. Please check the details and try again. RequestId: dummy_request_id",
136
+ ],
137
+ ]
138
+ `);
139
+ });
140
+ });
141
+
142
+ test('should fail if mesh id is not found', async () => {
143
+ getMesh.mockResolvedValueOnce(null);
144
+
145
+ const runResult = await GetCommand.run();
146
+
147
+ expect(runResult).toMatchInlineSnapshot(`undefined`);
148
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
149
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
150
+ Array [
151
+ Array [
152
+ "Unable to get mesh with the ID dummy_meshId. Please check the mesh ID and try again. RequestId: dummy_request_id",
153
+ Object {
154
+ "exit": false,
155
+ },
156
+ ],
157
+ ]
158
+ `);
159
+ });
160
+
161
+ test('should fail if get mesh method failed', async () => {
162
+ getMesh.mockRejectedValueOnce(new Error('get mesh failed'));
163
+
164
+ const runResult = GetCommand.run();
165
+
166
+ await expect(runResult).rejects.toEqual(
167
+ new Error(
168
+ 'Unable to get mesh. Please check the details and try again. If the error persists please contact support. RequestId: dummy_request_id',
169
+ ),
170
+ );
171
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
172
+ Array [
173
+ Array [
174
+ "get mesh failed",
175
+ ],
176
+ ]
177
+ `);
178
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
179
+ Array [
180
+ Array [
181
+ "Unable to get mesh. Please check the details and try again. If the error persists please contact support. RequestId: dummy_request_id",
182
+ ],
183
+ ]
184
+ `);
185
+ });
186
+
187
+ test('should pass if mesh id is valid', async () => {
188
+ const meshId = 'dummy_meshId';
189
+ getMeshId.mockResolvedValueOnce(meshId);
190
+ const runResult = await GetCommand.run();
191
+
192
+ expect(initSdk).toHaveBeenCalledWith({
193
+ ignoreCache: true,
194
+ });
195
+ expect(initRequestId).toHaveBeenCalled();
196
+ expect(runResult).toEqual({ meshId: 'dummy_meshId', mesh: mockGetMeshConfig });
197
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
198
+ Array [
199
+ Array [
200
+ "Successfully retrieved mesh %s",
201
+ "{
202
+ \\"meshId\\": \\"dummy_meshId\\",
203
+ \\"mesh\\": {
204
+ \\"meshConfig\\": {
205
+ \\"sources\\": [
206
+ {
207
+ \\"name\\": \\"<api_name>\\",
208
+ \\"handler\\": {
209
+ \\"graphql\\": {
210
+ \\"endpoint\\": \\"<gql_endpoint>\\"
211
+ }
212
+ }
213
+ }
214
+ ]
215
+ }
216
+ }
217
+ }",
218
+ ],
219
+ Array [
220
+ "Successfully wrote mesh to file %s",
221
+ "mesh.json",
222
+ ],
223
+ ]
224
+ `);
225
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
226
+ });
227
+
228
+ test('should write to file if file argument is provided', async () => {
229
+ writeFile.mockResolvedValueOnce(true);
230
+
231
+ const file = './mesh.json';
232
+ parseSpy.mockResolvedValueOnce({
233
+ args: {
234
+ file,
235
+ },
236
+ flags: {
237
+ ignoreCache: mockIgnoreCacheFlag,
238
+ },
66
239
  });
240
+
241
+ const runResult = await GetCommand.run();
242
+
243
+ expect(runResult).toEqual({ meshId: 'dummy_meshId', mesh: mockGetMeshConfig });
244
+ expect(writeFile.mock.calls).toMatchInlineSnapshot(`
245
+ Array [
246
+ Array [
247
+ "./mesh.json",
248
+ "{}",
249
+ ],
250
+ ]
251
+ `);
252
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
253
+ Array [
254
+ Array [
255
+ "Successfully retrieved mesh %s",
256
+ "{
257
+ \\"meshId\\": \\"dummy_meshId\\",
258
+ \\"mesh\\": {
259
+ \\"meshConfig\\": {
260
+ \\"sources\\": [
261
+ {
262
+ \\"name\\": \\"<api_name>\\",
263
+ \\"handler\\": {
264
+ \\"graphql\\": {
265
+ \\"endpoint\\": \\"<gql_endpoint>\\"
266
+ }
267
+ }
268
+ }
269
+ ]
270
+ }
271
+ }
272
+ }",
273
+ ],
274
+ Array [
275
+ "Successfully wrote mesh to file %s",
276
+ "./mesh.json",
277
+ ],
278
+ ]
279
+ `);
280
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
67
281
  });
68
282
 
69
- test('get-mesh-with-meshId', async () => {
70
- jest.spyOn(SchemaServiceClient.prototype, 'getMesh').mockImplementation(meshId => mockGetMesh);
71
- expect.assertions(1);
72
- const meshId = 'sample_merchant';
73
- const runResult = GetCommand.run([meshId]);
74
- await expect(runResult).resolves.toEqual(mockGetMesh);
283
+ test('should log error if failed to write to file', async () => {
284
+ writeFile.mockRejectedValueOnce(false);
285
+
286
+ const file = './mesh.json';
287
+ parseSpy.mockResolvedValueOnce({
288
+ args: {
289
+ file,
290
+ },
291
+ flags: {
292
+ ignoreCache: mockIgnoreCacheFlag,
293
+ },
294
+ });
295
+ const runResult = await GetCommand.run();
296
+
297
+ expect(runResult).toEqual({ meshId: 'dummy_meshId', mesh: mockGetMeshConfig });
298
+ expect(writeFile.mock.calls).toMatchInlineSnapshot(`
299
+ Array [
300
+ Array [
301
+ "./mesh.json",
302
+ "{}",
303
+ ],
304
+ ]
305
+ `);
306
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
307
+ Array [
308
+ Array [
309
+ "Successfully retrieved mesh %s",
310
+ "{
311
+ \\"meshId\\": \\"dummy_meshId\\",
312
+ \\"mesh\\": {
313
+ \\"meshConfig\\": {
314
+ \\"sources\\": [
315
+ {
316
+ \\"name\\": \\"<api_name>\\",
317
+ \\"handler\\": {
318
+ \\"graphql\\": {
319
+ \\"endpoint\\": \\"<gql_endpoint>\\"
320
+ }
321
+ }
322
+ }
323
+ ]
324
+ }
325
+ }
326
+ }",
327
+ ],
328
+ Array [
329
+ "Unable to write mesh to file %s",
330
+ "./mesh.json",
331
+ ],
332
+ ]
333
+ `);
334
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
75
335
  });
76
336
  });
@@ -10,68 +10,280 @@ 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
- const mockConsoleCLIInstance = {};
13
+ jest.mock('axios');
14
+ jest.mock('fs/promises');
14
15
  jest.mock('@adobe/aio-lib-env');
15
- const orgs = [{ id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' }];
16
- const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
16
+ jest.mock('../../../helpers', () => ({
17
+ initSdk: jest.fn().mockResolvedValue({}),
18
+ initRequestId: jest.fn().mockResolvedValue({}),
19
+ promptConfirm: jest.fn().mockResolvedValue(true),
20
+ }));
21
+ jest.mock('@adobe/aio-cli-lib-console', () => ({
22
+ init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
23
+ cleanStdOut: jest.fn(),
24
+ }));
25
+ jest.mock('@adobe/aio-lib-ims');
26
+ jest.mock('../../../lib/devConsole');
17
27
 
18
- const projects = [{ id: '5678', title: 'Project01' }];
19
- const selectedProject = { id: '5678', title: 'Project01' };
28
+ const mockConsoleCLIInstance = {};
20
29
 
21
- const workspaces = [{ id: '123456789', title: 'Workspace01' }];
30
+ const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
31
+ const selectedProject = { id: '5678', title: 'Project01' };
22
32
  const selectedWorkspace = { id: '123456789', title: 'Workspace01' };
23
33
 
24
- function setDefaultMockConsoleCLI() {
25
- mockConsoleCLIInstance.getToken = jest.fn().mockReturnValue('test_token');
26
- mockConsoleCLIInstance.getCliEnv = jest.fn().mockReturnValue('prod');
34
+ const { readFile } = require('fs/promises');
27
35
 
28
- mockConsoleCLIInstance.getOrganizations = jest.fn().mockResolvedValue(orgs);
29
- mockConsoleCLIInstance.promptForSelectOrganization = jest.fn().mockResolvedValue(selectedOrg);
36
+ const UpdateCommand = require('../update');
37
+ const { initSdk, initRequestId, promptConfirm } = require('../../../helpers');
38
+ const { getMeshId, updateMesh } = require('../../../lib/devConsole');
30
39
 
31
- mockConsoleCLIInstance.getProjects = jest.fn().mockResolvedValue(projects);
32
- mockConsoleCLIInstance.promptForSelectProject = jest.fn().mockResolvedValue(selectedProject);
40
+ let logSpy = null;
41
+ let errorLogSpy = null;
33
42
 
34
- mockConsoleCLIInstance.getWorkspaces = jest.fn().mockResolvedValue(workspaces);
35
- mockConsoleCLIInstance.promptForSelectWorkspace = jest.fn().mockResolvedValue(selectedWorkspace);
36
- }
43
+ let parseSpy = null;
37
44
 
38
- jest.mock('@adobe/aio-cli-lib-console', () => ({
39
- init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
40
- cleanStdOut: jest.fn(),
41
- }));
42
- jest.mock('@adobe/aio-lib-ims');
43
- const UpdateCommand = require('../update');
44
- const { SchemaServiceClient } = require('../../../classes/SchemaServiceClient');
45
- const mockUpdateMesh = require('../../__fixtures__/sample_mesh.json');
45
+ const mockIgnoreCacheFlag = Promise.resolve(true);
46
+ const mockAutoApproveAction = Promise.resolve(false);
46
47
 
47
48
  describe('update command tests', () => {
48
49
  beforeEach(() => {
49
- setDefaultMockConsoleCLI();
50
- const response = mockUpdateMesh;
51
- jest.spyOn(SchemaServiceClient.prototype, 'updateMesh').mockImplementation(data => response);
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(UpdateCommand.prototype, 'log');
59
+ errorLogSpy = jest.spyOn(UpdateCommand.prototype, 'error');
60
+
61
+ readFile.mockResolvedValue(true);
62
+
63
+ getMeshId.mockResolvedValue('mesh_id');
64
+ updateMesh.mockResolvedValue({ status: 'success' });
65
+
66
+ parseSpy = jest.spyOn(UpdateCommand.prototype, 'parse');
67
+ parseSpy.mockResolvedValue({
68
+ args: { file: 'valid_file_path' },
69
+ flags: {
70
+ ignoreCache: mockIgnoreCacheFlag,
71
+ autoConfirmAction: mockAutoApproveAction,
72
+ },
73
+ });
52
74
  });
53
75
 
54
76
  afterEach(() => {
55
77
  jest.restoreAllMocks();
56
78
  });
57
79
 
58
- test('update-mesh-missing-meshId-file', async () => {
59
- expect.assertions(2);
60
- const runResult = UpdateCommand.run([]);
61
- await expect(runResult instanceof Promise).toBeTruthy();
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(`Array []`);
88
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
89
+ Array [
90
+ Array [
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(`Array []`);
105
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
106
+ Array [
107
+ Array [
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(`Array []`);
128
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
129
+ Array [
130
+ Array [
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
+
62
141
  await expect(runResult).rejects.toEqual(
63
142
  new Error(
64
143
  'Unable to read the mesh configuration file provided. Please check the file and try again.',
65
144
  ),
66
145
  );
146
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
147
+ Array [
148
+ Array [
149
+ "File not found",
150
+ ],
151
+ ]
152
+ `);
153
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
154
+ Array [
155
+ Array [
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
+ Array [
170
+ Array [
171
+ "Update cancelled",
172
+ ],
173
+ ]
174
+ `);
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 []`);
67
225
  });
68
- test('update-mesh-with-configuration', async () => {
69
- expect.assertions(2);
70
- const runResult = UpdateCommand.run([
71
- 'sample_merchant',
72
- 'src/commands/__fixtures__/sample_mesh.json',
73
- ]);
74
- await expect(runResult instanceof Promise).toBeTruthy();
75
- await expect(runResult).resolves.toEqual(mockUpdateMesh);
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 []`);
76
288
  });
77
289
  });