Skip to content

Commit

Permalink
feat: add basic Slack Apps Setup
Browse files Browse the repository at this point in the history
  • Loading branch information
amtrack committed Oct 18, 2024
1 parent e1f80b5 commit c4cbc9f
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { RelateContactToMultipleAccounts as relateContactToMultipleAccounts } fr
import { ReportsAndDashboards as reportsAndDashboards } from './reports-and-dashboards';
import { SalesforceToSalesforce as salesforceToSalesforce } from './salesforce-to-salesforce';
import { Security as security } from './security';
import { Slack as slack } from './slack';
import { CompanyInformation as companyInformation } from './company-information';
import { LinkedInSalesNavigatorSettings as linkedInSalesNavigatorSettings } from './linkedin-sales-navigator-settings';

Expand All @@ -34,6 +35,7 @@ export {
reportsAndDashboards,
salesforceToSalesforce,
security,
slack,
companyInformation,
linkedInSalesNavigatorSettings
};
3 changes: 3 additions & 0 deletions src/plugins/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
},
"security": {
"$ref": "./security/schema.json"
},
"slack": {
"$ref": "./slack/schema.json"
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/slack/disable-sales.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "../schema.json",
"settings": {
"slack": {
"agreeToTermsAndConditions": true,
"enableSalesCloudForSlack": false
}
}
}
9 changes: 9 additions & 0 deletions src/plugins/slack/enable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "../schema.json",
"settings": {
"slack": {
"agreeToTermsAndConditions": true,
"enableSalesCloudForSlack": true
}
}
}
47 changes: 47 additions & 0 deletions src/plugins/slack/index.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import assert from 'assert';
import { type Config, Slack } from '.';

describe(Slack.name, function () {
let plugin: Slack;
before(() => {
plugin = new Slack(global.bf);
});

const configEnable: Config = {
agreeToTermsAndConditions: true,
enableSalesCloudForSlack: true
};
const configDisabledSalesCloud: Config = {
agreeToTermsAndConditions: true,
enableSalesCloudForSlack: false
};
const configDisabled: Config = {
agreeToTermsAndConditions: false,
enableSalesCloudForSlack: false
};
it('should accept terms and conditions', async () => {
await plugin.run(configEnable);
});
it('should already be accepted', async () => {
const res = await plugin.run(configEnable);
assert.deepStrictEqual(res, { message: 'no action necessary' });
});
it('should disable Sales Cloud for Slack', async () => {
await plugin.run(configDisabledSalesCloud);
});
it('should already be disabled', async () => {
const res = await plugin.run(configDisabledSalesCloud);
assert.deepStrictEqual(res, { message: 'no action necessary' });
});
it('should fail to unaccept terms and conditions', async () => {
let err;
try {
await plugin.apply(configDisabled);
} catch (e) {
err = e;
}
assert.throws(() => {
throw err;
}, /cannot be unaccepted/);
});
});
55 changes: 55 additions & 0 deletions src/plugins/slack/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { BrowserforcePlugin } from '../../plugin';

const PATHS = {
BASE: 'lightning/setup/SlackSetupAssistant/home'
};
const SELECTORS = {
TOS_LIGHTNING_INPUT:
'pierce/setup_service-slack-setup-assistant-container setup_service-slack-agree-to-terms lightning-input',
SALES_CLOUD_FOR_SLACK_TOGGLE:
'pierce/setup_service-slack-setup-assistant-container setup_service-stage setup_service-steps setup_service-step lightning-input:has(lightning-primitive-input-toggle input[name="SlkSetupStepSalesCloudForSlack"])',
TOAST_MESSAGE: 'div[id^="toastDescription"]'
};

export type Config = {
agreeToTermsAndConditions: boolean;
enableSalesCloudForSlack: boolean;
};

export class Slack extends BrowserforcePlugin {
public async retrieve(definition?: Config): Promise<Config> {
const page = await this.browserforce.openPage(PATHS.BASE);
await page.waitForSelector(SELECTORS.TOS_LIGHTNING_INPUT, { visible: true });
await page.waitForSelector(SELECTORS.SALES_CLOUD_FOR_SLACK_TOGGLE, { visible: true });
const response = {
agreeToTermsAndConditions: await page.$eval(SELECTORS.TOS_LIGHTNING_INPUT, (el) => el.hasAttribute('checked')),
enableSalesCloudForSlack: await page.$eval(SELECTORS.SALES_CLOUD_FOR_SLACK_TOGGLE, (el) =>
el.hasAttribute('checked')
)
};
await page.close();
return response;
}

public async apply(config: Config): Promise<void> {
if (config.agreeToTermsAndConditions === false) {
throw new Error('terms and conditions cannot be unaccepted once accepted');
}
const state = await this.retrieve();
const page = await this.browserforce.openPage(PATHS.BASE);
await page.waitForSelector(SELECTORS.TOS_LIGHTNING_INPUT, { visible: true });
if (state.agreeToTermsAndConditions !== config.agreeToTermsAndConditions) {
await Promise.all([page.waitForSelector(SELECTORS.TOAST_MESSAGE), page.click(SELECTORS.TOS_LIGHTNING_INPUT)]);
await page.waitForSelector(SELECTORS.TOAST_MESSAGE, { hidden: true });
}
await page.waitForSelector(SELECTORS.SALES_CLOUD_FOR_SLACK_TOGGLE, { visible: true });
if (state.enableSalesCloudForSlack !== config.enableSalesCloudForSlack) {
await Promise.all([
page.waitForSelector(SELECTORS.TOAST_MESSAGE),
page.click(SELECTORS.SALES_CLOUD_FOR_SLACK_TOGGLE)
]);
await page.waitForSelector(SELECTORS.TOAST_MESSAGE, { hidden: true });
}
await page.close();
}
}
17 changes: 17 additions & 0 deletions src/plugins/slack/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://github.com/amtrack/sfdx-browserforce-plugin/src/plugins/slack/schema.json",
"title": "Slack Apps Setup",
"type": "object",
"properties": {
"agreeToTermsAndConditions": {
"title": "Agree to Termns and Conditions",
"description": "Once the terms have been accepted, this cannot be reverted.",
"type": "boolean"
},
"enableSalesCloudForSlack": {
"title": "Enable the 'Sales Cloud for Slack' Slack App",
"type": "boolean"
}
}
}

0 comments on commit c4cbc9f

Please sign in to comment.