1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-11 09:24:35 +00:00

fix: added debug override on executeScriptSASViya and added tests for same function

This commit is contained in:
Mihajlo Medjedovic
2020-12-03 12:25:42 +01:00
parent 6eb2ceaf53
commit 761428502a
2 changed files with 70 additions and 6 deletions

View File

@@ -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
}

View File

@@ -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
)
}