Skip to content

Commit dcd7e38

Browse files
authored
Merge pull request #299 from HRanjan-11/CYP-909
converted session stop to build stop command in cli
2 parents b94e2b4 + dedda9b commit dcd7e38

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

commands/build_stop.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const axios = require('axios');
33
const constants = require("./utils/constants.js");
44
const process = require("process");
55
const fs = require("fs");
6-
function stop_session(args) {
6+
function stop_build(args) {
77
return new Promise(function (resolve, reject) {
88
var username = "";
99
var access_key = "";
@@ -26,33 +26,33 @@ function stop_session(args) {
2626
} else {
2727
reject("Access Key not provided");
2828
}
29-
if ("stop_last_session" in args) {
29+
if ("stop_last_build" in args) {
3030
const file_path = "lambdatest_run.json";
3131
if (fs.existsSync(file_path)) {
3232
let lambda_run = fs.readFileSync(file_path);
3333
try {
3434
let lambda_run_obj = JSON.parse(lambda_run);
35-
if (!("session_id" in lambda_run_obj)) {
36-
throw new Error("session_id is missing from the file");
35+
if (!("build_id" in lambda_run_obj)) {
36+
throw new Error("build_id is missing from the file");
3737
}
38-
args.session_id = lambda_run_obj.session_id;
38+
args.build_id = lambda_run_obj.build_id;
3939
} catch (e) {
4040
reject(
4141
"Error!! lambdatest_run.json file is tampered Err: " + e.message
4242
);
4343
}
4444
} else {
4545
reject(
46-
"Error!! Last session details not found, lambdatest_run.json file not present!!"
46+
"Error!! Last Build details not found, lambdatest_run.json file not present!!"
4747
);
4848
}
4949
} else {
5050
if (
51-
!("session_id" in args) ||
52-
args["session_id"] == "" ||
53-
args["session_id"] == undefined
51+
!("build_id" in args) ||
52+
args["build_id"] == "" ||
53+
args["build_id"] == undefined
5454
) {
55-
reject("Error!! Please provide a Session ID");
55+
reject("Error!! Please provide a Build ID");
5656
}
5757
}
5858
var env = "prod";
@@ -68,7 +68,7 @@ function stop_session(args) {
6868

6969
let options = {
7070
method: 'put',
71-
url: constants[env].BUILD_STOP_URL + args.session_id,
71+
url: constants[env].BUILD_STOP_URL + "?buildId=" + args.build_id,
7272
headers: {
7373
Authorization: "Token " + access_key,
7474
Username: username,
@@ -93,10 +93,10 @@ function stop_session(args) {
9393
axios(options)
9494
.then(response => {
9595
if(response.data.length == 0){
96-
resolve("No tests to stop in session " + args.session_id);
96+
resolve("No tests to stop in build " + args.build_id);
9797
} else {
9898
resolve(
99-
"Session Stopped successfully, No. of tests stopped are: " +
99+
"Build Stopped successfully, No. of tests stopped are: " +
100100
response.data.length
101101
);
102102
}
@@ -120,7 +120,7 @@ function stop_session(args) {
120120
}
121121

122122
module.exports = function (args) {
123-
stop_session(args)
123+
stop_build(args)
124124
.then(function (resp) {
125125
console.log(resp);
126126
})

commands/utils/constants.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = {
2424
prod: {
2525
INTEGRATION_BASE_URL: "https://api.lambdatest.com/liis",
2626
BUILD_BASE_URL: "https://api.lambdatest.com/automation/api/v1/builds/",
27-
BUILD_STOP_URL: "https://api.lambdatest.com/api/v1/test/stop?sessionId=",
27+
BUILD_STOP_URL: "https://api.lambdatest.com/api/v1/test/stop",
2828
SESSION_URL:
2929
"https://api.lambdatest.com/automation/api/v1/sessions?limit=200&session_id=",
3030
REPORT_URL:
@@ -35,7 +35,7 @@ module.exports = {
3535
BUILD_BASE_URL:
3636
"https://api-cypdevenv22-dev.lambdatestinternal.com/automation/api/v1/builds/",
3737
BUILD_STOP_URL:
38-
"https://api-cypdevenv22-dev.lambdatestinternal.com/api/v1/test/stop?sessionId=",
38+
"https://api-cypdevenv22-dev.lambdatestinternal.com/api/v1/test/stop",
3939
SESSION_URL:
4040
"https://api-cypdevenv22-dev.lambdatestinternal.com/automation/api/v1/sessions?limit=200&session_id=",
4141
REPORT_URL:
@@ -47,7 +47,7 @@ module.exports = {
4747
BUILD_BASE_URL:
4848
"https://stage-api.lambdatestinternal.com/automation/api/v1/builds/",
4949
BUILD_STOP_URL:
50-
"https://stage-api.lambdatestinternal.com/api/v1/test/stop?sessionId=",
50+
"https://stage-api.lambdatestinternal.com/api/v1/test/stop",
5151
SESSION_URL:
5252
"https://stage-api.lambdatestinternal.com/automation/api/v1/sessions?limit=200&session_id=",
5353
REPORT_URL:
@@ -59,7 +59,7 @@ module.exports = {
5959
BUILD_BASE_URL:
6060
"https://prestage-api.lambdatest.com/automation/api/v1/builds/",
6161
BUILD_STOP_URL:
62-
"https://prestage-api.lambdatest.com/api/v1/test/stop?sessionId=",
62+
"https://prestage-api.lambdatest.com/api/v1/test/stop",
6363
SESSION_URL:
6464
"https://prestage-api.lambdatest.com/automation/api/v1/sessions?limit=200&session_id=",
6565
REPORT_URL:
@@ -70,7 +70,7 @@ module.exports = {
7070
BUILD_BASE_URL:
7171
"https://preprod-api.lambdatest.com/automation/api/v1/builds/",
7272
BUILD_STOP_URL:
73-
"https://preprod-api.lambdatest.com/api/v1/test/stop?sessionId=",
73+
"https://preprod-api.lambdatest.com/api/v1/test/stop",
7474
SESSION_URL:
7575
"https://preprod-api.lambdatest.com/automation/api/v1/sessions?limit=200&session_id=",
7676
REPORT_URL:

commands/utils/poller/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const axios = require('axios');
55
function stop_cypress_session(lt_config, session_id, env) {
66
return new Promise(function (resolve, reject) {
77
let options = {
8-
url: constants[env].BUILD_STOP_URL + session_id,
8+
url: constants[env].BUILD_STOP_URL + "?sessionId=" + session_id,
99
headers: {
1010
Authorization: "Token " + lt_config["lambdatest_auth"]["access_key"],
1111
Username: lt_config["lambdatest_auth"]["username"],

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ const argv = require("yargs")
281281
function (yargs) {
282282
return yargs
283283
.option("id", {
284-
alias: "session_id",
285-
describe: "Session Identifier",
284+
alias: "build_id",
285+
describe: "Build Identifier",
286286
type: "string",
287287
})
288288
.option("user", {
@@ -306,9 +306,9 @@ const argv = require("yargs")
306306
"Default rejects self signed certificates in external requests",
307307
type: "bool",
308308
})
309-
.option("sls", {
310-
alias: "stop_last_session",
311-
describe: "stop last session",
309+
.option("slb", {
310+
alias: "stop_last_build",
311+
describe: "stop last build",
312312
type: "bool",
313313
});
314314
},

0 commit comments

Comments
 (0)