diff --git a/src/commands/authorizeCommand.ts b/src/commands/authorizeCommand.ts index 68e8f4f..33d4319 100644 --- a/src/commands/authorizeCommand.ts +++ b/src/commands/authorizeCommand.ts @@ -5,37 +5,34 @@ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ -import { commands, window } from 'vscode'; +import { commands, window, l10n } from 'vscode'; import { OrgUtils } from '../utils/orgUtils'; export class AuthorizeCommand { static async authorizeToOrg(): Promise { - const user = await OrgUtils.getDefaultUser(); - - // Ask user to authorize to an org now only if not authorized yet. - if (user === 'undefined') { + try { + await OrgUtils.getDefaultUser(); + return Promise.resolve(true); + } catch { + // Ask user to authorize to an org now only if not authorized yet. const result = await window.showInformationMessage( - 'Do you want to authorize an Org now?', - { title: 'Authorize' }, - { title: 'No' } + l10n.t('Do you want to authorize an Org now?'), + { title: l10n.t('Authorize') }, + { title: l10n.t('No') } ); - if (result) { - if (result.title === 'No') { - return Promise.resolve(false); - } else { - await commands.executeCommand('sfdx.force.auth.web.login'); - await window.showInformationMessage( - "Once you've authorized your Org, click here to continue.", - { title: 'OK' } - ); - return Promise.resolve(true); - } - } else { + if (!result || result.title === l10n.t('No')) { return Promise.resolve(false); + } else { + await commands.executeCommand('sfdx.force.auth.web.login'); + await window.showInformationMessage( + l10n.t( + "Once you've authorized your Org, click here to continue." + ), + { title: l10n.t('OK') } + ); + return Promise.resolve(true); } - } else { - return Promise.resolve(true); } } } diff --git a/src/commands/briefcaseCommand.ts b/src/commands/briefcaseCommand.ts index 533b2b1..cc0e01b 100644 --- a/src/commands/briefcaseCommand.ts +++ b/src/commands/briefcaseCommand.ts @@ -12,16 +12,17 @@ import { InstructionsWebviewProvider } from '../webviews'; export class BriefcaseCommand { static async setupBriefcase(extensionUri: Uri): Promise { await window.showInformationMessage( - 'Click OK to launch your org to the Briefcase Builder page. After ' + - 'launching, return here for instructions to set up a Briefcase rule.', - { title: 'OK' } + l10n.t( + 'Click OK to launch your org to the Briefcase Builder page. After launching, return here for instructions to set up a Briefcase rule.' + ), + { title: l10n.t('OK') } ); // TODO: this `withProgress` call probably needs tweaking on UX. await window.withProgress( { location: ProgressLocation.Notification, - title: 'Launching Briefcase Builder...' + title: l10n.t('Launching Briefcase Builder...') }, async (progress, token) => { await CommonUtils.executeCommandAsync( diff --git a/src/commands/deployToOrgCommand.ts b/src/commands/deployToOrgCommand.ts index 29fd5c9..0dc20b4 100644 --- a/src/commands/deployToOrgCommand.ts +++ b/src/commands/deployToOrgCommand.ts @@ -6,26 +6,28 @@ */ import path = require('path'); -import { Uri, commands, window, workspace } from 'vscode'; +import { Uri, commands, window, workspace, l10n } from 'vscode'; export class DeployToOrgCommand { static async deployToOrg(): Promise { const currentWorkspace = workspace; if (!currentWorkspace.workspaceFolders) { await window.showErrorMessage( - 'There are no workspace folders defined in your project.', - { title: 'OK' } + l10n.t( + 'There are no workspace folders defined in your project.' + ), + { title: l10n.t('OK') } ); return Promise.resolve(false); } const result = await window.showInformationMessage( - 'Do you want to deploy to an already-authorized Org?', - { title: 'Deploy' }, - { title: 'Cancel' } + l10n.t('Do you want to deploy to an already-authorized Org?'), + { title: l10n.t('Deploy') }, + { title: l10n.t('Cancel') } ); - if (!result || result.title === 'Cancel') { + if (!result || result.title === l10n.t('Cancel')) { return Promise.resolve(false); } diff --git a/src/test/suite/commands/authorizeToOrgCommand.test.ts b/src/test/suite/commands/authorizeToOrgCommand.test.ts index 592973b..341f285 100644 --- a/src/test/suite/commands/authorizeToOrgCommand.test.ts +++ b/src/test/suite/commands/authorizeToOrgCommand.test.ts @@ -30,7 +30,7 @@ suite('Authorize Org Command Test Suite', () => { test('Authorization cancelled by the user', async () => { // setup up so that org is not authorized yet const getDefaultUserStub = sinon.stub(OrgUtils, 'getDefaultUser'); - getDefaultUserStub.onCall(0).resolves('undefined'); + getDefaultUserStub.onCall(0).rejects(false); // simulate user choosing not to authorize const showInformationMessageStub = sinon.stub( diff --git a/src/test/suite/utils/orgUtils.test.ts b/src/test/suite/utils/orgUtils.test.ts index fd845de..8295bef 100644 --- a/src/test/suite/utils/orgUtils.test.ts +++ b/src/test/suite/utils/orgUtils.test.ts @@ -90,6 +90,32 @@ suite('Org Utils Test Suite', () => { assert.equal(reloadSpy.called, true, 'reload should be invoked'); }); + test('Username is not determined.', async () => { + const reloadSpy = sinon.spy(() => { + return Promise.resolve; + }); + + const config: SinonStub = sinon.stub(ConfigAggregator, 'create'); + config.returns({ + getInfo: (key: OrgConfigProperties) => { + switch (key) { + case OrgConfigProperties.TARGET_ORG: + return undefined; + default: + return 'BAD'; + } + }, + reload: reloadSpy + }); + + let expectedConditionReached = false; + const defaultUser = await OrgUtils.getDefaultUser().catch((err) => { + expectedConditionReached = true; + }); + + assert.equal(expectedConditionReached, true); + }); + test('Returns list of sobjects', async () => { const orgStub: SinonStub = sinon.stub(Org, 'create'); const stubConnection = sinon.createStubInstance(Connection); diff --git a/src/utils/orgUtils.ts b/src/utils/orgUtils.ts index 0238ccc..87429d2 100644 --- a/src/utils/orgUtils.ts +++ b/src/utils/orgUtils.ts @@ -75,9 +75,10 @@ export class OrgUtils { const currentUserConfig = aggregator.getInfo( OrgConfigProperties.TARGET_ORG ); - const currentUser = currentUserConfig.value - ? currentUserConfig.value - : 'undefined'; - return Promise.resolve(currentUser.toString()); + + if (currentUserConfig && currentUserConfig.value) { + return Promise.resolve(currentUserConfig.value.toString()); + } + return Promise.reject('no user'); } }