From b755297b3180c1a4b3a4fc2cebffb2720374b1cf Mon Sep 17 00:00:00 2001 From: Dustin Breese Date: Tue, 13 Jun 2023 15:14:01 -0600 Subject: [PATCH] Updated to not use then() and catch() Ran prettier, too. --- src/commands/authorizeCommand.ts | 49 ++++++++++++-------------- src/commands/briefcaseCommand.ts | 6 ++-- src/commands/deployToOrgCommand.ts | 4 ++- src/commands/landingPageCommand.ts | 26 ++++++++++---- src/commands/templateChooserCommand.ts | 4 ++- src/test/suite/utils/orgUtils.test.ts | 10 +++--- src/test/suite/webviews.test.ts | 23 ++++++------ src/utils/orgUtils.ts | 2 +- src/utils/uiUtils.ts | 8 ++--- src/webviews.ts | 5 ++- 10 files changed, 76 insertions(+), 61 deletions(-) diff --git a/src/commands/authorizeCommand.ts b/src/commands/authorizeCommand.ts index c7bda8e..33d4319 100644 --- a/src/commands/authorizeCommand.ts +++ b/src/commands/authorizeCommand.ts @@ -10,32 +10,29 @@ import { OrgUtils } from '../utils/orgUtils'; export class AuthorizeCommand { static async authorizeToOrg(): Promise { - let userAuthorized = false; - await OrgUtils.getDefaultUser() - .then(() => { - userAuthorized = true; - }) - .catch(async (err) => { - // Ask user to authorize to an org now only if not authorized yet. - const result = await window.showInformationMessage( - l10n.t('Do you want to authorize an Org now?'), - { title: l10n.t('Authorize') }, - { title: l10n.t('No') } - ); + 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( + l10n.t('Do you want to authorize an Org now?'), + { title: l10n.t('Authorize') }, + { title: l10n.t('No') } + ); - if (!result || result.title === l10n.t('No')) { - userAuthorized = 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') } - ); - userAuthorized = true; - } - }); - return Promise.resolve(userAuthorized); + 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); + } + } } } diff --git a/src/commands/briefcaseCommand.ts b/src/commands/briefcaseCommand.ts index 1a56329..38e130b 100644 --- a/src/commands/briefcaseCommand.ts +++ b/src/commands/briefcaseCommand.ts @@ -12,8 +12,10 @@ import { InstructionsWebviewProvider } from '../webviews'; export class BriefcaseCommand { static async setupBriefcase(extensionUri: Uri): Promise { await window.showInformationMessage( - 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.'), + 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') } ); diff --git a/src/commands/deployToOrgCommand.ts b/src/commands/deployToOrgCommand.ts index b24f6dd..0dc20b4 100644 --- a/src/commands/deployToOrgCommand.ts +++ b/src/commands/deployToOrgCommand.ts @@ -13,7 +13,9 @@ export class DeployToOrgCommand { const currentWorkspace = workspace; if (!currentWorkspace.workspaceFolders) { await window.showErrorMessage( - l10n.t('There are no workspace folders defined in your project.'), + l10n.t( + 'There are no workspace folders defined in your project.' + ), { title: l10n.t('OK') } ); return Promise.resolve(false); diff --git a/src/commands/landingPageCommand.ts b/src/commands/landingPageCommand.ts index a5475a2..83197a2 100644 --- a/src/commands/landingPageCommand.ts +++ b/src/commands/landingPageCommand.ts @@ -80,7 +80,9 @@ export class LandingPageCommand { */ static async configureRecordListCard(uem: UEMBuilder): Promise { const selectedItem = await UIUtils.showQuickPick( - l10n.t('Select which sObject you want to display on the Record List.'), + l10n.t( + 'Select which sObject you want to display on the Record List.' + ), l10n.t('Retrieving sObjects from your org, please wait...'), () => { return new Promise(async (resolve, reject) => { @@ -110,13 +112,15 @@ export class LandingPageCommand { const finishedOption: QuickPickItem = { label: l10n.t('-- Finished --'), - detail: l10n.t('I don\'t want any more fields to be displayed.') + detail: l10n.t("I don't want any more fields to be displayed.") }; // Prompt user for up to 3 fields. The first request we will retrieve the fields and show a progress // message const selectedFieldPickItem1 = await UIUtils.showQuickPick( - l10n.t('Select which field you want to display as the primary field.'), + l10n.t( + 'Select which field you want to display as the primary field.' + ), l10n.t('Retrieving list of fields for sObject.'), () => { return new Promise(async (resolve, reject) => { @@ -142,7 +146,9 @@ export class LandingPageCommand { // get optional field 2 -- do not show a progress message. const selectedFieldPickItem2 = await UIUtils.showQuickPick( - l10n.t('Select which field you want to display as the second field (or Finished to skip).'), + l10n.t( + 'Select which field you want to display as the second field (or Finished to skip).' + ), undefined, () => { return new Promise(async (resolve, reject) => { @@ -165,7 +171,9 @@ export class LandingPageCommand { let selectedFieldPickItem3: QuickPickItem; if (selectedFieldPickItem2.label !== finishedOption.label) { selectedFieldPickItem3 = await UIUtils.showQuickPick( - l10n.t('Select which field you want to display as the third field (or Finished to skip).'), + l10n.t( + 'Select which field you want to display as the third field (or Finished to skip).' + ), undefined, () => { return new Promise( @@ -218,7 +226,9 @@ export class LandingPageCommand { const cardTypes: QuickPickItem[] = [ { label: `${LandingPageCommand.GLOBAL_ACTIONS_CARD_LABEL}`, - description: l10n.t('A card showing the LWC Global Quick Actions defined in the org.') + description: l10n.t( + 'A card showing the LWC Global Quick Actions defined in the org.' + ) }, { label: `${LandingPageCommand.RECORD_LIST_CARD_LABEL}`, @@ -226,7 +236,9 @@ const cardTypes: QuickPickItem[] = [ }, { label: `${LandingPageCommand.TIMED_LIST_CARD_LABEL}`, - description: l10n.t('A card showing a list of records filtered and sorted by a date/time range.') + description: l10n.t( + 'A card showing a list of records filtered and sorted by a date/time range.' + ) }, { label: '', diff --git a/src/commands/templateChooserCommand.ts b/src/commands/templateChooserCommand.ts index c93510f..e7e4362 100644 --- a/src/commands/templateChooserCommand.ts +++ b/src/commands/templateChooserCommand.ts @@ -48,7 +48,9 @@ export class TemplateChooserCommand { }, { label: l10n.t('Retail Execution'), - detail: l10n.t('Global quick actions with new Opportunity, new Lead, and more.'), + detail: l10n.t( + 'Global quick actions with new Opportunity, new Lead, and more.' + ), filename: 'landing_page_retail_execution.json' } ]; diff --git a/src/test/suite/utils/orgUtils.test.ts b/src/test/suite/utils/orgUtils.test.ts index 4714909..8295bef 100644 --- a/src/test/suite/utils/orgUtils.test.ts +++ b/src/test/suite/utils/orgUtils.test.ts @@ -68,7 +68,7 @@ suite('Org Utils Test Suite', () => { const reloadSpy = sinon.spy(() => { return Promise.resolve; }); - + const config: SinonStub = sinon.stub(ConfigAggregator, 'create'); config.returns({ getInfo: (key: OrgConfigProperties) => { @@ -87,14 +87,14 @@ suite('Org Utils Test Suite', () => { const defaultUser = await OrgUtils.getDefaultUser(); assert.equal(defaultUser, 'username'); - assert.equal(reloadSpy.called, true, "reload should be invoked"); + 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) => { @@ -109,15 +109,13 @@ suite('Org Utils Test Suite', () => { }); let expectedConditionReached = false; - const defaultUser = await OrgUtils.getDefaultUser() - .catch((err) => { + 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/test/suite/webviews.test.ts b/src/test/suite/webviews.test.ts index 35ac96a..ff50a8e 100644 --- a/src/test/suite/webviews.test.ts +++ b/src/test/suite/webviews.test.ts @@ -13,7 +13,7 @@ import { afterEach, beforeEach } from 'mocha'; import * as fs from 'fs'; suite('InstructionsWebviewProvider Test Suite', () => { - const extensionUri = Uri.parse("file:///tmp/testdir"); + const extensionUri = Uri.parse('file:///tmp/testdir'); beforeEach(function () {}); @@ -22,29 +22,28 @@ suite('InstructionsWebviewProvider Test Suite', () => { }); test('Locale-specific file is returned if it exists', async () => { - const languageStub = sinon.stub(env, "language"); - languageStub.value("es"); + const languageStub = sinon.stub(env, 'language'); + languageStub.value('es'); - const fsExistStub = sinon.stub(fs, "existsSync"); + const fsExistStub = sinon.stub(fs, 'existsSync'); fsExistStub.returns(true); const provider = new InstructionsWebviewProvider(extensionUri); - const path = provider.getLocaleContentPath(extensionUri, "test.html"); + const path = provider.getLocaleContentPath(extensionUri, 'test.html'); - assert.equal(path, "test.es.html"); + assert.equal(path, 'test.es.html'); }); test('Defaults to english file if locale-specific file does not exist.', async () => { - const languageStub = sinon.stub(env, "language"); - languageStub.value("es"); + const languageStub = sinon.stub(env, 'language'); + languageStub.value('es'); - const fsExistStub = sinon.stub(fs, "existsSync"); + const fsExistStub = sinon.stub(fs, 'existsSync'); fsExistStub.returns(false); const provider = new InstructionsWebviewProvider(extensionUri); - const path = provider.getLocaleContentPath(extensionUri, "test.html"); + const path = provider.getLocaleContentPath(extensionUri, 'test.html'); - assert.equal(path, "test.html"); + assert.equal(path, 'test.html'); }); - }); diff --git a/src/utils/orgUtils.ts b/src/utils/orgUtils.ts index 22a1dd9..87429d2 100644 --- a/src/utils/orgUtils.ts +++ b/src/utils/orgUtils.ts @@ -79,6 +79,6 @@ export class OrgUtils { if (currentUserConfig && currentUserConfig.value) { return Promise.resolve(currentUserConfig.value.toString()); } - return Promise.reject("no user"); + return Promise.reject('no user'); } } diff --git a/src/utils/uiUtils.ts b/src/utils/uiUtils.ts index d59a8b0..5411974 100644 --- a/src/utils/uiUtils.ts +++ b/src/utils/uiUtils.ts @@ -13,9 +13,9 @@ import { window, QuickPickItem, QuickPickItemKind, QuickPick } from 'vscode'; export class UIUtils { /** * Wraps the ability to ask user for a selection from a quick pick list. - * + * * @param placeholderMessage Message shown to user in the quick pick text entry box. - * @param progressMessage Message shown while the quick pick is shown, but is not yet enabled due + * @param progressMessage Message shown while the quick pick is shown, but is not yet enabled due * to building a list of options via the callback. * @param optionsCallback Callback used to provide an array of QuickPickItems. * @param ignoreFocusOut Boolean for the ignoreFocusOut option on QuickPick. @@ -40,13 +40,13 @@ export class UIUtils { if (selectedItem) { resolve(selectedItem); } else { - reject("Nothing selected"); + reject('Nothing selected'); } }); quickPick.onDidHide((e) => { quickPick.dispose(); - reject("Hiding"); + reject('Hiding'); }); if (progressMessage) { diff --git a/src/webviews.ts b/src/webviews.ts index fe0850f..f290546 100644 --- a/src/webviews.ts +++ b/src/webviews.ts @@ -53,7 +53,10 @@ export class InstructionsWebviewProvider { this.extensionUri, contentPath ); - const htmlPath = vscode.Uri.joinPath(this.extensionUri, localeContentPath); + const htmlPath = vscode.Uri.joinPath( + this.extensionUri, + localeContentPath + ); const messagingJsPath = vscode.Uri.joinPath( this.extensionUri, MESSAGING_JS_PATH