-
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 #1 from amtrack/salesforce-to-salesforce
implement SalesforceToSalesforce
- Loading branch information
Showing
6 changed files
with
115 additions
and
5 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
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,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; |
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,5 @@ | ||
{ | ||
"orgPreferences": { | ||
"disabled": ["SalesforceToSalesforce"] | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"orgPreferences": { | ||
"enabled": ["SalesforceToSalesforce"] | ||
} | ||
} |
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,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())); | ||
}); | ||
} | ||
); |