@sasjs/cli 3.7.7 → 3.8.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.
Files changed (26) hide show
  1. package/build/commands/compile/compile.js +5 -6
  2. package/build/commands/compile/internal/checkCompileStatus.js +3 -4
  3. package/build/commands/compile/internal/compileTestFile.d.ts +3 -2
  4. package/build/commands/compile/internal/compileTestFile.js +26 -13
  5. package/build/commands/compile/internal/getAllFolders.d.ts +6 -0
  6. package/build/commands/compile/internal/{getAllJobFolders.js → getAllFolders.js} +49 -23
  7. package/build/commands/compile/internal/identifySasFile.js +3 -4
  8. package/build/commands/compile/internal/spec/compileTestFile.spec.js +37 -0
  9. package/build/commands/compile/internal/spec/getAllFolders.spec.d.ts +1 -0
  10. package/build/commands/compile/internal/spec/getAllFolders.spec.js +184 -0
  11. package/build/commands/compile/spec/copyFilesToBuildFolder.spec.js +2 -4
  12. package/build/commands/deploy/deploy.js +27 -21
  13. package/build/commands/job/internal/execute/index.d.ts +1 -0
  14. package/build/commands/job/internal/execute/index.js +1 -0
  15. package/build/commands/job/internal/execute/sas9.d.ts +14 -0
  16. package/build/commands/job/internal/execute/sas9.js +139 -0
  17. package/build/commands/job/jobCommand.d.ts +4 -0
  18. package/build/commands/job/jobCommand.js +86 -32
  19. package/build/commands/job/spec/jobCommand.spec.js +406 -251
  20. package/build/commands/testing/test.js +3 -4
  21. package/build/utils/test.d.ts +2 -2
  22. package/build/utils/test.js +8 -5
  23. package/package.json +3 -3
  24. package/build/commands/compile/internal/getAllJobFolders.d.ts +0 -2
  25. package/build/commands/compile/internal/getAllServiceFolders.d.ts +0 -2
  26. package/build/commands/compile/internal/getAllServiceFolders.js +0 -91
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
3
  if (k2 === undefined) k2 = k;
15
4
  Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
@@ -96,17 +85,37 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
96
85
  Object.defineProperty(exports, "__esModule", { value: true });
97
86
  var path_1 = __importDefault(require("path"));
98
87
  var viyaExecuteModule = __importStar(require("../internal/execute/viya"));
88
+ var sas9ExecuteModule = __importStar(require("../internal/execute/sas9"));
89
+ var node_1 = __importDefault(require("@sasjs/adapter/node"));
99
90
  var jobCommand_1 = require("../jobCommand");
100
91
  var utils_1 = require("@sasjs/utils");
92
+ var SasjsUtilsFilesModule = __importStar(require("@sasjs/utils/file"));
101
93
  var configUtils = __importStar(require("../../../utils/config"));
102
94
  var command_1 = require("../../../types/command");
95
+ var utilsModule = __importStar(require("../internal/utils"));
103
96
  var defaultArgs = ['node', 'sasjs', 'job', 'execute'];
104
- var target = new utils_1.Target({
97
+ var targetViya = new utils_1.Target({
105
98
  name: 'test',
106
99
  appLoc: '/Public/test/',
107
100
  serverType: utils_1.ServerType.SasViya,
108
101
  contextName: 'test context'
109
102
  });
103
+ var target9 = new utils_1.Target({
104
+ name: 'test',
105
+ appLoc: '/Public/test/',
106
+ serverType: utils_1.ServerType.Sas9,
107
+ contextName: 'test context',
108
+ authConfigSas9: {
109
+ userName: 'testUser',
110
+ password: 'password'
111
+ }
112
+ });
113
+ var sas9TargetWithoutAuthConfig = new utils_1.Target({
114
+ name: 'test',
115
+ appLoc: '/Public/test/',
116
+ serverType: utils_1.ServerType.Sas9,
117
+ contextName: 'test context'
118
+ });
110
119
  var authConfig = {};
111
120
  var jobFileName = 'someJob';
112
121
  var jobPath = "/Public/folder/".concat(jobFileName);
@@ -122,215 +131,351 @@ describe('JobCommand', function () {
122
131
  return [2 /*return*/];
123
132
  });
124
133
  }); });
