@sasjs/cli 3.7.8 → 3.8.1

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.
@@ -174,7 +174,7 @@ var getTokens = function (target, client, secret, httpsAgentOptions) { return __
174
174
  });
175
175
  return [4 /*yield*/, (0, auth_1.getNewAccessToken)(adapter, client, secret, target).catch(function (e) {
176
176
  var _a;
177
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error("An error has occurred while validating your credentials: ".concat(e, "\nPlease check your Client ID ").concat(target.serverType === types_1.ServerType.Sasjs ? '' : 'and Client Secret ', "and try again.\n"));
177
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error("An error has occurred while validating your credentials: ", e, "\nPlease check your Client ID ".concat(target.serverType === types_1.ServerType.Sasjs ? '' : 'and Client Secret ', "and try again.\n"));
178
178
  throw e;
179
179
  })];
180
180
  case 1:
@@ -259,11 +259,11 @@ function deployToSasViya(deployScriptName, target, isLocal, linesToExecute, logF
259
259
  * for printing web app url on console.
260
260
  */
261
261
  function deployToSas9(deployScriptName, target, linesToExecute, logFolder, streamConfig) {
262
- var _a, _b, _c, _d;
262
+ var _a, _b, _c, _d, _e;
263
263
  return __awaiter(this, void 0, void 0, function () {
264
- var username, password, sas9CredentialsError, sasjs, executionResult, appLoc, webAppStreamUrl;
265
- return __generator(this, function (_e) {
266
- switch (_e.label) {
264
+ var username, password, sas9CredentialsError, sasjs, completedWithError, executionResult, logContent, logFilePath, appLoc, webAppStreamUrl;
265
+ return __generator(this, function (_f) {
266
+ switch (_f.label) {
267
267
  case 0:
268
268
  if (target.authConfigSas9) {
269
269
  username = target.authConfigSas9.userName;
@@ -284,6 +284,7 @@ function deployToSas9(deployScriptName, target, linesToExecute, logFolder, strea
284
284
  appLoc: target.appLoc,
285
285
  serverType: target.serverType
286
286
  });
287
+ completedWithError = false;
287
288
  return [4 /*yield*/, sasjs
288
289
  .executeScriptSAS9(linesToExecute, username, password)
289
290
  .catch(function (err) {
@@ -292,30 +293,35 @@ function deployToSas9(deployScriptName, target, linesToExecute, logFolder, strea
292
293
  if (err && err.errorCode === 404) {
293
294
  (0, utils_1.displaySasjsRunnerError)(username);
294
295
  }
296
+ completedWithError = true;
297
+ return err;
295
298
  })];
296
299
  case 1:
297
- executionResult = _e.sent();
298
- if (!executionResult) return [3 /*break*/, 5];
299
- if (!logFolder) return [3 /*break*/, 3];
300
- return [4 /*yield*/, (0, utils_2.createFile)(path_1.default.join(logFolder, "".concat(deployScriptName.replace('.sas', ''), ".log")), executionResult !== null && executionResult !== void 0 ? executionResult : '')];
300
+ executionResult = _f.sent();
301
+ if (!executionResult) {
302
+ return [2 /*return*/, (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error getting execution log')];
303
+ }
304
+ if (!logFolder) {
305
+ return [2 /*return*/, (_b = process.logger) === null || _b === void 0 ? void 0 : _b.error('Unable to create log file.')];
306
+ }
307
+ logContent = completedWithError
308
+ ? executionResult.result
309
+ : executionResult;
310
+ logFilePath = path_1.default.join(logFolder, "".concat(deployScriptName.replace('.sas', ''), ".log"));
311
+ return [4 /*yield*/, (0, utils_2.createFile)(logFilePath, logContent !== null && logContent !== void 0 ? logContent : '')];
301
312
  case 2:
302
- _e.sent();
303
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("Deployment completed! Log is available at ".concat(path_1.default.join(logFolder, "".concat(deployScriptName.replace('.sas', ''), ".log"))));
304
- return [3 /*break*/, 4];
305
- case 3:
306
- (_b = process.logger) === null || _b === void 0 ? void 0 : _b.error('Unable to create log file.');
307
- _e.label = 4;
308
- case 4:
313
+ _f.sent();
314
+ if (completedWithError) {
315
+ (_c = process.logger) === null || _c === void 0 ? void 0 : _c.error("Deployment failed with errors! Log is available at ".concat(logFilePath));
316
+ throw new Error("Deployment failed.");
317
+ }
318
+ (_d = process.logger) === null || _d === void 0 ? void 0 : _d.success("Deployment completed! Log is available at ".concat(logFilePath));
309
319
  if (streamConfig === null || streamConfig === void 0 ? void 0 : streamConfig.streamWeb) {
310
320
  appLoc = target.appLoc.replace(/\ /g, '%20');
311
321
  webAppStreamUrl = "".concat(target.serverUrl, "/SASStoredProcess/?_PROGRAM=").concat(appLoc, "/services/").concat(streamConfig.streamServiceName);
312
- (_c = process.logger) === null || _c === void 0 ? void 0 : _c.info("Web app is available at ".concat(webAppStreamUrl));
322
+ (_e = process.logger) === null || _e === void 0 ? void 0 : _e.info("Web app is available at ".concat(webAppStreamUrl));
313
323
  }
314
- return [3 /*break*/, 6];
315
- case 5:
316
- (_d = process.logger) === null || _d === void 0 ? void 0 : _d.error('Error getting execution log');
317
- _e.label = 6;
318
- case 6: return [2 /*return*/];
324
+ return [2 /*return*/];
319
325
  }
320
326
  });
321
327
  });
@@ -1,2 +1,3 @@
1
1
  export * from './viya';
2
2
  export * from './sasjs';
3
+ export * from './sas9';
@@ -12,3 +12,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./viya"), exports);
14
14
  __exportStar(require("./sasjs"), exports);
15
+ __exportStar(require("./sas9"), exports);
@@ -0,0 +1,14 @@
1
+ import SASjs from '@sasjs/adapter/node';
2
+ /**
3
+ * Triggers an existing Stored Process for execution as a "job". See online documentation here: https://cli.sasjs.io/job/
4
+ * @param {object} sasjs - Configuration object of the SASJS adapter.
5
+ * @param {object} config - An object containing the username and password for authentication.
6
+ * @param {string} jobPath - Location of the Stored Process in SAS metadata (_program).
7
+ * @param {string | undefined} logFile - If provided, the CLI will write the log here.
8
+ * @param {string | undefined} output - If provided, and valid JSON is returned (ie using the SASjs macros), it will be written to this file location.
9
+ * @param {string | undefined} source - An optional path to a JSON file containing input macro variables.
10
+ */
11
+ export declare function executeJobSas9(sasjs: SASjs, config: {
12
+ username: string;
13
+ password: string;
14
+ }, jobPath: string, logFile?: string, output?: string, source?: string): Promise<any>;
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.executeJobSas9 = void 0;
43
+ var path_1 = __importDefault(require("path"));
44
+ var utils_1 = require("@sasjs/utils");
45
+ var file_1 = require("../../../../utils/file");
46
+ var displayResult_1 = require("../../../../utils/displayResult");
47
+ var utils_2 = require("../utils");
48
+ /**
49
+ * Triggers an existing Stored Process for execution as a "job". See online documentation here: https://cli.sasjs.io/job/
50
+ * @param {object} sasjs - Configuration object of the SASJS adapter.
51
+ * @param {object} config - An object containing the username and password for authentication.
52
+ * @param {string} jobPath - Location of the Stored Process in SAS metadata (_program).
53
+ * @param {string | undefined} logFile - If provided, the CLI will write the log here.
54
+ * @param {string | undefined} output - If provided, and valid JSON is returned (ie using the SASjs macros), it will be written to this file location.
55
+ * @param {string | undefined} source - An optional path to a JSON file containing input macro variables.
56
+ */
57
+ function executeJobSas9(sasjs, config, jobPath, logFile, output, source) {
58
+ return __awaiter(this, void 0, void 0, function () {
59
+ var macroVars, currentDirPath, startTime, result, endTime, outputJson, currentDirPath, outputPath, folderPath, parentFolderPath, error_1;
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0:
63
+ macroVars = null;
64
+ if (!source) return [3 /*break*/, 3];
65
+ currentDirPath = path_1.default.isAbsolute(source) ? '' : process.projectDir;
66
+ source = path_1.default.join(currentDirPath, source);
67
+ if (!(0, file_1.isJsonFile)(source))
68
+ throw 'Source file has to be JSON.';
69
+ return [4 /*yield*/, (0, utils_1.fileExists)(source).catch(function (_) {
70
+ throw 'Error while checking if source file exists.';
71
+ })];
72
+ case 1:
73
+ _a.sent();
74
+ return [4 /*yield*/, (0, utils_1.readFile)(source).catch(function (_) {
75
+ throw 'Error while reading source file.';
76
+ })];
77
+ case 2:
78
+ source = _a.sent();
79
+ macroVars = JSON.parse(source);
80
+ if (!(0, utils_1.isMacroVars)(macroVars)) {
81
+ throw "Provided source is not valid. An example of valid source:\n{ macroVars: { name1: 'value1', name2: 'value2' } }";
82
+ }
83
+ _a.label = 3;
84
+ case 3:
85
+ startTime = new Date().getTime();
86
+ return [4 /*yield*/, sasjs.request(jobPath, macroVars, config)];
87
+ case 4:
88
+ result = _a.sent();
89
+ endTime = new Date().getTime();
90
+ if (!result) return [3 /*break*/, 15];
91
+ if (!(result.status === 200)) return [3 /*break*/, 14];
92
+ process.logger.success("Job executed successfully! in ".concat((endTime - startTime) / 1000, " seconds"));
93
+ if (!(!!logFile && result.log)) return [3 /*break*/, 6];
94
+ return [4 /*yield*/, (0, utils_2.saveLog)(result.log, logFile, jobPath, false)];
95
+ case 5:
96
+ _a.sent();
97
+ _a.label = 6;
98
+ case 6:
99
+ if (!(!!output && result.result)) return [3 /*break*/, 13];
100
+ _a.label = 7;
101
+ case 7:
102
+ _a.trys.push([7, 12, , 13]);
103
+ outputJson = JSON.stringify(result.result, null, 2);
104
+ currentDirPath = path_1.default.isAbsolute(output)
105
+ ? ''
106
+ : process.projectDir;
107
+ outputPath = path_1.default.join(currentDirPath, /\.[a-z]{3,4}$/i.test(output)
108
+ ? output
109
+ : path_1.default.join(output, 'output.json'));
110
+ folderPath = outputPath.split(path_1.default.sep);
111
+ folderPath.pop();
112
+ parentFolderPath = folderPath.join(path_1.default.sep);
113
+ return [4 /*yield*/, (0, utils_1.folderExists)(parentFolderPath)];
114
+ case 8:
115
+ if (!!(_a.sent())) return [3 /*break*/, 10];
116
+ return [4 /*yield*/, (0, utils_1.createFolder)(parentFolderPath)];
117
+ case 9:
118
+ _a.sent();
119
+ _a.label = 10;
120
+ case 10: return [4 /*yield*/, (0, utils_1.createFile)(outputPath, outputJson)];
121
+ case 11:
122
+ _a.sent();
123
+ (0, displayResult_1.displaySuccess)("Output saved to: ".concat(outputPath));
124
+ return [3 /*break*/, 13];
125
+ case 12:
126
+ error_1 = _a.sent();
127
+ (0, displayResult_1.displayError)(error_1, 'An error has occurred when parsing an output of the job.');
128
+ return [3 /*break*/, 13];
129
+ case 13: return [3 /*break*/, 15];
130
+ case 14:
131
+ process.logger.error(result.message);
132
+ process.logger.error(JSON.stringify(result.error, null, 2));
133
+ _a.label = 15;
134
+ case 15: return [2 /*return*/, result];
135
+ }
136
+ });
137
+ });
138
+ }
139
+ exports.executeJobSas9 = executeJobSas9;
@@ -7,5 +7,9 @@ export declare class JobCommand extends TargetCommand {
7
7
  constructor(args: string[]);
8
8
  execute(): Promise<ReturnCode>;
9
9
  executeJobSasjs(sasjs: SASjs, target: Target): Promise<ReturnCode>;
10
+ executeJobSas9(sasjs: SASjs, target: Target, config: {
11
+ username: string;
12
+ password: string;
13
+ }): Promise<ReturnCode>;
10
14
  executeJobViya(target: Target, sasjs: SASjs, authConfig: AuthConfig): Promise<ReturnCode>;
11
15
  }
@@ -141,21 +141,14 @@ var JobCommand = /** @class */ (function (_super) {
141
141
  return _this;
142
142
  }
143
143
  JobCommand.prototype.execute = function () {
144
- var _a;
144
+ var _a, _b;
145
145
  return __awaiter(this, void 0, void 0, function () {
146
- var target, sasjs, _b, authConfig, _c, _d;
147
- return __generator(this, function (_e) {
148
- switch (_e.label) {
146
+ var target, sasjs, _c, authConfig, _d, username, password, _e, _f;
147
+ return __generator(this, function (_g) {
148
+ switch (_g.label) {
149
149
  case 0: return [4 /*yield*/, this.getTargetInfo()];
150
150
  case 1:
151
- target = (_e.sent()).target;
152
- _b = target.serverType;
153
- switch (_b) {
154
- case utils_1.ServerType.SasViya: return [3 /*break*/, 2];
155
- case utils_1.ServerType.Sasjs: return [3 /*break*/, 7];
156
- }
157
- return [3 /*break*/, 11];
158
- case 2:
151
+ target = (_g.sent()).target;
159
152
  sasjs = new node_1.default({
160
153
  serverUrl: target.serverUrl,
161
154
  httpsAgentOptions: target.httpsAgentOptions,
@@ -163,42 +156,74 @@ var JobCommand = /** @class */ (function (_super) {
163
156
  serverType: target.serverType,
164
157
  debug: true
165
158
  });
166
- return [4 /*yield*/, (0, utils_2.getAuthConfig)(target).catch(function (err) {
167
- var _a;
168
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Unable to execute job. Error fetching auth config: ', err);
169
- return null;
170
- })];
159
+ _c = target.serverType;
160
+ switch (_c) {
161
+ case utils_1.ServerType.SasViya: return [3 /*break*/, 2];
162
+ case utils_1.ServerType.Sas9: return [3 /*break*/, 7];
163
+ case utils_1.ServerType.Sasjs: return [3 /*break*/, 11];
164
+ }
165
+ return [3 /*break*/, 15];
166
+ case 2: return [4 /*yield*/, (0, utils_2.getAuthConfig)(target).catch(function (err) {
167
+ var _a;
168
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Unable to execute job. Error fetching auth config: ', err);
169
+ return null;
170
+ })];
171
171
  case 3:
172
- authConfig = _e.sent();
172
+ authConfig = _g.sent();
173
173
  if (!authConfig)
174
174
  return [2 /*return*/, command_1.ReturnCode.InternalError];
175
175
  if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 5];
176
176
  return [4 /*yield*/, this.executeJobViya(target, sasjs, authConfig)];
177
177
  case 4:
178
- _c = _e.sent();
178
+ _d = _g.sent();
179
179
  return [3 /*break*/, 6];
180
180
  case 5:
181
- _c = command_1.ReturnCode.InvalidCommand;
182
- _e.label = 6;
183
- case 6: return [2 /*return*/, _c];
181
+ _d = command_1.ReturnCode.InvalidCommand;
182
+ _g.label = 6;
183
+ case 6: return [2 /*return*/, _d];
184
184
  case 7:
185
+ username = void 0;
186
+ password = void 0;
187
+ if (target.authConfigSas9) {
188
+ username = target.authConfigSas9.userName;
189
+ password = target.authConfigSas9.password;
190
+ }
191
+ else {
192
+ username = process.env.SAS_USERNAME;
193
+ password = process.env.SAS_PASSWORD;
194
+ }
195
+ if (!username || !password) {
196
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Unable to execute job. username and password not found');
197
+ return [2 /*return*/, command_1.ReturnCode.InternalError];
198
+ }
199
+ password = (0, utils_1.decodeFromBase64)(password);
200
+ if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 9];
201
+ return [4 /*yield*/, this.executeJobSas9(sasjs, target, { username: username, password: password })];
202
+ case 8:
203
+ _e = _g.sent();
204
+ return [3 /*break*/, 10];
205
+ case 9:
206
+ _e = command_1.ReturnCode.InvalidCommand;
207
+ _g.label = 10;
208
+ case 10: return [2 /*return*/, _e];
209
+ case 11:
185
210
  sasjs = new node_1.default({
186
211
  serverType: target.serverType,
187
212
  serverUrl: target.serverUrl
188
213
  });
189
214
  if (typeof this.parsed.jobPath !== 'string')
190
215
  return [2 /*return*/, command_1.ReturnCode.InvalidCommand];
191
- if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 9];
216
+ if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 13];
192
217
  return [4 /*yield*/, this.executeJobSasjs(sasjs, target)];
193
- case 8:
194
- _d = _e.sent();
195
- return [3 /*break*/, 10];
196
- case 9:
197
- _d = command_1.ReturnCode.InvalidCommand;
198
- _e.label = 10;
199
- case 10: return [2 /*return*/, _d];
200
- case 11:
201
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error("This command is only supported for SAS Viya targets.\nPlease try again with a different target.");
218
+ case 12:
219
+ _f = _g.sent();
220
+ return [3 /*break*/, 14];
221
+ case 13:
222
+ _f = command_1.ReturnCode.InvalidCommand;
223
+ _g.label = 14;
224
+ case 14: return [2 /*return*/, _f];
225
+ case 15:
226
+ (_b = process.logger) === null || _b === void 0 ? void 0 : _b.error("This command is not supported for specified server type.\nPlease try again with a different server type.");
202
227
  return [2 /*return*/, command_1.ReturnCode.InternalError];
203
228
  }
204
229
  });
@@ -225,6 +250,35 @@ var JobCommand = /** @class */ (function (_super) {
225
250
  });
226
251
  });
227
252
  };
253
+ JobCommand.prototype.executeJobSas9 = function (sasjs, target, config) {
254
+ var _a;
255
+ return __awaiter(this, void 0, void 0, function () {
256
+ var jobPath, log, output, source, returnCode;
257
+ return __generator(this, function (_b) {
258
+ switch (_b.label) {
259
+ case 0:
260
+ jobPath = (0, prefixAppLoc_1.prefixAppLoc)(target.appLoc, this.parsed.jobPath);
261
+ log = (0, getLogFilePath_1.getLogFilePath)(this.parsed.log, jobPath);
262
+ output = ((_a = this.parsed.output) === null || _a === void 0 ? void 0 : _a.length)
263
+ ? this.parsed.output
264
+ : undefined;
265
+ source = this.parsed.source;
266
+ return [4 /*yield*/, (0, execute_1.executeJobSas9)(sasjs, config, jobPath, log, output, source)
267
+ .then(function () {
268
+ return command_1.ReturnCode.Success;
269
+ })
270
+ .catch(function (err) {
271
+ var _a;
272
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error executing job: ', err);
273
+ return command_1.ReturnCode.InternalError;
274
+ })];
275
+ case 1:
276
+ returnCode = _b.sent();
277
+ return [2 /*return*/, returnCode];
278
+ }
279
+ });
280
+ });
281
+ };
228
282
  JobCommand.prototype.executeJobViya = function (target, sasjs, authConfig) {
229
283
  var _a, _b, _c;
230
284
  return __awaiter(this, void 0, void 0, function () {
@@ -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('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('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
+ }); };
@@ -225,13 +225,14 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
225
225
  printTestUrl = function () { return process.logger.info("Test URL: ".concat(testUrl)); };
226
226
  printTestUrl();
227
227
  handleRes = function (res) { return __awaiter(_this, void 0, void 0, function () {
228
- var lineBreak, existingTestTarget, existingTestTarget;
228
+ var lineBreak, test_results, existingTestTarget, existingTestTarget;
229
229
  var _a, _b;
230
230
  return __generator(this, function (_c) {
231
231
  switch (_c.label) {
232
232
  case 0:
233
233
  lineBreak = true;
234
- if (!res.result) {
234
+ test_results = (_a = res.result) === null || _a === void 0 ? void 0 : _a.test_results;
235
+ if (!test_results) {
235
236
  (0, displayResult_1.displayError)({}, "Job did not return a response, to debug click ".concat(testUrl));
236
237
  printCodeExample();
237
238
  lineBreak = false;
@@ -258,8 +259,6 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
258
259
  });
259
260
  }
260
261
  }
261
- if (!((_a = res.result) === null || _a === void 0 ? void 0 : _a.test_results))
262
- lineBreak = false;
263
262
  if (!res.log) return [3 /*break*/, 2];
264
263
  return [4 /*yield*/, (0, saveOutput_1.saveLog)(outDirectory, test, res.log, lineBreak)];
265
264
  case 1:
@@ -124,7 +124,14 @@ function getNewAccessToken(sasjsInstance, clientId, clientSecret, target) {
124
124
  return [4 /*yield*/, getAuthCode(authUrl)];
125
125
  case 1:
126
126
  authCode = _b.sent();
127
- return [4 /*yield*/, sasjsInstance.getAccessToken(clientId, clientSecret, authCode)];
127
+ return [4 /*yield*/, sasjsInstance
128
+ .getAccessToken(clientId, clientSecret, authCode)
129
+ .then(function (res) {
130
+ var access_token = res.access_token, refresh_token = res.refresh_token;
131
+ if (access_token && refresh_token)
132
+ return res;
133
+ throw res;
134
+ })];
128
135
  case 2:
129
136
  _a = _b.sent(), access_token = _a.access_token, refresh_token = _a.refresh_token;
130
137
  return [2 /*return*/, { access_token: access_token, refresh_token: refresh_token }];
package/package.json CHANGED
@@ -47,8 +47,8 @@
47
47
  "access": "public"
48
48
  },
49
49
  "dependencies": {
50
- "@sasjs/adapter": "3.7.4",
51
- "@sasjs/core": "4.9.2",
50
+ "@sasjs/adapter": "3.7.8",
51
+ "@sasjs/core": "4.12.0",
52
52
  "@sasjs/lint": "1.11.2",
53
53
  "@sasjs/utils": "2.36.0",
54
54
  "chalk": "4.1.2",
@@ -94,5 +94,5 @@
94
94
  "typescript": "4.5.4",
95
95
  "util": "0.12.4"
96
96
  },
97
- "version": "3.7.8"
97
+ "version": "3.8.1"
98
98
  }