Skip to content

Commit

Permalink
Merge pull request #333 from ProcessMaker/fix_TCP4-3127
Browse files Browse the repository at this point in the history
fix_TCP4 3127
  • Loading branch information
karlOS123testing authored Dec 11, 2024
2 parents d916ad0 + 1354abb commit 08586c9
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions pages/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,73 @@ export class Scripts {
cy.xpath('//button[contains(text(),"Save")]').click();
});
}

/**
* This method retrieves the ID of a script by its name using the API.
* @param scriptName: The name of the script to search for.
* @return {Promise} A promise that resolves to the ID of the script if found, or undefined if not found.
*
* @example
* getScriptByNameApi("My Script Name").then(scriptId => {
* if (scriptId) {
* console.log("Script ID:", scriptId);
* } else {
* console.log("Script not found.");
* }
* });
*/
getScriptByNameApi(scriptName) {
return cy.window().then(win => {
return win.ProcessMaker.apiClient.get('/scripts', { params: { filter: scriptName } })
.then(response => {
const script = response.data.data.find(script => script.title === scriptName);
if(script){
return script.id;
}else{
return false
}
})
});
}

/**
* This method creates a script using the API.
* It first checks if a script with the given title already exists.
* If it does, it returns the existing script's ID.
* If not, it creates a new script with the provided payload and returns the newly created script's data.
*
* @param payload: An object containing the details of the script to be created.
* @return {Promise} A promise that resolves to the ID of the existing script or the data of the newly created script.
*
* @example
* let payloadScript = {
* "title": "scriptTest_api1",
* "script_executor_id": "1",
* "description": "test automation",
* "script_category_id": "1",
* "run_as_user_id": 1,
* "projects": [],
* "code": '<?php \n$test["resp"] = "test qa"; \nreturn [$test];',
* "timeout": "5",
* "retry_attempts": 0,
* "retry_wait_time": 5
* };
* createScriptAPI(payloadScript).then(scriptID => {
* console.log("Script created or found:", scriptID);
* });
* see TCP4-3127
*/
createScriptAPI(payload) {
return cy.window().then(win => {
return win.ProcessMaker.apiClient.post('/scripts', payload)
.then(response => {
return response.data.data.id;
}).catch(err => {
const errorMessage = err.response?.data?.message?.toLowerCase() || 'Unknown error';
cy.log("message: ===" + errorMessage + "===");;
return this.getScriptByNameApi(payload.title);
});
})
}

}

0 comments on commit 08586c9

Please sign in to comment.