diff --git a/sasjs-tests/src/testSuites/Compute.ts b/sasjs-tests/src/testSuites/Compute.ts index 4d02294..ec9ed35 100644 --- a/sasjs-tests/src/testSuites/Compute.ts +++ b/sasjs-tests/src/testSuites/Compute.ts @@ -27,15 +27,70 @@ export const computeTests = (adapter: SASjs): TestSuite => ({ const expectedProperties = ["id", "state", "creationTimeStamp", "jobConditionCode"] return validate(expectedProperties, res.result); } + }, + { + title: "Execute Script Viya - complete job", + description: "Should execute sas file and return log", + test: () => { + const fileLines = [ + `data;`, + `do x=1 to 100;`, + `output;`, + `end;`, + `run;` + ] + + return adapter.executeScriptSASViya( + 'sasCode.sas', + fileLines, + 'SAS Studio compute context', + undefined, + true + ) + }, + assertion: (res: any) => { + const expectedLogContent = `1 data;\\n2 do x=1 to 100;\\n3 output;\\n4 end;\\n5 run;\\n\\n` + + return validateLog(expectedLogContent, res.log); + } + }, + { + title: "Execute Script Viya - failed job", + description: "Should execute sas file and return log", + test: () => { + const fileLines = [ + `%abort;` + ] + + return adapter.executeScriptSASViya( + 'sasCode.sas', + fileLines, + 'SAS Studio compute context', + undefined, + true + ).catch((err: any) => err ) + }, + assertion: (res: any) => { + const expectedLogContent = `1 %abort;\\nERROR: The %ABORT statement is not valid in open code.\\n` + + return validateLog(expectedLogContent, res.log); + } } ] }); +const validateLog = (text: string, log: string): boolean => { + console.log(`[JSON.stringify(log)]`, JSON.stringify(log)) + const isValid = JSON.stringify(log).includes(text) + + return isValid +} + const validate = (expectedProperties: string[], data: any): boolean => { const actualProperties = Object.keys(data); - const isValid = expectedProperties.every( - (property) => actualProperties.includes(property) - ); - return isValid + const isValid = expectedProperties.every( + (property) => actualProperties.includes(property) + ); + return isValid } \ No newline at end of file diff --git a/src/SASjs.ts b/src/SASjs.ts index 1db7a88..9604fc8 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -206,11 +206,20 @@ export default class SASjs { return await this.sasViyaApiClient!.createSession(contextName, accessToken) } + /** + * Executes the sas code against given sas server + * @param fileName - name of the file to run. + * @param linesOfCode - lines of sas code from the file to run. + * @param contextName - context name override on which code will be run. + * @param accessToken - the access tokne to authorizing the request. + * @param debug - debug flag override + */ public async executeScriptSASViya( fileName: string, linesOfCode: string[], contextName: string, - accessToken?: string + accessToken?: string, + debug?: boolean ) { this.isMethodSupported('executeScriptSASViya', ServerType.SASViya) @@ -220,7 +229,7 @@ export default class SASjs { contextName, accessToken, null, - this.sasjsConfig.debug + debug ? debug : this.sasjsConfig.debug ) }