|
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'; |
8 | 5 |
|
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; |
17 | 10 |
|
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'); |
54 | 14 | });
|
55 | 15 |
|
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; |
91 | 19 |
|
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:'); |
122 | 23 | });
|
123 | 24 |
|
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; |
132 | 28 |
|
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'); |
141 | 32 | });
|
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 |
| - // }); |
170 | 33 | });
|
0 commit comments