Skip to content

Commit 57ea34f

Browse files
Merge pull request #1844 from contentstack/feat/DX-2346
[DX-2346], added support for AWS-NA and AWS-EU, fixed test cases
2 parents 0de443c + 3331173 commit 57ea34f

File tree

9 files changed

+90
-182
lines changed

9 files changed

+90
-182
lines changed

.github/workflows/unit-test.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ jobs:
1919
- name: Install dependencies for all plugins
2020
run: |
2121
npm run setup-repo-old
22-
22+
2323
- name: Run tests for Audit plugin
2424
working-directory: ./packages/contentstack-audit
2525
run: npm run test:unit
2626

27+
- name: Run tests for Contentstack Config
28+
working-directory: ./packages/contentstack-config
29+
run: npm run test
2730
# - name: Fetch latest references
2831
# run: |
2932
# git fetch --prune
@@ -41,11 +44,11 @@ jobs:
4144
# CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
4245
# echo "Changed files:"
4346
# echo "$CHANGED_FILES"
44-
47+
4548
# # Identify affected plugins
4649
# AFFECTED_PLUGINS=$(echo "$CHANGED_FILES" | grep -oP '(?<=^packages/)([^/]+)' | sort -u | tr '\n' ' ')
4750
# echo "Affected plugins: $AFFECTED_PLUGINS"
48-
51+
4952
# # Set output for the next step
5053
# echo "::set-output name=affected_plugins::$AFFECTED_PLUGINS"
5154

@@ -59,4 +62,4 @@ jobs:
5962
# else
6063
# echo "contentstack-audit has not changed. Skipping tests."
6164
# fi
62-
# done
65+
# done

packages/contentstack-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"version": "oclif readme && git add README.md",
1313
"test:report": "tsc -p test && nyc --reporter=lcov --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
1414
"pretest": "tsc -p test",
15-
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
15+
"test": "mocha --require ts-node/register 'test/**/*.test.ts'",
1616
"posttest": "npm run lint",
1717
"lint": "eslint src/**/*.ts",
1818
"format": "eslint src/**/*.ts --fix",

packages/contentstack-config/src/commands/config/set/region.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
5353
'$ csdx config:set:region',
5454
'$ csdx config:set:region NA',
5555
'$ csdx config:set:region EU',
56+
'$ csdx config:set:region AWS-NA',
57+
'$ csdx config:set:region AWS-EU',
5658
'$ csdx config:set:region AZURE-NA',
5759
'$ csdx config:set:region AZURE-EU',
5860
'$ csdx config:set:region GCP-NA',

packages/contentstack-config/src/interfaces/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface InquirePayload {
77
name: string;
88
message: string;
99
choices?: Array<any>;
10+
// eslint-disable-next-line @typescript-eslint/ban-types
1011
transformer?: Function;
1112
}
1213

@@ -27,8 +28,8 @@ export interface Limit {
2728

2829
export interface RateLimitConfig {
2930
getLimit?: Limit;
30-
limit?: Limit
31-
bulkLimit?: Limit
31+
limit?: Limit;
32+
bulkLimit?: Limit;
3233
}
3334

3435
export interface SetRateLimitConfig {

packages/contentstack-config/src/utils/interactive.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isEmpty } from 'lodash';
21
import { cliux, messageHandler } from '@contentstack/cli-utilities';
32

43
export const askRegions = async (): Promise<string> => {
@@ -9,12 +8,14 @@ export const askRegions = async (): Promise<string> => {
98
choices: [
109
{ name: 'NA', value: 'NA' },
1110
{ name: 'EU', value: 'EU' },
11+
{ name: 'AWS-NA', value: 'NA' },
12+
{ name: 'AWS-EU', value: 'EU' },
1213
{ name: 'AZURE-NA', value: 'AZURE-NA' },
1314
{ name: 'AZURE-EU', value: 'AZURE-EU' },
1415
{ name: 'GCP-NA', value: 'GCP-NA' },
1516
{ name: 'GCP-EU', value: 'GCP-EU' },
1617
{ name: 'Custom', value: 'custom' },
17-
{ name: 'exit', value: 'exit' },
18+
{ name: 'Exit', value: 'exit' },
1819
],
1920
});
2021
};