125
- beforeEach(function () {
126
- setupMocks();
127
- });
128
- it('should parse sasjs job execute command', function () { return __awaiter(void 0, void 0, void 0, function () {
129
- var _a;
130
- return __generator(this, function (_b) {
131
- switch (_b.label) {
132
- case 0: return [4 /*yield*/, executeCommandWrapper([jobPath])];
133
- case 1:
134
- _b.sent();
135
- (_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({ jobPath: jobPath })), false));
136
- return [2 /*return*/];
137
- }
138
- });
139
- }); });
140
- it('should pass wait as true if log flag with value is present', function () { return __awaiter(void 0, void 0, void 0, function () {
141
- var _a;
142
- return __generator(this, function (_b) {
143
- switch (_b.label) {
144
- case 0: return [4 /*yield*/, executeCommandWrapper([jobPath, '--log', log])];
145
- case 1:
146
- _b.sent();
147
- (_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
148
- jobPath: jobPath,
149
- waitForJob: true,
150
- logFile: path_1.default.join(projectFolder, log)
151
- })), false));
152
- return [2 /*return*/];
153
- }
134
+ describe('for server type viya', function () {
135
+ beforeEach(function () {
136
+ setupMocksForViya();
154
137
  });
155
- }); });
156
- it('should pass path for log file and wait to true if log flag without value is present', function () { return __awaiter(void 0, void 0, void 0, function () {
157
- var _a;
158
- return __generator(this, function (_b) {
159
- switch (_b.label) {
160
- case 0: return [4 /*yield*/, executeCommandWrapper([jobPath, '--log'])];
161
- case 1:
162
- _b.sent();
163
- (_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
164
- jobPath: jobPath,
165
- waitForJob: true,
166
- logFile: path_1.default.join(process.projectDir, "".concat(jobFileName, ".log"))
167
- })), false));
168
- return [2 /*return*/];
169
- }
170
- });
171
- }); });
172
- it('should pass wait as true if returnStatusOnly flag is present', function () { return __awaiter(void 0, void 0, void 0, function () {
173
- var _a;
174
- return __generator(this, function (_b) {
175
- switch (_b.label) {
176
- case 0: return [4 /*yield*/, executeCommandWrapper([jobPath, '--returnStatusOnly'])];
177
- case 1:
178
- _b.sent();
179
- (_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
180
- jobPath: jobPath,
181
- waitForJob: true,
182
- returnStatusOnly: true
183
- })), false));
184
- return [2 /*return*/];
185
- }
186
- });
187
- }); });
188
- it('should parse sasjs job execute command with all arguments', function () { return __awaiter(void 0, void 0, void 0, function () {
189
- var _a;
190
- return __generator(this, function (_b) {
191
- switch (_b.label) {
192
- case 0: return [4 /*yield*/, executeCommandWrapper([
193
- jobPath,
194
- '--target',
195
- 'test',
196
- '--log',
197
- log,
198
- '--output',
199
- output,
200
- '--statusFile',
201
- statusFile,
202
- '--source',
203
- source,
204
- '--returnStatusOnly',
205
- '--ignoreWarnings',
206
- '--wait',
207
- '--streamLog'
208
- ])];
209
- case 1:
210
- _b.sent();
211
- (_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
212
- jobPath: jobPath,
213
- waitForJob: true,
214
- output: output,
215
- logFile: path_1.default.join(projectFolder, log),
216
- statusFile: path_1.default.join(projectFolder, statusFile),
217
- returnStatusOnly: true,
218
- ignoreWarnings: true,
219
- source: source,
220
- streamLog: true
221
- })), false));
222
- return [2 /*return*/];
223
- }
224
- });
225
- }); });
226
- it('should parse a sasjs job execute command with all shorthand arguments', function () { return __awaiter(void 0, void 0, void 0, function () {
227
- var _a;
228
- return __generator(this, function (_b) {
229
- switch (_b.label) {
230
- case 0: return [4 /*yield*/, executeCommandWrapper([
231
- jobPath,
232
- '-t',
233
- 'test',
234
- '-l',
235
- log,
236
- '-o',
237
- output,
238
- '--statusFile',
239
- statusFile,
240
- '-s',
241
- source,
242
- '-r',
243
- '-i',
244
- '-w',
245
- '--streamLog'
246
- ])];
247
- case 1:
248
- _b.sent();
249
- (_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
250
- jobPath: jobPath,
251
- waitForJob: true,
252
- output: output,
253
- logFile: path_1.default.join(projectFolder, log),
254
- statusFile: path_1.default.join(projectFolder, statusFile),
255
- returnStatusOnly: true,
256
- ignoreWarnings: true,
257
- source: source,
258
- streamLog: true
259
- })), false));
260
- return [2 /*return*/];
261
- }
262
- });
263
- }); });
264
- it('should log success and return the success code when execution is successful', function () { return __awaiter(void 0, void 0, void 0, function () {
265
- var returnCode;
266
- return __generator(this, function (_a) {
267
- switch (_a.label) {
268
- case 0: return [4 /*yield*/, executeCommandWrapper([jobPath])];
269
- case 1:
270
- returnCode = _a.sent();
271
- expect(returnCode).toEqual(command_1.ReturnCode.Success);
272
- return [2 /*return*/];
273
- }
138
+ it('should parse sasjs job execute command', function () { return __awaiter(void 0, void 0, void 0, function () {
139
+ var _a;
140
+ return __generator(this, function (_b) {
141
+ switch (_b.label) {
142
+ case 0: return [4 /*yield*/, executeCommandWrapper([jobPath])];
143
+ case 1:
144
+ _b.sent();
145
+ (_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({ jobPath: jobPath })), false));
146
+ return [2 /*return*/];
147
+ }
148
+ });
149
+ }); });
150
+ it('should pass wait as true if log flag with value is present', function () { return __awaiter(void 0, void 0, void 0, function () {
151
+ var _a;
152
+ return __generator(this, function (_b) {
153
+ switch (_b.label) {
154
+ case 0: return [4 /*yield*/, executeCommandWrapper([jobPath, '--log', log])];
155
+ case 1:
156
+ _b.sent();
157
+ (_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
158
+ jobPath: jobPath,
159
+ waitForJob: true,
160
+ logFile: path_1.default.join(projectFolder, log)
161
+ })), false));
162
+ return [2 /*return*/];
163
+ }
164
+ });
165
+ }); });
166
+ it('should pass path for log file and wait to true if log flag without value is present', function () { return __awaiter(void 0, void 0, void 0, function () {
167
+ var _a;
168
+ return __generator(this, function (_b) {
169
+ switch (_b.label) {
170
+ case 0: return [4 /*yield*/, executeCommandWrapper([jobPath, '--log'])];
171
+ case 1:
172
+ _b.sent();
173
+ (_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
174
+ jobPath: jobPath,
175
+ waitForJob: true,
176
+ logFile: path_1.default.join(process.projectDir, "".concat(jobFileName, ".log"))
177
+ })), false));
178
+ return [2 /*return*/];
179
+ }
180
+ });
181
+ }); });
182
+ it('should pass wait as true if returnStatusOnly flag is present', function () { return __awaiter(void 0, void 0, void 0, function () {
183
+ var _a;
184
+ return __generator(this, function (_b) {
185
+ switch (_b.label) {
186
+ case 0: return [4 /*yield*/, executeCommandWrapper([jobPath, '--returnStatusOnly'])];
187
+ case 1:
188
+ _b.sent();
189
+ (_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
190
+ jobPath: jobPath,
191
+ waitForJob: true,
192
+ returnStatusOnly: true
193
+ })), false));
194
+ return [2 /*return*/];
195
+ }
196
+ });
197
+ }); });
198
+ it('should parse sasjs job execute command with all arguments', function () { return __awaiter(void 0, void 0, void 0, function () {
199
+ var _a;
200
+ return __generator(this, function (_b) {
201
+ switch (_b.label) {
202
+ case 0: return [4 /*yield*/, executeCommandWrapper([
203
+ jobPath,
204
+ '--target',
205
+ 'test',
206
+ '--log',
207
+ log,
208
+ '--output',
209
+ output,
210
+ '--statusFile',
211
+ statusFile,
212
+ '--source',
213
+ source,
214
+ '--returnStatusOnly',
215
+ '--ignoreWarnings',
216
+ '--wait',
217
+ '--streamLog'
218
+ ])];
219
+ case 1:
220
+ _b.sent();
221
+ (_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
222
+ jobPath: jobPath,
223
+ waitForJob: true,
224
+ output: output,
225
+ logFile: path_1.default.join(projectFolder, log),
226
+ statusFile: path_1.default.join(projectFolder, statusFile),
227
+ returnStatusOnly: true,
228
+ ignoreWarnings: true,
229
+ source: source,
230
+ streamLog: true
231
+ })), false));
232
+ return [2 /*return*/];
233
+ }
234
+ });
235
+ }); });
236
+ it('should parse a sasjs job execute command with all shorthand arguments', function () { return __awaiter(void 0, void 0, void 0, function () {
237
+ var _a;
238
+ return __generator(this, function (_b) {
239
+ switch (_b.label) {
240
+ case 0: return [4 /*yield*/, executeCommandWrapper([
241
+ jobPath,
242
+ '-t',
243
+ 'test',
244
+ '-l',
245
+ log,
246
+ '-o',
247
+ output,
248
+ '--statusFile',
249
+ statusFile,
250
+ '-s',
251
+ source,
252
+ '-r',
253
+ '-i',
254
+ '-w',
255
+ '--streamLog'
256
+ ])];
257
+ case 1:
258
+ _b.sent();
259
+ (_a = expect(viyaExecuteModule.executeJobViya)).toHaveBeenCalledWith.apply(_a, __spreadArray([], __read(executeCalledWith({
260
+ jobPath: jobPath,
261
+ waitForJob: true,
262
+ output: output,
263
+ logFile: path_1.default.join(projectFolder, log),
264
+ statusFile: path_1.default.join(projectFolder, statusFile),
265
+ returnStatusOnly: true,
266
+ ignoreWarnings: true,
267
+ source: source,
268
+ streamLog: true
269
+ })), false));
270
+ return [2 /*return*/];
271
+ }
272
+ });
273
+ }); });
274
+ it('should log success and return the success code when execution is successful', function () { return __awaiter(void 0, void 0, void 0, function () {
275
+ var returnCode;
276
+ return __generator(this, function (_a) {
277
+ switch (_a.label) {
278
+ case 0: return [4 /*yield*/, executeCommandWrapper([jobPath])];
279
+ case 1:
280
+ returnCode = _a.sent();
281
+ expect(returnCode).toEqual(command_1.ReturnCode.Success);
282
+ return [2 /*return*/];
283
+ }
284
+ });
285
+ }); });
286
+ it('should return the error code when getting Auth Config is unsuccessful', function () { return __awaiter(void 0, void 0, void 0, function () {
287
+ var returnCode;
288
+ return __generator(this, function (_a) {
289
+ switch (_a.label) {
290
+ case 0:
291
+ jest
292
+ .spyOn(configUtils, 'getAuthConfig')
293
+ .mockImplementation(function () { return Promise.reject(new Error('Test Error')); });
294
+ return [4 /*yield*/, executeCommandWrapper([jobPath])];
295
+ case 1:
296
+ returnCode = _a.sent();
297
+ expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
298
+ expect(process.logger.error).toHaveBeenCalled();
299
+ return [2 /*return*/];
300
+ }
301
+ });
302
+ }); });
303
+ it('should log the error and return the error code when execution is unsuccessful', function () { return __awaiter(void 0, void 0, void 0, function () {
304
+ var returnCode;
305
+ return __generator(this, function (_a) {
306
+ switch (_a.label) {
307
+ case 0:
308
+ jest
309
+ .spyOn(viyaExecuteModule, 'executeJobViya')
310
+ .mockImplementation(function () { return Promise.reject(new Error('Test Error')); });
311
+ return [4 /*yield*/, executeCommandWrapper([jobPath])];
312
+ case 1:
313
+ returnCode = _a.sent();
314
+ expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
315
+ expect(process.logger.error).toHaveBeenCalled();
316
+ return [2 /*return*/];
317
+ }
318
+ });
319
+ }); });
320
+ });
321
+ describe.only('for server type sas9', function () {
322
+ beforeEach(function () {
323
+ setupMocksForSAS9();
274
324
  });
275
- }); });
276
- it('should return the error code when target is not SASVIYA', function () { return __awaiter(void 0, void 0, void 0, function () {
277
- var returnCode;
278
- return __generator(this, function (_a) {
279
- switch (_a.label) {
280
- case 0:
281
- jest
282
- .spyOn(configUtils, 'findTargetInConfiguration')
283
- .mockImplementation(function () {
284
- return Promise.resolve({
285
- target: new utils_1.Target(__assign(__assign({}, target.toJson()), { serverType: utils_1.ServerType.Sas9 })),
286
- isLocal: true
325
+ it.only('should return the error code when user credentials are not found', function () { return __awaiter(void 0, void 0, void 0, function () {
326
+ var username, password, returnCode;
327
+ return __generator(this, function (_a) {
328
+ switch (_a.label) {
329
+ case 0:
330
+ username = process.env.SAS_USERNAME;
331
+ password = process.env.SAS_PASSWORD;
332
+ process.env.SAS_USERNAME = '';
333
+ process.env.SAS_PASSWORD = '';
334
+ jest
335
+ .spyOn(configUtils, 'findTargetInConfiguration')
336
+ .mockImplementation(function () {
337
+ return Promise.resolve({
338
+ target: sas9TargetWithoutAuthConfig,
339
+ isLocal: true
340
+ });
287
341
  });
288
- });
289
- return [4 /*yield*/, executeCommandWrapper([jobPath], false)];
290
- case 1:
291
- returnCode = _a.sent();
292
- expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
293
- expect(process.logger.error).toHaveBeenCalled();
294
- return [2 /*return*/];
295
- }
296
- });
297
- }); });
298
- it('should return the error code when getting Auth Config is unsuccessful', function () { return __awaiter(void 0, void 0, void 0, function () {
299
- var returnCode;
300
- return __generator(this, function (_a) {
301
- switch (_a.label) {
302
- case 0:
303
- jest
304
- .spyOn(configUtils, 'getAuthConfig')
305
- .mockImplementation(function () { return Promise.reject(new Error('Test Error')); });
306
- return [4 /*yield*/, executeCommandWrapper([jobPath])];
307
- case 1:
308
- returnCode = _a.sent();
309
- expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
310
- expect(process.logger.error).toHaveBeenCalled();
311
- return [2 /*return*/];
312
- }
313
- });
314
- }); });
315
- it('should log the error and return the error code when execution is unsuccessful', function () { return __awaiter(void 0, void 0, void 0, function () {
316
- var returnCode;
317
- return __generator(this, function (_a) {
318
- switch (_a.label) {
319
- case 0:
320
- jest
321
- .spyOn(viyaExecuteModule, 'executeJobViya')
322
- .mockImplementation(function () { return Promise.reject(new Error('Test Error')); });
323
- return [4 /*yield*/, executeCommandWrapper([jobPath])];
324
- case 1:
325
- returnCode = _a.sent();
326
- expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
327
- expect(process.logger.error).toHaveBeenCalled();
328
- return [2 /*return*/];
329
- }
330
- });
331
- }); });
342
+ return [4 /*yield*/, executeCommandWrapper([jobPath])];
343
+ case 1:
344
+ returnCode = _a.sent();
345
+ expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
346
+ expect(process.logger.error).toHaveBeenCalled();
347
+ process.env.SAS_USERNAME = username;
348
+ process.env.SAS_PASSWORD = password;
349
+ return [2 /*return*/];
350
+ }
351
+ });
352
+ }); });
353
+ it('should log success and return the success code when execution is successful', function () { return __awaiter(void 0, void 0, void 0, function () {
354
+ var returnCode;
355
+ return __generator(this, function (_a) {
356
+ switch (_a.label) {
357
+ case 0:
358
+ jest
359
+ .spyOn(sas9ExecuteModule, 'executeJobSas9')
360
+ .mockImplementation(function () { return Promise.resolve(); });
361
+ return [4 /*yield*/, executeCommandWrapper([jobPath])];
362
+ case 1:
363
+ returnCode = _a.sent();
364
+ expect(returnCode).toEqual(command_1.ReturnCode.Success);
365
+ return [2 /*return*/];
366
+ }
367
+ });
368
+ }); });
369
+ it('should log the error and return the error code when execution is unsuccessful', function () { return __awaiter(void 0, void 0, void 0, function () {
370
+ var returnCode;
371
+ return __generator(this, function (_a) {
372
+ switch (_a.label) {
373
+ case 0:
374
+ jest
375
+ .spyOn(sas9ExecuteModule, 'executeJobSas9')
376
+ .mockImplementation(function () { return Promise.reject(new Error('Test Error')); });
377
+ return [4 /*yield*/, executeCommandWrapper([jobPath])];
378
+ case 1:
379
+ returnCode = _a.sent();
380
+ expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
381
+ expect(process.logger.error).toHaveBeenCalled();
382
+ return [2 /*return*/];
383
+ }
384
+ });
385
+ }); });
386
+ it('should log success and return the success code with source argument', function () { return __awaiter(void 0, void 0, void 0, function () {
387
+ var returnCode;
388
+ return __generator(this, function (_a) {
389
+ switch (_a.label) {
390
+ case 0: return [4 /*yield*/, executeCommandWrapper([
391
+ jobPath,
392
+ '--source',
393
+ 'testSource/source.json'
394
+ ])];
395
+ case 1:
396
+ returnCode = _a.sent();
397
+ expect(returnCode).toEqual(command_1.ReturnCode.Success);
398
+ return [2 /*return*/];
399
+ }
400
+ });
401
+ }); });
402
+ it('should log the error and return the error code when source argument is provide but source file does not exists', function () { return __awaiter(void 0, void 0, void 0, function () {
403
+ var returnCode;
404
+ return __generator(this, function (_a) {
405
+ switch (_a.label) {
406
+ case 0: return [4 /*yield*/, executeCommandWrapper([
407
+ jobPath,
408
+ '--source',
409
+ 'source.json'
410
+ ])];
411
+ case 1:
412
+ returnCode = _a.sent();
413
+ expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
414
+ expect(process.logger.error).toHaveBeenCalled();
415
+ return [2 /*return*/];
416
+ }
417
+ });
418
+ }); });
419
+ it('should log the error and return the error code when source argument is provide but source does not contain valid macroVars', function () { return __awaiter(void 0, void 0, void 0, function () {
420
+ var returnCode;
421
+ return __generator(this, function (_a) {
422
+ switch (_a.label) {
423
+ case 0: return [4 /*yield*/, executeCommandWrapper([
424
+ jobPath,
425
+ '--source',
426
+ 'testSource/invalid.json'
427
+ ])];
428
+ case 1:
429
+ returnCode = _a.sent();
430
+ expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
431
+ expect(process.logger.error).toHaveBeenCalled();
432
+ return [2 /*return*/];
433
+ }
434
+ });
435
+ }); });
436
+ it('should log success and return the success code with log argument', function () { return __awaiter(void 0, void 0, void 0, function () {
437
+ var returnCode;
438
+ return __generator(this, function (_a) {
439
+ switch (_a.label) {
440
+ case 0:
441
+ jest
442
+ .spyOn(utilsModule, 'saveLog')
443
+ .mockImplementation(function () { return Promise.resolve(); });
444
+ return [4 /*yield*/, executeCommandWrapper([
445
+ jobPath,
446
+ '--log',
447
+ 'sample.log'
448
+ ])];
449
+ case 1:
450
+ returnCode = _a.sent();
451
+ expect(returnCode).toEqual(command_1.ReturnCode.Success);
452
+ return [2 /*return*/];
453
+ }
454
+ });
455
+ }); });
456
+ it('should log success and return the success code with output argument', function () { return __awaiter(void 0, void 0, void 0, function () {
457
+ var returnCode;
458
+ return __generator(this, function (_a) {
459
+ switch (_a.label) {
460
+ case 0:
461
+ jest
462
+ .spyOn(SasjsUtilsFilesModule, 'createFile')
463
+ .mockImplementation(function () { return Promise.resolve(); });
464
+ return [4 /*yield*/, executeCommandWrapper([
465
+ jobPath,
466
+ '--output',
467
+ 'output.json'
468
+ ])];
469
+ case 1:
470
+ returnCode = _a.sent();
471
+ expect(returnCode).toEqual(command_1.ReturnCode.Success);
472
+ return [2 /*return*/];
473
+ }
474
+ });
475
+ }); });
476
+ });
332
477
  });
