Skip to content

Commit

Permalink
feat: add enableRelateContactToMultipleAccounts as workaround to unre…
Browse files Browse the repository at this point in the history
…liable Metadata (#470)

Co-authored-by: Matthias Rolke <mr.amtrack@gmail.com>
  • Loading branch information
jverelst and amtrack authored Oct 18, 2021
1 parent 185f6f7 commit 32bac9b
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { ReportsAndDashboards as reportsAndDashboards } from './reports-and-dash
import { SalesforceToSalesforce as salesforceToSalesforce } from './salesforce-to-salesforce';
import { Security as security } from './security';

import { RelateContactToMultipleAccounts as relateContactToMultipleAccounts } from './relate-contact-to-multiple-accounts';

export {
relateContactToMultipleAccounts,
activitySettings,
communities,
customerPortal,
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/relate-contact-to-multiple-accounts/disable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "../schema.json",
"settings": {
"relateContactToMultipleAccounts": {
"enabled": false
}
}
}
8 changes: 8 additions & 0 deletions src/plugins/relate-contact-to-multiple-accounts/enable.json
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 src/plugins/relate-contact-to-multiple-accounts/index.e2e-spec.ts
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()
);
});
});
49 changes: 49 additions & 0 deletions src/plugins/relate-contact-to-multiple-accounts/index.ts
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 src/plugins/relate-contact-to-multiple-accounts/schema.json
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"
}
}
}
3 changes: 3 additions & 0 deletions src/plugins/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"properties": {
"settings": {
"properties": {
"relateContactToMultipleAccounts": {
"$ref": "./relate-contact-to-multiple-accounts/schema.json"
},
"highVelocitySalesSettings": {
"$ref": "./high-velocity-sales-settings/schema.json"
},
Expand Down

0 comments on commit 32bac9b

Please sign in to comment.