packages/contentstack-config/src/utils/rate-limit-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class RateLimitHandler {
3232
const features = organizations.plan?.features || [];
3333

3434
const limitsToUpdate: { [key: string]: Limit } = { ...rateLimit[config.org] };
35-
let utilizationMap = {};
35+
const utilizationMap = {};
3636
limitNames.forEach((name, index) => {
3737
if (utilizeValues[index] !== undefined) {
3838
utilizationMap[name] = utilizeValues[index];

packages/contentstack-config/src/utils/region-handler.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class UserConfig {
8181
* @returns {object} region object with cma, cda, region property
8282
*/
8383
setRegion(region) {
84-
let selectedRegion = regions[region];
84+
const selectedRegion = regions[region];
8585
if (selectedRegion) {
8686
configHandler.set('region', selectedRegion);
8787
return selectedRegion;
@@ -151,8 +151,7 @@ class UserConfig {
151151
* @returns { object } JSON object with only valid keys for region
152152
*/
153153
sanitizeRegionObject(regionObject) {
154-
let sanitizedRegion;
155-
sanitizedRegion = {
154+
const sanitizedRegion = {
156155
cma: regionObject.cma,
157156
cda: regionObject.cda,
158157
uiHost: regionObject.uiHost,
Lines changed: 23 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,33 @@
1-
import * as path from "path";
2-
import { expect, test } from "@oclif/test";
3-
// @ts-ignore
4-
import { Helper } from "./utils";
5-
import { cliux, messageHandler } from "@contentstack/cli-utilities";
6-
// @ts-ignore
7-
import { PRINT_LOGS, CDA, CMA, REGION_NAME } from "./config.json";
1+
import { expect } from 'chai';
2+
import * as sinon from 'sinon';
3+
import { spawnSync } from 'child_process';
4+
import { cliux } from '@contentstack/cli-utilities';
85

9-
const messageFilePath = path.join(
10-
__dirname,
11-
"..",
12-
"..",
13-
"..",
14-
"contentstack-config",
15-
"messages/index.json"
16-
);
6+
describe('ContentStack-Config Plugin Tests', () => {
7+
it("Should execute 'config:set:region --AZURE-NA'", () => {
8+
const result = spawnSync('csdx', ['config:set:region', 'AZURE-NA'], { encoding: 'utf-8' });
9+
const output = result.stdout + result.stderr;
1710

18-
describe("ContentStack-Config plugin test", () => {
19-
beforeEach(() => {
20-
messageHandler.init({ messageFilePath });
21-
});
22-
afterEach(() => {
23-
messageHandler.init({ messageFilePath: "" });
24-
});
25-
26-
describe('Running config:set:region command without any flags and set AZURE-NA as Region', () => {
27-
test
28-
.stub(cliux, 'inquire', async () => 'AZURE-NA')
29-
.stdout({ print: PRINT_LOGS || false })
30-
.command(['config:set:region'])
31-
.it('Check config:set:region command output [It should set AZURE-NA as region]', (ctx) => {
32-
expect(ctx.stdout)
33-
.to.be.a('string')
34-
.that.have.includes(
35-
'Region has been set to AZURE-NA\nCDA HOST: https://azure-na-cdn.contentstack.com\nCMA HOST: https://azure-na-api.contentstack.com\n',
36-
'AZURE-NA region is not setup.!',
37-
);
38-
});
39-
});
40-
41-
describe('Running config:set:region command without any flags and set AZURE-EU as Region', () => {
42-
test
43-
.stub(cliux, 'inquire', async () => 'AZURE-EU')
44-
.stdout({ print: PRINT_LOGS || false })
45-
.command(['config:set:region'])
46-
.it('Check config:set:region command output [It should set AZURE-EU as region]', (ctx) => {
47-
expect(ctx.stdout)
48-
.to.be.a('string')
49-
.that.have.includes(
50-
'Region has been set to AZURE-EU\nCDA HOST: https://azure-eu-cdn.contentstack.com\nCMA HOST: https://azure-eu-api.contentstack.com\n',
51-
'AZURE-EU region is not setup.!',
52-
);
53-
});
11+
expect(output).to.include('Region has been set to AZURE-NA');
12+
expect(output).to.include('CDA HOST: https://azure-na-cdn.contentstack.com');
13+
expect(output).to.include('CMA HOST: https://azure-na-api.contentstack.com');
5414
});
5515

56-
describe("Running config:set:region command with arg as NA region", () => {
57-
test
58-
.stdout({ print: PRINT_LOGS || false })
59-
.command(["config:set:region", "NA"])
60-
.it("Check NA region has setup", (ctx) => {
61-
expect(ctx.stdout).to.equal(
62-
"Region has been set to NA\nCDA HOST: https://cdn.contentstack.io\nCMA HOST: https://api.contentstack.io\n"
63-
);
64-
});
65-
});
66-
67-
describe("Running config:set:region command with custom Name, CMA, CDA flags", () => {
68-
test
69-
.stdout({ print: PRINT_LOGS || false })
70-
.command([
71-
"config:set:region",
72-
`-n=${REGION_NAME || "Test"}`,
73-
`-d=${CDA || "https://cdn.contentstack.io"}`,
74-
`-m=${CMA || "https://api.contentstack.io"}`,
75-
])
76-
.it(
77-
`Check Name=${REGION_NAME || "Test"}, CDA=${
78-
CDA || "https://cdn.contentstack.io"
79-
}, CMA=${CMA || "https://api.contentstack.io"} values has setup`,
80-
(ctx) => {
81-
expect(ctx.stdout).to.equal(
82-
`Custom region has been set to ${
83-
REGION_NAME || "Test"
84-
}\nCMA HOST: ${CMA || "https://api.contentstack.io"}\nCDA HOST: ${
85-
CDA || "https://cdn.contentstack.io"
86-
}\n`
87-
);
88-
}
89-
);
90-
});
16+
it("Should execute 'config:get:region' and return the current region", () => {
17+
const result = spawnSync('csdx', ['config:get:region'], { encoding: 'utf-8' });
18+
const output = result.stdout + result.stderr;
9119

92-
describe("Running config:set:region command without any flags and setting custom values", () => {
93-
test
94-
// @ts-ignore
95-
.stub(cliux, "inquire", async (inquire) => {
96-
switch (inquire.name) {
97-
case "selectedRegion":
98-
return "custom";
99-
case "name":
100-
return REGION_NAME || "Test";
101-
case "cma":
102-
return CMA || "https://api.contentstack.io";
103-
case "cda":
104-
return CDA || "https://cdn.contentstack.io";
105-
}
106-
})
107-
.stdout({ print: PRINT_LOGS || false })
108-
.stderr()
109-
.command(["config:set:region"])
110-
.it("Verifying output with custom values", async (ctx) => {
111-
expect(ctx.stdout)
112-
.to.be.a("string")
113-
.that.have.includes(
114-
`Custom region has been set to ${
115-
REGION_NAME || "Test"
116-
}\nCMA HOST: ${CMA || "https://api.contentstack.io"}\nCDA HOST: ${
117-
CDA || "https://cdn.contentstack.io"
118-
}\n`,
119-
"Custom CDA, CMA setup failed.!"
120-
);
121-
});
20+
expect(output).to.include('Currently using');
21+
expect(output).to.include('CDA HOST:');
22+
expect(output).to.include('CMA HOST:');
12223
});
12324

124-
describe("Running config:get:region command", () => {
125-
let currentRegion;
126-
before(async () => {
127-
currentRegion = await Helper.run();
128-
});
129-
after(() => {
130-
currentRegion = null;
131-
});
25+
it("Should execute 'config:set:region NA' and set NA region", () => {
26+
const result = spawnSync('csdx', ['config:set:region', 'NA'], { encoding: 'utf-8' });
27+
const output = result.stdout + result.stderr;
13228

133-
test
134-
.stdout({ print: PRINT_LOGS || false })
135-
.command(["config:get:region"])
136-
.it("Should print current region and it's CDA, CMA as", (ctx) => {
137-
expect(ctx.stdout, "Expected output not found.!").to.equal(
138-
`Currently using ${currentRegion.name} region\nCDA HOST: ${currentRegion.cda}\nCMA HOST: ${currentRegion.cma}\n`
139-
);
140-
});
29+
expect(output).to.include('Region has been set to NA');
30+
expect(output).to.include('CDA HOST: https://cdn.contentstack.io');
31+
expect(output).to.include('CMA HOST: https://api.contentstack.io');
14132
});
142-
143-
// describe('Running config:get:region command to check if a region is setup', () => {
144-
// let currentRegion;
145-
// before(async () => {
146-
// currentRegion = await Helper.run();
147-
// });
148-
// after(() => {
149-
// currentRegion = null;
150-
// });
151-
152-
// test
153-
// .stdout({ print: PRINT_LOGS || false })
154-
// .command(['config:get:region'])
155-
// .catch((error) => {
156-
// if (error.message) {
157-
// expect(error.message).to.be.a('string').equals('EEXIT: 0');
158-
// }
159-
// })
160-
// .it("Should print current region and it's CDA, CMA or region should be undefined", (ctx) => {
161-
// if (currentRegion) {
162-
// expect(ctx.stdout).to.includes(
163-
// `Currently using ${currentRegion.name} region\nCDA HOST: ${currentRegion.cda}\nCMA HOST: ${currentRegion.cma}\n`,
164-
// );
165-
// } else {
166-
// expect(ctx.error).to.be.undefined;
167-
// }
168-
// });
169-
// });
17033
});

0 commit comments

Comments
 (0)