Skip to content

Commit

Permalink
fix: adds more tests to non-sfdx nuts
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed Aug 10, 2023
1 parent 8db2c93 commit 5a0573f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/commands/config/unset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class UnSet extends SfCommand<SetOrUnsetConfigCommandResult> {
throw messages.createError('error.NoConfigKeysFound');
}
const config = await Config.create(Config.getDefaultOptions(flags.global));
const globalConfig = await Config.create(Config.getDefaultOptions(true));
const globalConfig = flags.global ? config : await Config.create(Config.getDefaultOptions(true));

await globalConfig.read();
await config.read();
Expand Down
68 changes: 55 additions & 13 deletions test/commands/config/unset.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,68 @@ describe('config unset NUTs', async () => {
execCmd('config set org-api-version=51.0 --global');
});

it('lists singular config correctly', () => {
const result = execCmd<SetOrUnsetConfigCommandResult>('config unset org-api-version --json', {
ensureExitCode: 0,
}).jsonOutput?.result.successes;
expect(result).to.deep.equal([
{
name: 'org-api-version',
success: true,
},
]);
});

it('lists singular result correctly stdout', () => {
it('displays correct stdout on success', () => {
const res = execCmd('config unset org-api-version').shellOutput.stdout;
expect(res).to.include('Unset Config');
expect(res).to.include('org-api-version');
expect(res).to.include('Name');
expect(res).to.include('Success');
expect(res).to.include('true');
});

it('unsets the config globally', () => {
const res = execCmd('config:unset apiVersion --global --json', { ensureExitCode: 0 });
expect(res.jsonOutput).to.deep.equal({
result: {
failures: [],
successes: [
{
name: 'org-api-version',
success: true,
},
],
},
status: 0,
warnings: ['Deprecated config name: apiVersion. Please use org-api-version instead.'],
});
});

it('warns when nothing unset locally and config still set globally', () => {
const res = execCmd('config:unset org-api-version --json', { ensureExitCode: 0 });
expect(res.jsonOutput).to.deep.equal({
result: {
failures: [],
successes: [
{
name: 'org-api-version',
success: true,
},
],
},
status: 0,
warnings: ['The org-api-version config variable is still set globally, unset it by using the --global flag.'],
});
});

it('warns when unset locally and config still set globally', () => {
// This will result in apiVersion being set both globally and locally
execCmd('config:set org-api-version=52.0', { ensureExitCode: 0 });

const res = execCmd('config:unset org-api-version --json', { ensureExitCode: 0 });
expect(res.jsonOutput).to.deep.equal({
result: {
failures: [],
successes: [
{
name: 'org-api-version',
success: true,
},
],
},
status: 0,
warnings: ['The org-api-version config variable is still set globally, unset it by using the --global flag.'],
});
});
});

describe('config unset with multiple results', () => {
Expand Down
27 changes: 25 additions & 2 deletions test/commands/sfdx/config/unset.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,33 @@ describe('config:unset NUTs', async () => {

describe('config:unset with singular result', () => {
beforeEach(() => {
execCmd('config:set apiVersion=51.0 --global');
execCmd('config:set apiVersion=51.0 --global', { ensureExitCode: 0 });
});

it('warns when config still set globally', () => {
it('warns when nothing unset locally and config still set globally', () => {
const res = execCmd('config:unset apiVersion --json', { ensureExitCode: 0 });
expect(res.jsonOutput).to.deep.equal({
result: {
failures: [],
successes: [
{
name: 'org-api-version',
success: true,
},
],
},
status: 0,
warnings: [
'Deprecated config name: apiVersion. Please use org-api-version instead.',
'The org-api-version config variable is still set globally, unset it by using the --global flag.',
],
});
});

it('warns when unset locally and config still set globally', () => {
// This will result in apiVersion being set both globally and locally
execCmd('config:set apiVersion=52.0', { ensureExitCode: 0 });

const res = execCmd('config:unset apiVersion --json', { ensureExitCode: 0 });
expect(res.jsonOutput).to.deep.equal({
result: {
Expand Down

0 comments on commit 5a0573f

Please sign in to comment.