333
- var setupMocks = function () {
478
+ var setupMocksForViya = function () {
334
479
  jest.resetAllMocks();
335
480
  jest.mock('../internal/execute');
336
481
  jest.mock('../../../utils/config');
@@ -339,20 +484,40 @@ var setupMocks = function () {
339
484
  .mockImplementation(function () { return Promise.resolve(); });
340
485
  jest
341
486
  .spyOn(configUtils, 'findTargetInConfiguration')
342
- .mockImplementation(function () { return Promise.resolve({ target: target, isLocal: true }); });
487
+ .mockImplementation(function () {
488
+ return Promise.resolve({ target: targetViya, isLocal: true });
489
+ });
343
490
  jest
344
491
  .spyOn(configUtils, 'getAuthConfig')
345
492
  .mockImplementation(function () { return Promise.resolve(authConfig); });
346
493
  process.logger = new utils_1.Logger(utils_1.LogLevel.Off);
347
494
  jest.spyOn(process.logger, 'error');
348
495
  };
496
+ var setupMocksForSAS9 = function () {
497
+ jest.resetAllMocks();
498
+ jest.mock('../internal/execute');
499
+ jest.spyOn(node_1.default.prototype, 'request').mockImplementation(function () {
500
+ return Promise.resolve({
501
+ status: 200,
502
+ result: { data: 'test data' },
503
+ log: 'test log'
504
+ });
505
+ });
506
+ jest
507
+ .spyOn(configUtils, 'findTargetInConfiguration')
508
+ .mockImplementation(function () {
509
+ return Promise.resolve({ target: target9, isLocal: true });
510
+ });
511
+ process.logger = new utils_1.Logger(utils_1.LogLevel.Off);
512
+ jest.spyOn(process.logger, 'error');
513
+ };
349
514
  var executeCalledWith = function (_a) {
350
515
  var jobPath = _a.jobPath, _b = _a.waitForJob, waitForJob = _b === void 0 ? false : _b, _c = _a.output, output = _c === void 0 ? false : _c, _d = _a.logFile, logFile = _d === void 0 ? undefined : _d, _e = _a.statusFile, statusFile = _e === void 0 ? undefined : _e, _f = _a.returnStatusOnly, returnStatusOnly = _f === void 0 ? false : _f, _g = _a.ignoreWarnings, ignoreWarnings = _g === void 0 ? false : _g, _h = _a.source, source = _h === void 0 ? undefined : _h, _j = _a.streamLog, streamLog = _j === void 0 ? false : _j;
351
516
  return [
352
517
  expect.anything(),
353
518
  authConfig,
354
519
  jobPath,
355
- target,
520
+ targetViya,
356
521
  waitForJob,
357
522
  output,
358
523
  logFile,
@@ -363,36 +528,26 @@ var executeCalledWith = function (_a) {
363
528
  streamLog
364
529
  ];
365
530
  };
366
- var executeCommandWrapper = function (additionalParams, checkTarget) {
367
- if (checkTarget === void 0) { checkTarget = true; }
368
- return __awaiter(void 0, void 0, void 0, function () {
369
- var subCommand, args, command, returnCode, targetInfo;
370
- return __generator(this, function (_a) {
371
- switch (_a.label) {
372
- case 0:
373
- subCommand = 'execute';
374
- args = __spreadArray(__spreadArray([], __read(defaultArgs), false), __read(additionalParams), false).map(function (arg) {
375
- if (arg === 'execute') {
376
- arg = Math.random() > 0.5 ? 'exec' : arg;
377
- subCommand = arg;
378
- }
379
- return arg;
380
- });
381
- command = new jobCommand_1.JobCommand(args);
382
- return [4 /*yield*/, command.execute()];
383
- case 1:
384
- returnCode = _a.sent();
385
- expect(command.name).toEqual('job');
386
- expect(command.subCommand).toEqual(subCommand);
387
- if (!checkTarget) return [3 /*break*/, 3];
388
- return [4 /*yield*/, command.getTargetInfo()];
389
- case 2:
390
- targetInfo = _a.sent();
391
- expect(targetInfo.target).toEqual(target);
392
- expect(targetInfo.isLocal).toBeTrue();
393
- _a.label = 3;
394
- case 3: return [2 /*return*/, returnCode];
395
- }
396
- });
531
+ var executeCommandWrapper = function (additionalParams) { return __awaiter(void 0, void 0, void 0, function () {
532
+ var subCommand, args, command, returnCode;
533
+ return __generator(this, function (_a) {
534
+ switch (_a.label) {
535
+ case 0:
536
+ subCommand = 'execute';
537
+ args = __spreadArray(__spreadArray([], __read(defaultArgs), false), __read(additionalParams), false).map(function (arg) {
538
+ if (arg === 'execute') {
539
+ arg = Math.random() > 0.5 ? 'exec' : arg;
540
+ subCommand = arg;
541
+ }
542
+ return arg;
543
+ });
544
+ command = new jobCommand_1.JobCommand(args);
545
+ return [4 /*yield*/, command.execute()];
546
+ case 1:
547
+ returnCode = _a.sent();
548
+ expect(command.name).toEqual('job');
549
+ expect(command.subCommand).toEqual(subCommand);
550
+ return [2 /*return*/, returnCode];
551
+ }
397
552
  });
398
- };
553
+ }); };