Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix_TCP4 3127 #333

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
})
}

}
Loading