Skip to content
This repository was archived by the owner on Nov 14, 2020. It is now read-only.

Commit 881792b

Browse files
committed
String trim added to all mnodules involving branch names and refactores describe in test cases to be synchronous
1 parent 80768fa commit 881792b

8 files changed

+27
-12
lines changed

git/gitAddBranchApi.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ const fetchRepopath = require("../global/fetchGitRepoPath");
1212

1313
const gitAddBranchApi = async (repoId, branchName) => {
1414
try {
15-
if(branchName.match(/[^a-zA-Z0-9-_.:~@$^/\\s\\r\\n]/gi)){
16-
throw new Error("Invalid branch name string")
15+
branchName = branchName.trim();
16+
if (branchName.match(/[^a-zA-Z0-9-_.:~@$^/\\s\\r\\n]/gi)) {
17+
throw new Error("Invalid branch name string");
1718
}
1819

1920
return await execPromisified(`git checkout -b "${branchName}"`, {

git/gitBranchDeleteApi.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const fetchRepopath = require("../global/fetchGitRepoPath");
1414

1515
const gitDeleteBranchApi = async (repoId, branchName, forceFlag) => {
1616
try {
17+
branchName = branchName.trim();
1718
if (branchName.match(/[^a-zA-Z0-9-_.:~@$^/\\s\\r\\n]/gi)) {
1819
throw new Error("Invalid branchName string!");
1920
}

git/gitFetchPullApi.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const gitFetchApi = async (repoId, remoteUrl = "", remoteBranch = "") => {
4949
const remoteName = await getRemoteName(repoId, remoteUrl);
5050
console.log("Selected remote name : ", remoteName);
5151

52+
remoteBranch = remoteBranch.trim();
5253
let invalidInput = false;
5354

5455
if (
@@ -124,6 +125,8 @@ const gitPullApi = async (repoId, remoteUrl, remoteBranch) => {
124125
const remoteName = await getRemoteName(repoId, remoteUrl);
125126
console.log("Selected remote name : ", remoteName);
126127

128+
remoteBranch = remoteBranch.trim();
129+
127130
if (!remoteName) {
128131
console.log("NO REMOTE MATCHING THE URL");
129132

git/gitPushToRemoteAPI.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const gitPushToRemoteApi = async (repoId, remoteHost, branch) => {
3030
.join("");
3131

3232
const remoteName = filteredRemote.trim().split(/\s/gi)[0];
33+
branch = branch.trim();
3334

3435
if (branch.match(/[^a-zA-Z0-9-_.:~@$^/\\s\\n\\r]/gi)) {
3536
console.log(

git/gitSetBranch.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const fetchRepopath = require("../global/fetchGitRepoPath");
1212
*/
1313

1414
const gitSetBranchApi = async (repoId, branch) => {
15+
branch = branch.trim();
16+
1517
if (branch.match(/[^a-zA-Z0-9-_.:~@$^/\\s\\r\\n]/gi)) {
1618
console.log("Invalid branch string!");
1719
return "BRANCH_SET_FAILED";

tests/git-tests/gitAddBranchApi.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { getSelectedRepoId } = require("../common/fetchTestRepoId");
33

44
const testBranch = "JEST_TEST_BRANCH";
55

6-
describe("test module for - gitAddBranchApi", async () => {
6+
describe("test module for - gitAddBranchApi", () => {
77
test("positive test case for gitAddBranchApi", async () => {
88
const repoId = await getSelectedRepoId();
99
const addBranchResult = await gitAddBranchApi(repoId, testBranch);
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
const { gitDeleteBranchApi } = require("../../git/gitBranchDeleteApi");
2+
const { gitAddBranchApi } = require("../../git/gitAddBranchApi");
23
const { getSelectedRepoId } = require("../common/fetchTestRepoId");
34
const { gitSetBranchApi } = require("../../git/gitSetBranch");
45

56
const testBranch = "JEST_TEST_BRANCH";
67

7-
describe("test module for - gitBranchDeleteApi", async () => {
8+
describe("test module for - gitBranchDeleteApi", () => {
89
test("positive test case for gitBranchDeleteApi", async () => {
910
const repoId = await getSelectedRepoId();
10-
await gitSetBranchApi(repoId, "master");
11+
const setBranchStatus = await gitSetBranchApi(repoId, "master");
12+
const addBranchStatus = await gitAddBranchApi(repoId, testBranch);
1113

12-
const addBranchResult = await gitDeleteBranchApi(repoId, testBranch, true);
14+
const deleteBranchResult = await gitDeleteBranchApi(
15+
repoId,
16+
testBranch,
17+
true
18+
);
1319

14-
expect(addBranchResult).toBeTruthy();
15-
expect(addBranchResult.status).toBe("BRANCH_DELETE_SUCCESS");
20+
expect(deleteBranchResult).toBeTruthy();
21+
expect(deleteBranchResult.status).toBe("BRANCH_DELETE_SUCCESS");
1622
});
1723

1824
test("negative test case for gitAddBranchApi", async () => {
1925
const repoId = await getSelectedRepoId();
20-
const addBranchResult = await gitDeleteBranchApi(repoId, ",./\\", true);
26+
const deleteBranchResult = await gitDeleteBranchApi(repoId, ",./\\", true);
2127

22-
expect(addBranchResult).toBeTruthy();
23-
expect(addBranchResult.status).toBe("BRANCH_DELETE_FAILED");
28+
expect(deleteBranchResult).toBeTruthy();
29+
expect(deleteBranchResult.status).toBe("BRANCH_DELETE_FAILED");
2430
});
2531
});

tests/git-tests/gitFolderDetailsApi.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ const { gitFetchFolderContentApi } = require("../../git/gitFolderDetailsApi");
22
const { getSelectedRepoId } = require("../common/fetchTestRepoId");
33

44
test("Test module for - gitFolderDetailsApi", async () => {
5+
const repoId = await getSelectedRepoId();
56
const { gitFileBasedCommit, gitTrackedFiles } = await (
6-
await gitFetchFolderContentApi(await getSelectedRepoId(), "")
7+
await gitFetchFolderContentApi(repoId, ".")
78
).gitFolderContent;
89

910
expect(typeof gitFileBasedCommit).toBe("object");

0 commit comments

Comments
 (0)