Skip to content

Commit 6dbf41b

Browse files
author
naman-contentstack
committed
[DX-2346], added support for AWS-NA and AWS-EU, fixed test cases
1 parent cdce068 commit 6dbf41b

File tree

5 files changed

+48
-163
lines changed

5 files changed

+48
-163
lines changed

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: 3 additions & 1 deletion
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',
@@ -118,7 +120,7 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
118120
this.logger.error('failed to set the region', error);
119121
cliux.error(`Failed to set region due to: ${error.message}`);
120122
}
121-
} else if (['NA', 'EU', 'AZURE-NA', 'AZURE-EU', 'GCP-NA', 'GCP-EU'].includes(selectedRegion)) {
123+
} else if (['NA', 'EU', 'AWS-NA', 'AWS-EU', 'AZURE-NA', 'AZURE-EU', 'GCP-NA', 'GCP-EU'].includes(selectedRegion)) {
122124
const regionDetails: Region = regionHandler.setRegion(selectedRegion);
123125
await authHandler.setConfigData('logout'); //Todo: Handle this logout flow well through logout command call
124126
cliux.success(`Region has been set to ${regionDetails.name}`);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ export const askRegions = async (): Promise<string> => {
99
choices: [
1010
{ name: 'NA', value: 'NA' },
1111
{ name: 'EU', value: 'EU' },
12+
{ name: 'AWS-NA', value: 'AWS-NA' },
13+
{ name: 'AWS-EU', value: 'AWS-EU' },
1214
{ name: 'AZURE-NA', value: 'AZURE-NA' },
1315
{ name: 'AZURE-EU', value: 'AZURE-EU' },
1416
{ name: 'GCP-NA', value: 'GCP-NA' },
1517
{ name: 'GCP-EU', value: 'GCP-EU' },
1618
{ name: 'Custom', value: 'custom' },
17-
{ name: 'exit', value: 'exit' },
19+
{ name: 'Exit', value: 'exit' },
1820
],
1921
});
2022
};

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ const regions = {
2626
launchHubUrl: 'https://launch-api.contentstack.com',
2727
personalizeUrl: 'https://personalize-api.contentstack.com',
2828
},
29+
'AWS-NA': {
30+
name: 'AWS-NA',
31+
cma: 'https://api.contentstack.io',
32+
cda: 'https://cdn.contentstack.io',
33+
uiHost: 'https://app.contentstack.com',
34+
developerHubUrl: 'https://developerhub-api.contentstack.com',
35+
launchHubUrl: 'https://launch-api.contentstack.com',
36+
personalizeUrl: 'https://personalize-api.contentstack.com',
37+
},
2938
EU: {
3039
name: 'EU',
3140
cma: 'https://eu-api.contentstack.com',
@@ -35,6 +44,15 @@ const regions = {
3544
launchHubUrl: 'https://eu-launch-api.contentstack.com',
3645
personalizeUrl: 'https://eu-personalize-api.contentstack.com',
3746
},
47+
'AWS-EU': {
48+
name: 'AWS-EU',
49+
cma: 'https://eu-api.contentstack.com',
50+
cda: 'https://eu-cdn.contentstack.com',
51+
uiHost: 'https://eu-app.contentstack.com',
52+
developerHubUrl: 'https://eu-developerhub-api.contentstack.com',
53+
launchHubUrl: 'https://eu-launch-api.contentstack.com',
54+
personalizeUrl: 'https://eu-personalize-api.contentstack.com',
55+
},
3856
'AZURE-NA': {
3957
name: 'AZURE-NA',
4058
cma: 'https://azure-na-api.contentstack.com',
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)