diff --git a/test/commands/config/get.nut.ts b/test/commands/config/get.nut.ts index 8c90749f..1cf5853d 100644 --- a/test/commands/config/get.nut.ts +++ b/test/commands/config/get.nut.ts @@ -40,7 +40,7 @@ describe('config get NUTs', async () => { it('gets singular config correctly', () => { const result = execCmd('config get org-api-version --json', { ensureExitCode: 0, - }).jsonOutput?.result.at(0); + }).jsonOutput?.result[0]; expect(result?.name).to.equal('org-api-version'); expect(result?.location).to.equal('Global'); expect(result?.value).to.equal('51.0'); diff --git a/test/commands/config/set.nut.ts b/test/commands/config/set.nut.ts index 55ee63d6..f63b19dc 100644 --- a/test/commands/config/set.nut.ts +++ b/test/commands/config/set.nut.ts @@ -9,6 +9,7 @@ import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; import { expect } from 'chai'; import { Messages } from '@salesforce/core'; import { SetConfigCommandResult } from '../../../src/commands/config/set'; +import { Msg } from '../../../src/config'; Messages.importMessagesDirectory(__dirname); const messages = Messages.load('@salesforce/plugin-settings', 'config.set', [ @@ -18,20 +19,32 @@ const messages = Messages.load('@salesforce/plugin-settings', 'config.set', [ let testSession: TestSession; -function verifyValidationError(key: string, value: string | number, message: string) { - const expected = [ - { - name: key, - value: `${value}`, - message, - success: false, +function verifyValidationError(key: string, value: string) { + const expected = { + result: { + failures: [ + { + error: { + exitCode: 1, + name: 'InvalidConfigValueError', + }, + name: key, + success: false, + value, + }, + ], + successes: [], }, - ]; - const result = execCmd>(`config set ${key}=${value} --json`, { cli: 'sf' }).jsonOutput - ?.result; - delete result?.at(0)?.error; - expect(result).to.deep.equal(expected); - execCmd(`config unset ${key}`); + status: 1, + warnings: [], + }; + const res = execCmd(`config:set ${key}=${value} --json`).jsonOutput; + const result = res?.result.failures as Msg[]; + // validate error message / failures error message here and delete, it will vary based on the value. + expect(result[0]?.message).to.include('Invalid config value:'); + delete result[0]?.message; + expect(res).to.deep.equal(expected); + execCmd(`config:unset ${key}`); } function verifyKeysAndValuesJson(key: string, value: string | boolean) { @@ -104,11 +117,7 @@ describe('config set NUTs', async () => { }); it('will fail to validate org-api-version', () => { - verifyValidationError( - 'org-api-version', - '50', - 'Invalid config value: Specify a valid Salesforce API version, for example, 42.0.' - ); + verifyValidationError('org-api-version', '50'); }); }); @@ -119,11 +128,7 @@ describe('config set NUTs', async () => { }); it('will fail to validate org-max-query-limit', () => { - verifyValidationError( - 'org-max-query-limit', - '-2', - 'Invalid config value: Specify a valid positive integer, for example, 150000.' - ); + verifyValidationError('org-max-query-limit', '-2'); }); }); @@ -137,23 +142,59 @@ describe('config set NUTs', async () => { }); it('will fail to validate org-instance-url when non-Salesforce URL', () => { - verifyValidationError( - 'org-instance-url', - 'abc.com', - 'Invalid config value: Specify a valid Salesforce instance URL.' - ); + verifyValidationError('org-instance-url', 'abc.com'); }); }); - describe('target-org', () => { + describe('target orgs', () => { it('will fail to validate target-org', () => { - verifyValidationError('target-org', 'ab', 'Invalid config value: org "ab" is not authenticated.'); + const expected = { + status: 1, + result: { + successes: [], + failures: [ + { + name: 'target-org', + success: false, + value: 'ab', + error: { + cause: {}, + name: 'Error', + exitCode: 1, + }, + message: 'Invalid config value: org "ab" is not authenticated.', + }, + ], + }, + warnings: [], + }; + const res = execCmd('config:set target-org=ab --json').jsonOutput; + expect(res).to.deep.equal(expected); }); - }); - describe('target-dev-hub', () => { - it('will fail to validate target-dev-hub', () => { - verifyValidationError('target-dev-hub', 'ab', 'Invalid config value: org "ab" is not authenticated.'); + it('will fail to validate target-dev-org', () => { + const expected = { + status: 1, + result: { + successes: [], + failures: [ + { + name: 'target-dev-hub', + success: false, + value: 'ab', + error: { + cause: {}, + name: 'Error', + exitCode: 1, + }, + message: 'Invalid config value: org "ab" is not authenticated.', + }, + ], + }, + warnings: [], + }; + const res = execCmd('config:set target-dev-hub=ab --json').jsonOutput; + expect(res).to.deep.equal(expected); }); }); @@ -178,11 +219,7 @@ describe('config set NUTs', async () => { }); it('will fail to validate disable-telemetry', () => { - verifyValidationError( - 'disable-telemetry', - 'ab', - 'Invalid config value: The config value can only be set to true or false.' - ); + verifyValidationError('disable-telemetry', 'ab'); }); }); @@ -195,11 +232,7 @@ describe('config set NUTs', async () => { }); it('will fail to validate disable-telemetry', () => { - verifyValidationError( - 'disable-telemetry', - 'ab', - 'Invalid config value: The config value can only be set to true or false.' - ); + verifyValidationError('disable-telemetry', 'ab'); }); }); }); diff --git a/test/commands/sfdx/config/get.nut.ts b/test/commands/sfdx/config/get.nut.ts index a04ab809..ba88c1d3 100644 --- a/test/commands/sfdx/config/get.nut.ts +++ b/test/commands/sfdx/config/get.nut.ts @@ -37,7 +37,7 @@ describe('config:get NUTs', async () => { it('gets singular config correctly', () => { const res = execCmd('config:get apiVersion --json', { ensureExitCode: 0 }).jsonOutput; - const result = res?.result.at(0) ?? ({} as Msg); + const result = res?.result[0] ?? ({} as Msg); // the path variable will change machine to machine, ensure it has the config file and then delete it expect(result.path).to.include('config.json'); expect(result.key).to.include('apiVersion'); diff --git a/test/commands/sfdx/config/set.nut.ts b/test/commands/sfdx/config/set.nut.ts index dbd27edc..d1045de1 100644 --- a/test/commands/sfdx/config/set.nut.ts +++ b/test/commands/sfdx/config/set.nut.ts @@ -33,8 +33,8 @@ function verifyValidationError(key: string, value: string | number) { const res = execCmd(`config:set ${key}=${value} --json`).jsonOutput; const result = res?.result.failures as Msg[]; // validate error message / failures error message here and delete, it will vary based on the value. - expect(result.at(0)?.message).to.include('Invalid config value:'); - delete result.at(0)?.message; + expect(result[0]?.message).to.include('Invalid config value:'); + delete result[0]?.message; expect(res).to.deep.equal(expected); execCmd(`config:unset ${key}`); } @@ -43,15 +43,15 @@ function verifyValidationStartsWith(key: string, value: string | number, message const res = execCmd(`config:set ${key}=${value} --json`).jsonOutput; expect(res?.result).to.have.property('successes').with.length(0); expect(res?.result).to.have.property('failures').with.length(1); - const result = res?.result.failures.at(0) as Msg; + const result = res?.result.failures[0] as Msg; expect(result.message?.startsWith(message)).to.be.true; execCmd(`config:unset ${key}`); } function verifyKeysAndValuesJson(key: string, value: string | boolean) { const res = execCmd(`config:set ${key}=${value} --json`, { ensureExitCode: 0 }).jsonOutput; - expect(res?.result.successes.at(0)?.message).to.include(`Deprecated config name: ${key}. Please use`); - delete res?.result.successes.at(0)?.message; + expect(res?.result.successes[0]?.message).to.include(`Deprecated config name: ${key}. Please use`); + delete res?.result.successes[0]?.message; expect(res).to.deep.equal({ status: 0, result: {