-
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 #497 from gavinhughpalmer/master
- Loading branch information
Showing
11 changed files
with
196 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ | |
/tmp | ||
node_modules | ||
/.sfdx | ||
/.sf | ||
|
||
.vscode/settings.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
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,8 @@ | ||
{ | ||
"$schema": "../schema.json", | ||
"settings": { | ||
"emailDeliverability": { | ||
"accessLevel": "All email" | ||
} | ||
} | ||
} |
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,94 @@ | ||
import * as assert from 'assert'; | ||
import * as child from 'child_process'; | ||
import * as path from 'path'; | ||
import { EmailDeliverability } from '.'; | ||
|
||
describe(EmailDeliverability.name, function() { | ||
this.slow('30s'); | ||
this.timeout('2m'); | ||
// Note order is important here, the scratch org will be created with all access set, I have placed last so if a scratch is reused at least it is in the same state | ||
it('should set "no access"', () => { | ||
const applyNoAccessCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:apply', | ||
'-f', | ||
path.resolve(path.join(__dirname, 'no-access.json')) | ||
]); | ||
assert.deepStrictEqual(applyNoAccessCmd.status, 0, applyNoAccessCmd.output.toString()); | ||
assert( | ||
/to '"No access"'/.test(applyNoAccessCmd.output.toString()), | ||
applyNoAccessCmd.output.toString() | ||
); | ||
}); | ||
it('should already be set to "no access"', () => { | ||
const applyNoAccessCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:apply', | ||
'-f', | ||
path.join(__dirname, 'no-access.json') | ||
]); | ||
assert.deepStrictEqual(applyNoAccessCmd.status, 0, applyNoAccessCmd.output.toString()); | ||
assert( | ||
/no action necessary/.test(applyNoAccessCmd.output.toString()), | ||
applyNoAccessCmd.output.toString() | ||
); | ||
}); | ||
it('should set "system only"', () => { | ||
const systemEmailCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:apply', | ||
'-f', | ||
path.resolve(path.join(__dirname, 'system.json')) | ||
]); | ||
assert.deepStrictEqual(systemEmailCmd.status, 0, systemEmailCmd.output.toString()); | ||
assert( | ||
/to '"System email only"'/.test(systemEmailCmd.output.toString()), | ||
systemEmailCmd.output.toString() | ||
); | ||
}); | ||
it('should already be set to no access', () => { | ||
const systemEmailCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:apply', | ||
'-f', | ||
path.join(__dirname, 'system.json') | ||
]); | ||
assert.deepStrictEqual(systemEmailCmd.status, 0, systemEmailCmd.output.toString()); | ||
assert( | ||
/no action necessary/.test(systemEmailCmd.output.toString()), | ||
systemEmailCmd.output.toString() | ||
); | ||
}); | ||
it('should apply all email', () => { | ||
const applyAllCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:apply', | ||
'-f', | ||
path.resolve(path.join(__dirname, 'all.json')) | ||
]); | ||
assert.deepStrictEqual(applyAllCmd.status, 0, applyAllCmd.output.toString()); | ||
assert( | ||
/to '"All email"'/.test(applyAllCmd.output.toString()), | ||
applyAllCmd.output.toString() | ||
); | ||
}); | ||
it('should already be have all enabled', () => { | ||
const applyAllCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:apply', | ||
'-f', | ||
path.join(__dirname, 'all.json') | ||
]); | ||
assert.deepStrictEqual(applyAllCmd.status, 0, applyAllCmd.output.toString()); | ||
assert( | ||
/no action necessary/.test(applyAllCmd.output.toString()), | ||
applyAllCmd.output.toString() | ||
); | ||
}); | ||
it('should error on invalid input', () => { | ||
const systemEmailCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:apply', | ||
'-f', | ||
path.join(__dirname, 'invalid.json') | ||
]); | ||
assert.notDeepStrictEqual(systemEmailCmd.status, 0, systemEmailCmd.output.toString()); | ||
assert( | ||
/Invalid email access level/.test(systemEmailCmd.output.toString()), | ||
systemEmailCmd.output.toString() | ||
); | ||
}); | ||
}); |
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,49 @@ | ||
import { BrowserforcePlugin } from '../../plugin'; | ||
|
||
const PATHS = { | ||
BASE: 'email-admin/editOrgEmailSettings.apexp' | ||
}; | ||
const SELECTORS = { | ||
ACCESS_LEVEL: 'select[id$=":sendEmailAccessControlSelect"]', | ||
CONFIRM_MESSAGE: 'span[id$=":successText"]', | ||
SAVE_BUTTON: 'input[id$=":saveBtn"]' | ||
}; | ||
const ACCESS_LEVEL_VALUES = new Map([ | ||
['No access', '0',], | ||
['System email only', '1',], | ||
['All email', '2'] | ||
]); | ||
|
||
type Config = { | ||
accessLevel: string; | ||
}; | ||
|
||
export class EmailDeliverability extends BrowserforcePlugin { | ||
public async retrieve(definition?: Config): Promise<Config> { | ||
if (!ACCESS_LEVEL_VALUES.has(definition.accessLevel)) { | ||
throw new Error(`Invalid email access level ${definition.accessLevel}`); | ||
} | ||
const page = await this.browserforce.openPage(PATHS.BASE); | ||
await page.waitForSelector(SELECTORS.ACCESS_LEVEL); | ||
const selectedOptions = await page.$$eval( | ||
`${SELECTORS.ACCESS_LEVEL} > option[selected]`, | ||
options => options.map(option => option.textContent) | ||
); | ||
if (!selectedOptions) { | ||
throw new Error('Selected access level not found...') | ||
} | ||
return { | ||
accessLevel: selectedOptions[0] | ||
};; | ||
} | ||
|
||
public async apply(config: Config): Promise<void> { | ||
const page = await this.browserforce.openPage(PATHS.BASE); | ||
await page.waitForSelector(SELECTORS.ACCESS_LEVEL); | ||
await page.select(SELECTORS.ACCESS_LEVEL, ACCESS_LEVEL_VALUES.get(config.accessLevel)); | ||
await Promise.all([ | ||
page.waitForSelector(SELECTORS.CONFIRM_MESSAGE), | ||
page.click(SELECTORS.SAVE_BUTTON) | ||
]); | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"$schema": "../schema.json", | ||
"settings": { | ||
"emailDeliverability": { | ||
"accessLevel": "Invalid" | ||
} | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"$schema": "../schema.json", | ||
"settings": { | ||
"emailDeliverability": { | ||
"accessLevel": "No access" | ||
} | ||
} | ||
} |
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,14 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"$id": "https://github.com/amtrack/sfdx-browserforce-plugin/src/plugins/density-settings/schema.json", | ||
"title": "Email Deliverability Settings", | ||
"type": "object", | ||
"properties": { | ||
"accessLevel": { | ||
"title": "Access Level", | ||
"description": "Choose the email Deliverability Access Level required", | ||
"type": "string", | ||
"enum": ["No access", "System email only", "All email"] | ||
} | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"$schema": "../schema.json", | ||
"settings": { | ||
"emailDeliverability": { | ||
"accessLevel": "System email only" | ||
} | ||
} | ||
} |
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