-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #629 from amtrack/feat/slack
feat: add basic Slack Apps Setup
- Loading branch information
Showing
8 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,9 @@ | |
}, | ||
"security": { | ||
"$ref": "./security/schema.json" | ||
}, | ||
"slack": { | ||
"$ref": "./slack/schema.json" | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"$schema": "../schema.json", | ||
"settings": { | ||
"slack": { | ||
"agreeToTermsAndConditions": true, | ||
"enableSalesCloudForSlack": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"$schema": "../schema.json", | ||
"settings": { | ||
"slack": { | ||
"agreeToTermsAndConditions": true, | ||
"enableSalesCloudForSlack": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |