Skip to content

Commit dc16108

Browse files
author
naman-contentstack
committed
updat testcases and add GH pipeline for it
1 parent cc27c96 commit dc16108

File tree

10 files changed

+216
-40
lines changed

10 files changed

+216
-40
lines changed

.github/workflows/unit-test.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
# name: Run Unit Tests
1+
name: Run Unit Tests
22

3-
# on:
4-
# pull_request:
5-
# types: [opened, synchronize, reopened]
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
66

7-
# jobs:
8-
# run-tests:
9-
# runs-on: ubuntu-latest
10-
# steps:
11-
# - name: Checkout code
12-
# uses: actions/checkout@v4
7+
jobs:
8+
run-tests:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
1313

14-
# - name: Set up Node.js
15-
# uses: actions/setup-node@v4
16-
# with:
17-
# node-version: "22.x"
14+
- name: Set up Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: "22.x"
1818

19-
# - name: Install dependencies
20-
# run: |
21-
# npm install
22-
# npm install -g @contentstack/cli
19+
- name: Install dependencies
20+
run: |
21+
npm install
22+
npm install -g @contentstack/cli
2323
24-
# - name: Configure Region
25-
# run: csdx config:set:region AWS-NA
24+
- name: Configure Region
25+
run: csdx config:set:region AWS-NA
2626

27-
# - name: Run tests
28-
# run: npm run test
27+
- name: Run tests
28+
run: npm run test

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $ npm install -g @contentstack/apps-cli
2121
$ csdx COMMAND
2222
running command...
2323
$ csdx (--version|-v)
24-
@contentstack/apps-cli/1.5.0 darwin-arm64 node-v22.13.1
24+
@contentstack/apps-cli/1.6.0 darwin-arm64 node-v22.13.1
2525
$ csdx --help [COMMAND]
2626
USAGE
2727
$ csdx COMMAND
@@ -71,7 +71,7 @@ EXAMPLES
7171
$ csdx app:update
7272
```
7373

74-
_See code: [src/commands/app/index.ts](https://github.com/contentstack/apps-cli/blob/v1.5.0/src/commands/app/index.ts)_
74+
_See code: [src/commands/app/index.ts](https://github.com/contentstack/apps-cli/blob/v1.6.0/src/commands/app/index.ts)_
7575

7676
## `csdx app:create`
7777

@@ -111,7 +111,7 @@ EXAMPLES
111111
$ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplate <Ecommerce App Boilerplate>
112112
```
113113

114-
_See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.5.0/src/commands/app/create.ts)_
114+
_See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.6.0/src/commands/app/create.ts)_
115115

116116
## `csdx app:delete`
117117

@@ -136,7 +136,7 @@ EXAMPLES
136136
$ csdx app:delete --app-uid <value> --org <value> -d ./boilerplate
137137
```
138138

139-
_See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.5.0/src/commands/app/delete.ts)_
139+
_See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.6.0/src/commands/app/delete.ts)_
140140

141141
## `csdx app:deploy`
142142

@@ -174,7 +174,7 @@ EXAMPLES
174174
$ csdx app:deploy --org <UID> --app-uid <APP-UID-1> --hosting-type <hosting-with-launch> --launch-project <new> --config <config-path>
175175
```
176176

177-
_See code: [src/commands/app/deploy.ts](https://github.com/contentstack/apps-cli/blob/v1.5.0/src/commands/app/deploy.ts)_
177+
_See code: [src/commands/app/deploy.ts](https://github.com/contentstack/apps-cli/blob/v1.6.0/src/commands/app/deploy.ts)_
178178

179179
## `csdx app:get`
180180

@@ -204,7 +204,7 @@ EXAMPLES
204204
$ csdx app:get --org <value> --app-uid <value> --app-type organization
205205
```
206206

207-
_See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.5.0/src/commands/app/get.ts)_
207+
_See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.6.0/src/commands/app/get.ts)_
208208

209209
## `csdx app:install`
210210

@@ -230,7 +230,7 @@ EXAMPLES
230230
$ csdx app:install --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>
231231
```
232232

233-
_See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.5.0/src/commands/app/install.ts)_
233+
_See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.6.0/src/commands/app/install.ts)_
234234

235235
## `csdx app:reinstall`
236236

