mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-18 17:40:06 +00:00
fix: added debug override on executeScriptSASViya and added tests for same function
This commit is contained in:
@@ -27,15 +27,70 @@ export const computeTests = (adapter: SASjs): TestSuite => ({
|
|||||||
const expectedProperties = ["id", "state", "creationTimeStamp", "jobConditionCode"]
|
const expectedProperties = ["id", "state", "creationTimeStamp", "jobConditionCode"]
|
||||||
return validate(expectedProperties, res.result);
|
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 validate = (expectedProperties: string[], data: any): boolean => {
|
||||||
const actualProperties = Object.keys(data);
|
const actualProperties = Object.keys(data);
|
||||||
|
|
||||||
const isValid = expectedProperties.every(
|
const isValid = expectedProperties.every(
|
||||||
(property) => actualProperties.includes(property)
|
(property) => actualProperties.includes(property)
|
||||||
);
|
);
|
||||||
return isValid
|
return isValid
|
||||||
}
|
}
|
||||||
13
src/SASjs.ts
13
src/SASjs.ts
@@ -206,11 +206,20 @@ export default class SASjs {
|
|||||||
return await this.sasViyaApiClient!.createSession(contextName, accessToken)
|
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(
|
public async executeScriptSASViya(
|
||||||
fileName: string,
|
fileName: string,
|
||||||
linesOfCode: string[],
|
linesOfCode: string[],
|
||||||
contextName: string,
|
contextName: string,
|
||||||
accessToken?: string
|
accessToken?: string,
|
||||||
|
debug?: boolean
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('executeScriptSASViya', ServerType.SASViya)
|
this.isMethodSupported('executeScriptSASViya', ServerType.SASViya)
|
||||||
|
|
||||||
@@ -220,7 +229,7 @@ export default class SASjs {
|
|||||||
contextName,
|
contextName,
|
||||||
accessToken,
|
accessToken,
|
||||||
null,
|
null,
|
||||||
this.sasjsConfig.debug
|
debug ? debug : this.sasjsConfig.debug
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user