From 0cdbb105274c9991d7121d58fea6c870c4f7f74f Mon Sep 17 00:00:00 2001 From: Matthias Rolke Date: Mon, 29 Jan 2018 17:16:42 +0100 Subject: [PATCH] implement SalesforceToSalesforce --- README.md | 5 +- commands/shape-apply.js | 3 +- plugins/salesforce-to-salesforce.js | 70 +++++++++++++++++++ .../disable-salesforce-to-salesforce.json | 5 ++ .../enable-salesforce-to-salesforce.json | 5 ++ test/salesforce-to-salesforce.js | 32 +++++++++ 6 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 plugins/salesforce-to-salesforce.js create mode 100644 test/fixtures/disable-salesforce-to-salesforce.json create mode 100644 test/fixtures/enable-salesforce-to-salesforce.json create mode 100644 test/salesforce-to-salesforce.js diff --git a/README.md b/README.md index 1f7445b2..646997d8 100644 --- a/README.md +++ b/README.md @@ -66,15 +66,12 @@ Sharing Settings * `ExternalSharing` * `CustomerPortal` (Warning: cannot be disabled once enabled) +* `SalesforceToSalesforce` (Warning: cannot be disabled once enabled) ## Planned Features (contributions welcome) **Org Preferences** -General Settings - -* `SalesforceToSalesforce` - Live Agent Settings * `LiveAgent` diff --git a/commands/shape-apply.js b/commands/shape-apply.js index e14bf1e8..bc6db41a 100644 --- a/commands/shape-apply.js +++ b/commands/shape-apply.js @@ -36,7 +36,8 @@ module.exports = { // headless: !(process.env.BROWSER_DEBUG === "true"); const DRIVERS = { ExternalSharing: require("../plugins/external-sharing"), - CustomerPortal: require("../plugins/customer-portal") + CustomerPortal: require("../plugins/customer-portal"), + SalesforceToSalesforce: require("../plugins/salesforce-to-salesforce") }; const targetUsername = context.flags.targetusername; diff --git a/plugins/salesforce-to-salesforce.js b/plugins/salesforce-to-salesforce.js new file mode 100644 index 00000000..b9c7840b --- /dev/null +++ b/plugins/salesforce-to-salesforce.js @@ -0,0 +1,70 @@ +/* eslint-disable capitalized-comments */ +// const CONTENT_SELECTOR = "#contentWrapper"; +const BASE_SELECTOR = "table.detailList"; + +class Plugin { + constructor(browser, creds) { + this.name = "Salesforce to Salesforce"; + this.browser = browser; + this.creds = creds; + this.baseUrl = creds.instanceUrl + "/_ui/s2s/ui/PartnerNetworkEnable/e"; + this.baseSelector = BASE_SELECTOR; + this.property = { + name: "enabled", + label: "Enabled", + selector: "#penabled" + }; + } + + async retrieve() { + let page = await this.browser.newPage(); + await page.goto(this.baseUrl); + await page.waitFor(this.baseSelector); + const inputEnable = await page.$(this.property.selector); + let response = {}; + if (inputEnable) { + response[this.property.name] = await page.$eval( + this.property.selector, + el => el.checked + ); + } else { + // already enabled + response[this.property.name] = true; + } + await page.close(); + return response; + } + + async apply(actions) { + if (!actions || !actions.length) { + return; + } + let action = actions[0]; + if (action.name === "enabled" && action.targetValue === false) { + console.error(`SKIPPED: ${this.name} cannot be disabled`); + return; + } + let page = await this.browser.newPage(); + await page.goto(this.baseUrl); + await page.waitFor(this.property.selector); + await page.evaluate( + data => { + // eslint-disable-next-line no-undef + var checkbox = document.querySelector(data.action.selector); + checkbox.checked = data.action.targetValue; + }, + { + action + } + ); + await page.click("input[title='Save']"); + await page.waitForNavigation(); + await page.close(); + } +} + +Plugin.schema = { + properties: [{ name: "enabled", label: "Enabled", selector: "#penabled" }] +}; + +module.exports = Plugin; diff --git a/test/fixtures/disable-salesforce-to-salesforce.json b/test/fixtures/disable-salesforce-to-salesforce.json new file mode 100644 index 00000000..5b91cd78 --- /dev/null +++ b/test/fixtures/disable-salesforce-to-salesforce.json @@ -0,0 +1,5 @@ +{ + "orgPreferences": { + "disabled": ["SalesforceToSalesforce"] + } +} diff --git a/test/fixtures/enable-salesforce-to-salesforce.json b/test/fixtures/enable-salesforce-to-salesforce.json new file mode 100644 index 00000000..01cfa4ec --- /dev/null +++ b/test/fixtures/enable-salesforce-to-salesforce.json @@ -0,0 +1,5 @@ +{ + "orgPreferences": { + "enabled": ["SalesforceToSalesforce"] + } +} diff --git a/test/salesforce-to-salesforce.js b/test/salesforce-to-salesforce.js new file mode 100644 index 00000000..960cb47c --- /dev/null +++ b/test/salesforce-to-salesforce.js @@ -0,0 +1,32 @@ +const assert = require("assert"); +const child = require("child_process"); +const path = require("path"); + +(process.env.TEST_INTEGRATION === "true" ? describe : describe.skip)( + "SalesforceToSalesforce", + () => { + it("should enable salesforce to salesforce", function() { + this.timeout(1000 * 120); + this.slow(1000 * 30); + var enableCmd = child.spawnSync("sfdx", [ + "browserforce:shape:apply", + "-f", + path.resolve( + path.join("test", "fixtures", "enable-salesforce-to-salesforce.json") + ) + ]); + assert.deepEqual(enableCmd.status, 0, enableCmd.stderr); + assert(/to 'true'/.test(enableCmd.stdout.toString())); + var disableCmd = child.spawnSync("sfdx", [ + "browserforce:shape:apply", + "-f", + path.resolve( + path.join("test", "fixtures", "disable-salesforce-to-salesforce.json") + ) + ]); + assert.deepEqual(disableCmd.status, 0, disableCmd.stderr); + assert(/to 'false'/.test(disableCmd.stdout.toString())); + assert(/cannot be disabled/.test(disableCmd.stderr.toString())); + }); + } +);