-
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.
feat: add enableRelateContactToMultipleAccounts as workaround to unre…
…liable Metadata (#470) Co-authored-by: Matthias Rolke <mr.amtrack@gmail.com>
- Loading branch information
Showing
7 changed files
with
141 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "../schema.json", | ||
"settings": { | ||
"relateContactToMultipleAccounts": { | ||
"enabled": 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,8 @@ | ||
{ | ||
"$schema": "../schema.json", | ||
"settings": { | ||
"relateContactToMultipleAccounts": { | ||
"enabled": true | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/plugins/relate-contact-to-multiple-accounts/index.e2e-spec.ts
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,57 @@ | ||
import * as assert from 'assert'; | ||
import * as child from 'child_process'; | ||
import * as path from 'path'; | ||
import { RelateContactToMultipleAccounts } from '.'; | ||
|
||
describe(RelateContactToMultipleAccounts.name, function() { | ||
this.slow('30s'); | ||
this.timeout('2m'); | ||
it('should enable', () => { | ||
const enableCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:apply', | ||
'-f', | ||
path.resolve(path.join(__dirname, 'enable.json')) | ||
]); | ||
assert.deepStrictEqual(enableCmd.status, 0, enableCmd.output.toString()); | ||
assert( | ||
/to 'true'/.test(enableCmd.output.toString()), | ||
enableCmd.output.toString() | ||
); | ||
}); | ||
it('should already be enabled', () => { | ||
const enableCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:apply', | ||
'-f', | ||
path.join(__dirname, 'enable.json') | ||
]); | ||
assert.deepStrictEqual(enableCmd.status, 0, enableCmd.output.toString()); | ||
assert( | ||
/no action necessary/.test(enableCmd.output.toString()), | ||
enableCmd.output.toString() | ||
); | ||
}); | ||
it('should disable', () => { | ||
const disableCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:apply', | ||
'-f', | ||
path.resolve(path.join(__dirname, 'disable.json')) | ||
]); | ||
assert.deepStrictEqual(disableCmd.status, 0, disableCmd.output.toString()); | ||
assert( | ||
/to 'false'/.test(disableCmd.output.toString()), | ||
disableCmd.output.toString() | ||
); | ||
}); | ||
it('should already be disabled', () => { | ||
const disableCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:apply', | ||
'-f', | ||
path.join(__dirname, 'disable.json') | ||
]); | ||
assert.deepStrictEqual(disableCmd.status, 0, disableCmd.output.toString()); | ||
assert( | ||
/no action necessary/.test(disableCmd.output.toString()), | ||
disableCmd.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: 'accounts/accountSetup.apexp' | ||
}; | ||
const SELECTORS = { | ||
ENABLED: 'input[id$=":sharedContactsCheckBox"]', | ||
EDIT_BUTTON: 'input[id$=":edit"]', | ||
SAVE_BUTTON: 'input[id$=":save"]' | ||
}; | ||
|
||
type Config = { | ||
enabled: boolean; | ||
}; | ||
|
||
export class RelateContactToMultipleAccounts extends BrowserforcePlugin { | ||
public async retrieve(definition?: Config): Promise<Config> { | ||
const page = await this.browserforce.openPage(PATHS.BASE); | ||
await page.waitForSelector(SELECTORS.ENABLED); | ||
const response = { | ||
enabled: await page.$eval( | ||
SELECTORS.ENABLED, | ||
(el: HTMLInputElement) => el.checked | ||
) | ||
}; | ||
return response; | ||
} | ||
|
||
public async apply(config: Config): Promise<void> { | ||
const page = await this.browserforce.openPage(PATHS.BASE); | ||
// First we have to click the 'Edit' button, to make the checkbox editable | ||
await page.waitForSelector(SELECTORS.ENABLED); | ||
await page.click(SELECTORS.EDIT_BUTTON); | ||
await page.waitForNavigation(); | ||
// Change the value of the checkbox | ||
await page.waitForSelector(SELECTORS.ENABLED); | ||
await page.$eval( | ||
SELECTORS.ENABLED, | ||
(e: HTMLInputElement, v: boolean) => { | ||
e.checked = v; | ||
}, | ||
config.enabled | ||
); | ||
// Save | ||
await Promise.all([ | ||
page.click(SELECTORS.SAVE_BUTTON) | ||
]); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/plugins/relate-contact-to-multiple-accounts/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,13 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"$id": "https://github.com/amtrack/sfdx-browserforce-plugin/src/plugins/relate-contact-to-multiple-accounts/schema.json", | ||
"title": "RelateContactToMultipleAccounts Settings", | ||
"type": "object", | ||
"properties": { | ||
"enabled": { | ||
"title": "Enable RelateContactToMultipleAccounts", | ||
"description": "This allows you to enable the 'Relate contact to multiple Accounts' in the Account settings. Doing this through the metadata API will not always make the AccountContactRelation object available. Enabling the feature using the setup does always work, therefore this plugin.", | ||
"type": "boolean" | ||
} | ||
} | ||
} |
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