Skip to content

Commit c95b997

Browse files
authored
Merge pull request #2250 from contentstack/feat/dx-3733
Removed deprecated code from config plugin
2 parents f715656 + 26c6c48 commit c95b997

File tree

6 files changed

+103
-55
lines changed

6 files changed

+103
-55
lines changed

.talismanrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ fileignoreconfig:
55
checksum: fb0c32cd846cce3a53927316699a1c5aaa814939fe9b33bcd9141addbbe447d0
66
- filename: packages/contentstack-bootstrap/test/bootstrap.test.js
77
checksum: b1f46b3447b1b358f80d6404d9d5b385fb385714e5c1f865ca97d64d6edaefc2
8+
- filename: packages/contentstack-config/test/unit/commands/remove-base-branch.test.ts
9+
checksum: 7e98fa2a3bc763ea8a35a229533fb815729c39e08531480c46326737fbe07810
810
version: '1.0'

packages/contentstack-config/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,18 +391,18 @@ Set region for CLI
391391

392392
```
393393
USAGE
394-
$ csdx config:set:region [REGION] [-d <value> -m <value> --ui-host <value> -n <value>] [--developer-hub <value>]
395-
[--personalize <value>] [--launch <value>]
394+
$ csdx config:set:region [REGION] [--cda <value> --cma <value> --ui-host <value> -n <value>] [--developer-hub
395+
<value>] [--personalize <value>] [--launch <value>]
396396
397397
ARGUMENTS
398398
[REGION] Name for the region
399399
400400
FLAGS
401-
-d, --cda=<value> Custom host to set for content delivery API, if this flag is added then cma, ui-host and
401+
-n, --name=<value> Name for the region, if this flag is added then cda, cma and ui-host flags are required
402+
--cda=<value> Custom host to set for content delivery API, if this flag is added then cma, ui-host and
402403
name flags are required
403-
-m, --cma=<value> Custom host to set for content management API, , if this flag is added then cda, ui-host
404+
--cma=<value> Custom host to set for content management API, , if this flag is added then cda, ui-host
404405
and name flags are required
405-
-n, --name=<value> Name for the region, if this flag is added then cda, cma and ui-host flags are required
406406
--developer-hub=<value> Custom host to set for Developer hub API
407407
--launch=<value> Custom host to set for Launch API
408408
--personalize=<value> Custom host to set for Personalize API

packages/contentstack-config/src/commands/config/get/early-access-header.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export default class GetEarlyAccessHeaderCommand extends Command {
88

99
async run() {
1010
try {
11-
let config = configHandler.get(`earlyAccessHeaders`);
11+
const config = configHandler.get(`earlyAccessHeaders`);
1212
if (config && Object.keys(config).length > 0) {
13-
let tableData = Object.keys(config).map((key) => ({
13+
const tableData = Object.keys(config).map((key) => ({
1414
['Alias']: key,
1515
['Early access header']: config[key],
1616
}));

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,21 @@
1-
import { Command } from '@contentstack/cli-command';
2-
import {
3-
cliux,
4-
printFlagDeprecation,
5-
flags as _flags,
6-
authHandler,
7-
FlagInput,
8-
ArgInput,
9-
args,
10-
} from '@contentstack/cli-utilities';
1+
import { cliux, flags as _flags, authHandler, FlagInput, ArgInput, args } from '@contentstack/cli-utilities';
112
import { Region } from '../../../interfaces';
123
import { regionHandler, interactive } from '../../../utils';
13-
import { Args, BaseCommand } from '../../../base-command';
4+
import { BaseCommand } from '../../../base-command';
145

156
export default class RegionSetCommand extends BaseCommand<typeof RegionSetCommand> {
167
config: any;
178
static description = 'Set region for CLI';
189
static flags: FlagInput = {
1910
cda: _flags.string({
20-
char: 'd',
2111
description:
2212
'Custom host to set for content delivery API, if this flag is added then cma, ui-host and name flags are required',
2313
dependsOn: ['cma', 'ui-host', 'name'],
24-
parse: printFlagDeprecation(['-d'], ['--cda']),
2514
}),
2615
cma: _flags.string({
27-
char: 'm',
2816
description:
2917
'Custom host to set for content management API, , if this flag is added then cda, ui-host and name flags are required',
3018
dependsOn: ['cda', 'ui-host', 'name'],
31-
parse: printFlagDeprecation(['-m'], ['--cma']),
3219
}),
3320
'ui-host': _flags.string({
3421
description: 'Custom UI host to set for CLI, if this flag is added then cda, cma and name flags are required',
Lines changed: 87 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,109 @@
1-
import { describe, it } from 'mocha';
1+
import { describe, it, beforeEach, afterEach } from 'mocha';
22
import { expect } from 'chai';
3-
import { stub } from 'sinon';
3+
import { stub, restore } from 'sinon';
44
import RemoveBranchConfigCommand from '../../../src/commands/config/remove/base-branch';
55
import { interactive } from '../../../src/utils';
66
import { removeConfigMockData } from '../mock';
77
import { cliux, configHandler } from '@contentstack/cli-utilities';
88

99
describe('Delete config', () => {
10+
const testApiKey = removeConfigMockData.flags.apiKey;
11+
const testBaseBranch = 'test-branch';
12+
13+
beforeEach(() => {
14+
// Set up test config before each test
15+
configHandler.set(`baseBranch.${testApiKey}`, testBaseBranch);
16+
});
17+
18+
afterEach(() => {
19+
// Clean up test config after each test
20+
try {
21+
configHandler.delete(`baseBranch.${testApiKey}`);
22+
} catch (error) {
23+
// Ignore if config doesn't exist
24+
}
25+
restore();
26+
});
27+
1028
it('Delete config with all flags, should be successful', async function () {
11-
const stub1 = stub(RemoveBranchConfigCommand.prototype, 'run');
12-
await RemoveBranchConfigCommand.run(['--stack-api-key', removeConfigMockData.flags.apiKey, '-y']);
13-
expect(stub1.calledOnce).to.be.true;
14-
stub1.restore();
29+
const successStub = stub(cliux, 'success');
30+
await RemoveBranchConfigCommand.run(['--stack-api-key', testApiKey, '-y']);
31+
32+
// Verify that base branch and stack-api-key are displayed before deletion
33+
expect(successStub.called).to.be.true;
34+
const successCalls = successStub.getCalls();
35+
const messages = successCalls.map(call => call.args[0]);
36+
37+
// Should show base branch and stack-api-key before deletion
38+
expect(messages.some(msg => msg.includes(`base branch : ${testBaseBranch}`))).to.be.true;
39+
expect(messages.some(msg => msg.includes(`stack-api-key: ${testApiKey}`))).to.be.true;
40+
// Should show success message after deletion
41+
expect(messages.some(msg => msg.includes('removed successfully'))).to.be.true;
1542
});
43+
1644
it('Should prompt when api key is not passed', async () => {
17-
const askStackAPIKey = stub(interactive, 'askStackAPIKey').resolves(removeConfigMockData.flags.apiKey);
45+
const askStackAPIKey = stub(interactive, 'askStackAPIKey').resolves(testApiKey);
1846
await RemoveBranchConfigCommand.run(['-y']);
1947
expect(askStackAPIKey.calledOnce).to.be.true;
20-
askStackAPIKey.restore();
2148
});
49+
2250
it('Should throw an error if config doesnt exist', async () => {
23-
const config = configHandler;
24-
const getConfig = config.get(`baseBranch.${removeConfigMockData.flags.apiKey}`);
51+
// Remove the config first
52+
configHandler.delete(`baseBranch.${testApiKey}`);
53+
54+
const errorStub = stub(cliux, 'error');
55+
await RemoveBranchConfigCommand.run(['--stack-api-key', testApiKey]);
2556

26-
const throwError = stub(cliux, 'error');
27-
await RemoveBranchConfigCommand.run(['--stack-api-key', removeConfigMockData.flags.apiKey]);
28-
if (getConfig === undefined) expect(throwError.calledOnce).to.be.true;
29-
throwError.restore();
57+
expect(errorStub.calledOnce).to.be.true;
58+
expect(errorStub.getCalls()[0].args[0]).to.include(`No config set for stack-api-key : ${testApiKey}`);
3059
});
60+
3161
it('Should ask for confirmation to remove config if the config exists', async () => {
32-
const config = configHandler;
33-
const getConfig = config.get(`baseBranch.${removeConfigMockData.flags.apiKey}`);
62+
const askConfirmation = stub(interactive, 'askConfirmation').resolves(true);
63+
await RemoveBranchConfigCommand.run(['--stack-api-key', testApiKey]);
64+
65+
expect(askConfirmation.calledOnce).to.be.true;
66+
});
3467

35-
const askConfirmation = stub(interactive, 'askConfirmation');
36-
await RemoveBranchConfigCommand.run(['--stack-api-key', removeConfigMockData.flags.apiKey]);
37-
if (getConfig) expect(askConfirmation.calledOnce).to.be.true;
38-
askConfirmation.restore();
68+
it('Should show base branch and stack-api-key before deletion', async () => {
69+
const successStub = stub(cliux, 'success');
70+
const askConfirmation = stub(interactive, 'askConfirmation').resolves(true);
71+
72+
await RemoveBranchConfigCommand.run(['--stack-api-key', testApiKey]);
73+
74+
const successCalls = successStub.getCalls();
75+
const messages = successCalls.map(call => call.args[0]);
76+
77+
// Verify that base branch and stack-api-key are displayed
78+
expect(messages.some(msg => msg.includes(`base branch : ${testBaseBranch}`))).to.be.true;
79+
expect(messages.some(msg => msg.includes(`stack-api-key: ${testApiKey}`))).to.be.true;
3980
});
81+
4082
it('Should show success message on deletion of config', async () => {
41-
const config = configHandler;
42-
const getConfig = config.get(`baseBranch.${removeConfigMockData.flags.apiKey}`);
43-
44-
const askConfirmation = stub(interactive, 'askConfirmation');
45-
const showSuccess = stub(cliux, 'success');
46-
await RemoveBranchConfigCommand.run(['--stack-api-key', removeConfigMockData.flags.apiKey]);
47-
if (getConfig && askConfirmation.calledOnce) expect(showSuccess.calledOnce).to.be.true;
48-
askConfirmation.restore();
83+
const successStub = stub(cliux, 'success');
84+
const askConfirmation = stub(interactive, 'askConfirmation').resolves(true);
85+
86+
await RemoveBranchConfigCommand.run(['--stack-api-key', testApiKey]);
87+
88+
expect(askConfirmation.calledOnce).to.be.true;
89+
90+
const successCalls = successStub.getCalls();
91+
const messages = successCalls.map(call => call.args[0]);
92+
93+
// Should show success message after deletion
94+
expect(messages.some(msg => msg.includes('removed successfully'))).to.be.true;
95+
});
96+
97+
it('Should not delete config if confirmation is rejected', async () => {
98+
const askConfirmation = stub(interactive, 'askConfirmation').resolves(false);
99+
const deleteStub = stub(configHandler, 'delete');
100+
101+
await RemoveBranchConfigCommand.run(['--stack-api-key', testApiKey]);
102+
103+
expect(askConfirmation.calledOnce).to.be.true;
104+
// delete should not be called if confirmation is rejected
105+
expect(deleteStub.called).to.be.false;
106+
107+
deleteStub.restore();
49108
});
50109
});

packages/contentstack/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3416,18 +3416,18 @@ Set region for CLI
34163416

34173417
```
34183418
USAGE
3419-
$ csdx config:set:region [REGION] [-d <value> -m <value> --ui-host <value> -n <value>] [--developer-hub <value>]
3420-
[--personalize <value>] [--launch <value>]
3419+
$ csdx config:set:region [REGION] [--cda <value> --cma <value> --ui-host <value> -n <value>] [--developer-hub
3420+
<value>] [--personalize <value>] [--launch <value>]
34213421
34223422
ARGUMENTS
34233423
[REGION] Name for the region
34243424
34253425
FLAGS
3426-
-d, --cda=<value> Custom host to set for content delivery API, if this flag is added then cma, ui-host and
3426+
-n, --name=<value> Name for the region, if this flag is added then cda, cma and ui-host flags are required
3427+
--cda=<value> Custom host to set for content delivery API, if this flag is added then cma, ui-host and
34273428
name flags are required
3428-
-m, --cma=<value> Custom host to set for content management API, , if this flag is added then cda, ui-host
3429+
--cma=<value> Custom host to set for content management API, , if this flag is added then cda, ui-host
34293430
and name flags are required
3430-
-n, --name=<value> Name for the region, if this flag is added then cda, cma and ui-host flags are required
34313431
--developer-hub=<value> Custom host to set for Developer hub API
34323432
--launch=<value> Custom host to set for Launch API
34333433
--personalize=<value> Custom host to set for Personalize API

0 commit comments

Comments
 (0)