@@ -256,7 +256,7 @@ EXAMPLES
256256
$ csdx app:reinstall --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>
257257
```
258258

259-
_See code: [src/commands/app/reinstall.ts](https://github.com/contentstack/apps-cli/blob/v1.5.0/src/commands/app/reinstall.ts)_
259+
_See code: [src/commands/app/reinstall.ts](https://github.com/contentstack/apps-cli/blob/v1.6.0/src/commands/app/reinstall.ts)_
260260

261261
## `csdx app:uninstall`
262262

@@ -283,7 +283,7 @@ EXAMPLES
283283
$ csdx app:uninstall --org <UID> --app-uid <APP-UID-1> --installation-uid <INSTALLATION-UID-1>
284284
```
285285

286-
_See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.5.0/src/commands/app/uninstall.ts)_
286+
_See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.6.0/src/commands/app/uninstall.ts)_
287287

288288
## `csdx app:update`
289289

@@ -306,5 +306,5 @@ EXAMPLES
306306
$ csdx app:update --app-manifest ./boilerplate/manifest.json
307307
```
308308

309-
_See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.5.0/src/commands/app/update.ts)_
309+
_See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.6.0/src/commands/app/update.ts)_
310310
<!-- commandsstop -->

test/unit/commands/app/create.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,31 @@ describe("app:create", () => {
3636
sandbox = sinon.createSandbox();
3737
axios.defaults.adapter = "http";
3838

39+
// Stub authentication
40+
sandbox.stub(configHandler, "get").callsFake((key: string) => {
41+
if (key === "region") {
42+
return {
43+
cma: "https://api.contentstack.io",
44+
cda: "https://cdn.contentstack.io",
45+
region: "us",
46+
};
47+
}
48+
if (key === "authtoken") {
49+
return "mock-auth-token";
50+
}
51+
if (key === "authorisationType") {
52+
return "BASIC";
53+
}
54+
return undefined;
55+
});
56+
57+
sandbox
58+
.stub(
59+
require("../../../../src/base-command").BaseCommand.prototype,
60+
"validateRegionAndAuth"
61+
)
62+
.callsFake(() => {});
63+
3964
writeStreamMock = new MockWriteStream();
4065
sandbox.stub(fs, "renameSync").callsFake(() => {});
4166
sandbox.stub(fs, "createWriteStream").callsFake(() => writeStreamMock);

test/unit/commands/app/delete.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,32 @@ describe("app:delete", () => {
1515
let sandbox: sinon.SinonSandbox;
1616
beforeEach(() => {
1717
sandbox = sinon.createSandbox();
18+
19+
// Stub authentication
20+
sandbox.stub(configHandler, "get").callsFake((key: string) => {
21+
if (key === "region") {
22+
return {
23+
cma: "https://api.contentstack.io",
24+
cda: "https://cdn.contentstack.io",
25+
region: "us",
26+
};
27+
}
28+
if (key === "authtoken") {
29+
return "mock-auth-token";
30+
}
31+
if (key === "authorisationType") {
32+
return "BASIC";
33+
}
34+
return undefined;
35+
});
36+
37+
sandbox
38+
.stub(
39+
require("../../../../src/base-command").BaseCommand.prototype,
40+
"validateRegionAndAuth"
41+
)
42+
.callsFake(() => {});
43+
1844
nock(region.cma)
1945
.get("/v3/organizations?limit=100&asc=name&include_count=true&skip=0")
2046
.reply(200, { organizations: mock.organizations });

test/unit/commands/app/deploy.test.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,23 @@ describe("app:deploy", () => {
1717
sandbox = sinon.createSandbox();
1818

1919
// Stub authentication
20-
sandbox.stub(configHandler, "get").returns({
21-
cma: "https://api.contentstack.io",
22-
cda: "https://cdn.contentstack.io",
23-
region: "us",
20+
sandbox.stub(configHandler, "get").callsFake((key: string) => {
21+
if (key === "region") {
22+
return {
23+
cma: "https://api.contentstack.io",
24+
cda: "https://cdn.contentstack.io",
25+
region: "us",
26+
};
27+
}
28+
if (key === "authtoken") {
29+
return "mock-auth-token";
30+
}
31+
if (key === "authorisationType") {
32+
return "BASIC";
33+
}
34+
return undefined;
2435
});
36+
2537
sandbox
2638
.stub(
2739
require("../../../../src/base-command").BaseCommand.prototype,

test/unit/commands/app/get.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,32 @@ describe("app:get", () => {
2020

2121
beforeEach(() => {
2222
sandbox = sinon.createSandbox();
23+
24+
// Stub authentication
25+
sandbox.stub(configHandler, "get").callsFake((key: string) => {
26+
if (key === "region") {
27+
return {
28+
cma: "https://api.contentstack.io",
29+
cda: "https://cdn.contentstack.io",
30+
region: "us",
31+
};
32+
}
33+
if (key === "authtoken") {
34+
return "mock-auth-token";
35+
}
36+
if (key === "authorisationType") {
37+
return "BASIC";
38+
}
39+
return undefined;
40+
});
41+
42+
sandbox
43+
.stub(
44+
require("../../../../src/base-command").BaseCommand.prototype,
45+
"validateRegionAndAuth"
46+
)
47+
.callsFake(() => {});
48+
2349
sandbox.stub(cliux, "loader").callsFake(() => {});
2450
sandbox.stub(fs, "writeFileSync").callsFake(() => {});
2551
});

test/unit/commands/app/install.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ describe("app:install", () => {
1818
sandbox = sinon.createSandbox();
1919
axios.defaults.adapter = "http";
2020

21+
// Stub authentication
22+
sandbox.stub(configHandler, "get").callsFake((key: string) => {
23+
if (key === "region") {
24+
return {
25+
cma: "https://api.contentstack.io",
26+
cda: "https://cdn.contentstack.io",
27+
region: "us",
28+
};
29+
}
30+
if (key === "authtoken") {
31+
return "mock-auth-token";
32+
}
33+
if (key === "authorisationType") {
34+
return "BASIC";
35+
}
36+
return undefined;
37+
});
38+
39+
sandbox
40+
.stub(
41+
require("../../../../src/base-command").BaseCommand.prototype,
42+
"validateRegionAndAuth"
43+
)
44+
.callsFake(() => {});
45+
2146
sandbox.stub(cliux, "loader").callsFake(() => {});
2247

2348
nock(region.cma)

test/unit/commands/app/reinstall.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,31 @@ describe("app:reinstall", () => {
1616
beforeEach(() => {
1717
sandbox = sinon.createSandbox();
1818

19+
// Stub authentication
20+
sandbox.stub(configHandler, "get").callsFake((key: string) => {
21+
if (key === "region") {
22+
return {
23+
cma: "https://api.contentstack.io",
24+
cda: "https://cdn.contentstack.io",
25+
region: "us",
26+
};
27+
}
28+
if (key === "authtoken") {
29+
return "mock-auth-token";
30+
}
31+
if (key === "authorisationType") {
32+
return "BASIC";
33+
}
34+
return undefined;
35+
});
36+
37+
sandbox
38+
.stub(
39+
require("../../../../src/base-command").BaseCommand.prototype,
40+
"validateRegionAndAuth"
41+
)
42+
.callsFake(() => {});
43+
1944
sandbox.stub(cliux, "loader").callsFake(() => {});
2045

2146
nock(region.cma)

test/unit/commands/app/uninstall.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,32 @@ describe("app:uninstall", () => {
1515

1616
beforeEach(() => {
1717
sandbox = sinon.createSandbox();
18+
19+
// Stub authentication
20+
sandbox.stub(configHandler, "get").callsFake((key: string) => {
21+
if (key === "region") {
22+
return {
23+
cma: "https://api.contentstack.io",
24+
cda: "https://cdn.contentstack.io",
25+
region: "us",
26+
};
27+
}
28+
if (key === "authtoken") {
29+
return "mock-auth-token";
30+
}
31+
if (key === "authorisationType") {
32+
return "BASIC";
33+
}
34+
return undefined;
35+
});
36+
37+
sandbox
38+
.stub(
39+
require("../../../../src/base-command").BaseCommand.prototype,
40+
"validateRegionAndAuth"
41+
)
42+
.callsFake(() => {});
43+
1844
sandbox.stub(cliux, "loader").callsFake(() => {});
1945

2046
nock(region.cma)

test/unit/commands/app/update.test.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,21 @@ describe("app:update", () => {
2020
sandbox = sinon.createSandbox();
2121

2222
// Stub authentication
23-
sandbox.stub(configHandler, "get").returns({
24-
cma: "https://api.contentstack.io",
25-
cda: "https://cdn.contentstack.io",
26-
region: "us",
23+
sandbox.stub(configHandler, "get").callsFake((key: string) => {
24+
if (key === "region") {
25+
return {
26+
cma: "https://api.contentstack.io",
27+
cda: "https://cdn.contentstack.io",
28+
region: "us",
29+
};
30+
}
31+
if (key === "authtoken") {
32+
return "mock-auth-token";
33+
}
34+
if (key === "authorisationType") {
35+
return "BASIC";
36+
}
37+
return undefined;
2738
});
2839

2940
// Stub the validateRegionAndAuth method to skip authentication check

0 commit comments

Comments
 (0)