Skip to content

Commit

Permalink
Merge pull request #1 from amtrack/salesforce-to-salesforce
Browse files Browse the repository at this point in the history
implement SalesforceToSalesforce
  • Loading branch information
amtrack authored Jan 29, 2018
2 parents 0bc934a + 0cdbb10 commit 4272b3d
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 5 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 2 additions & 1 deletion commands/shape-apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
70 changes: 70 additions & 0 deletions plugins/salesforce-to-salesforce.js
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions test/fixtures/disable-salesforce-to-salesforce.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"orgPreferences": {
"disabled": ["SalesforceToSalesforce"]
}
}
5 changes: 5 additions & 0 deletions test/fixtures/enable-salesforce-to-salesforce.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"orgPreferences": {
"enabled": ["SalesforceToSalesforce"]
}
}
32 changes: 32 additions & 0 deletions test/salesforce-to-salesforce.js
Original file line number Diff line number Diff line change
@@ -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()));
});
}
);

0 comments on commit 4272b3d

Please sign in to comment.