-
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 #110 from amtrack/feat/enable-critical-updates
feat: implement activating/deactivating critical updates
- Loading branch information
Showing
12 changed files
with
515 additions
and
2 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
14 changes: 14 additions & 0 deletions
14
src/plugins/company-settings/critical-updates/activate-all.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,14 @@ | ||
{ | ||
"$schema": "../../schema.json", | ||
"settings": { | ||
"companySettings": { | ||
"criticalUpdates": [ | ||
{ | ||
"name": "*", | ||
"comment": "Activated by sfdx-browserforce-plugin", | ||
"active": true | ||
} | ||
] | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/plugins/company-settings/critical-updates/deactivate-all.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,14 @@ | ||
{ | ||
"$schema": "../../schema.json", | ||
"settings": { | ||
"companySettings": { | ||
"criticalUpdates": [ | ||
{ | ||
"name": "*", | ||
"comment": "Deactivated by sfdx-browserforce-plugin", | ||
"active": false | ||
} | ||
] | ||
} | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
src/plugins/company-settings/critical-updates/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,122 @@ | ||
import { core } from '@salesforce/command'; | ||
import * as assert from 'assert'; | ||
import * as child from 'child_process'; | ||
import { unlink } from 'fs'; | ||
import * as path from 'path'; | ||
import { file } from 'tmp'; | ||
import { promisify } from 'util'; | ||
import CriticalUpdates from '.'; | ||
const tmpFilePromise = promisify(file); | ||
const fsUnlinkPromise = promisify(unlink); | ||
|
||
describe(CriticalUpdates.name, () => { | ||
let activatableCriticalUpdatesAvailable, | ||
deactivatableCriticalUpdatesAvailable = false; | ||
let stateFileActivation, stateFileDeactivation; | ||
before(async () => { | ||
stateFileActivation = await tmpFilePromise('state1.json'); | ||
stateFileDeactivation = await tmpFilePromise('state2.json'); | ||
}); | ||
after(async () => { | ||
await fsUnlinkPromise(stateFileActivation); | ||
await fsUnlinkPromise(stateFileDeactivation); | ||
}); | ||
it('should list all activatable critical updates', async function() { | ||
this.timeout(1000 * 90); | ||
this.slow(1000 * 30); | ||
const planActivateCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:plan', | ||
'-f', | ||
path.resolve(path.join(__dirname, 'activate-all.json')), | ||
'-s', | ||
stateFileActivation | ||
]); | ||
assert.deepEqual( | ||
planActivateCmd.status, | ||
0, | ||
planActivateCmd.output.toString() | ||
); | ||
let state; | ||
try { | ||
state = await core.fs.readJson(stateFileActivation); | ||
} catch (err) { | ||
assert(false, err); | ||
} | ||
assert(state); | ||
assert(state.settings); | ||
assert(state.settings.companySettings); | ||
assert(state.settings.companySettings.criticalUpdates); | ||
if (state.settings.companySettings.criticalUpdates.length) { | ||
activatableCriticalUpdatesAvailable = state.settings.companySettings.criticalUpdates.some( | ||
item => item.active === false | ||
); | ||
} | ||
}); | ||
it('should activate all available critical updates', function() { | ||
if (!activatableCriticalUpdatesAvailable) { | ||
this.skip(); | ||
} | ||
this.timeout(1000 * 90); | ||
this.slow(1000 * 30); | ||
const activateCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:apply', | ||
'-f', | ||
path.resolve(path.join(__dirname, 'activate-all.json')) | ||
]); | ||
assert.deepEqual(activateCmd.status, 0, activateCmd.output.toString()); | ||
assert( | ||
/changing 'criticalUpdates' to '\[/.test(activateCmd.output.toString()), | ||
activateCmd.output.toString() | ||
); | ||
}); | ||
it('should list all deactivatable critical updates', async function() { | ||
this.timeout(1000 * 90); | ||
this.slow(1000 * 30); | ||
const planDeactivateCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:plan', | ||
'-f', | ||
path.resolve(path.join(__dirname, 'deactivate-all.json')), | ||
'-s', | ||
'/tmp/sfdx-browserforce-plugin.state.json' | ||
]); | ||
assert.deepEqual( | ||
planDeactivateCmd.status, | ||
0, | ||
planDeactivateCmd.output.toString() | ||
); | ||
let state; | ||
try { | ||
state = await core.fs.readJson( | ||
'/tmp/sfdx-browserforce-plugin.state.json' | ||
); | ||
} catch (err) { | ||
assert(false, err); | ||
} | ||
assert(state); | ||
assert(state.settings); | ||
assert(state.settings.companySettings); | ||
assert(state.settings.companySettings.criticalUpdates); | ||
if (state.settings.companySettings.criticalUpdates.length) { | ||
deactivatableCriticalUpdatesAvailable = state.settings.companySettings.criticalUpdates.some( | ||
item => item.active === true | ||
); | ||
} | ||
}); | ||
it('should deactivate all deactivatable critical updates', function() { | ||
if (!deactivatableCriticalUpdatesAvailable) { | ||
this.skip(); | ||
} | ||
this.timeout(1000 * 90); | ||
this.slow(1000 * 30); | ||
const deactivateCmd = child.spawnSync(path.resolve('bin', 'run'), [ | ||
'browserforce:apply', | ||
'-f', | ||
path.resolve(path.join(__dirname, 'deactivate-all.json')) | ||
]); | ||
assert.deepEqual(deactivateCmd.status, 0, deactivateCmd.output.toString()); | ||
assert( | ||
/changing 'criticalUpdates' to '\[/.test(deactivateCmd.output.toString()), | ||
deactivateCmd.output.toString() | ||
); | ||
}); | ||
}); |
153 changes: 153 additions & 0 deletions
153
src/plugins/company-settings/critical-updates/index.test.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,153 @@ | ||
import * as assert from 'assert'; | ||
import CriticalUpdates from '.'; | ||
|
||
interface TestData { | ||
name: string | string[]; | ||
active: boolean; | ||
comment?: string; | ||
} | ||
interface Test { | ||
description: string; | ||
source: TestData[]; | ||
target: TestData[]; | ||
expected: TestData[]; | ||
skip?: boolean; | ||
} | ||
|
||
const tests: Test[] = [ | ||
{ | ||
description: 'should return no change', | ||
source: [ | ||
{ | ||
name: 'Update 1', | ||
active: true | ||
}, | ||
{ | ||
name: 'Update 2', | ||
active: true | ||
}, | ||
{ | ||
name: 'Update 3', | ||
active: true | ||
} | ||
], | ||
target: [ | ||
{ | ||
name: 'Update 2', | ||
active: true, | ||
comment: 'This is a comment' | ||
} | ||
], | ||
expected: [] | ||
}, | ||
{ | ||
description: 'should match a specific item', | ||
source: [ | ||
{ | ||
name: 'Update 1', | ||
active: false | ||
}, | ||
{ | ||
name: 'Update 2', | ||
active: false | ||
}, | ||
{ | ||
name: 'Update 3', | ||
active: false | ||
} | ||
], | ||
target: [ | ||
{ | ||
name: 'Update 2', | ||
active: true, | ||
comment: 'This is a comment' | ||
} | ||
], | ||
expected: [ | ||
{ | ||
name: 'Update 2', | ||
active: true, | ||
comment: 'This is a comment' | ||
} | ||
] | ||
}, | ||
{ | ||
description: 'should match all inactive items', | ||
source: [ | ||
{ | ||
name: 'Update 1', | ||
active: true | ||
}, | ||
{ | ||
name: 'Update 2', | ||
active: false | ||
}, | ||
{ | ||
name: 'Update 3', | ||
active: true | ||
} | ||
], | ||
target: [ | ||
{ | ||
name: '*', | ||
active: true, | ||
comment: 'This is a comment' | ||
} | ||
], | ||
expected: [ | ||
{ | ||
name: 'Update 2', | ||
active: true, | ||
comment: 'This is a comment' | ||
} | ||
] | ||
}, | ||
{ | ||
description: 'should handle multiple patterns', | ||
source: [ | ||
{ | ||
name: 'Update 1', | ||
active: false | ||
}, | ||
{ | ||
name: 'Update 2', | ||
active: false | ||
}, | ||
{ | ||
name: 'Update 3', | ||
active: false | ||
} | ||
], | ||
target: [ | ||
{ | ||
name: ['*', '!Update 2'], | ||
active: true, | ||
comment: 'This is a comment' | ||
} | ||
], | ||
expected: [ | ||
{ | ||
name: 'Update 1', | ||
active: true, | ||
comment: 'This is a comment' | ||
}, | ||
{ | ||
name: 'Update 3', | ||
active: true, | ||
comment: 'This is a comment' | ||
} | ||
] | ||
} | ||
]; | ||
|
||
describe('CriticalUpdates', () => { | ||
describe('diff()', () => { | ||
const p = new CriticalUpdates(null, null); | ||
for (const t of tests) { | ||
(t.skip ? it.skip : it)(t.description, () => { | ||
const actual = p.diff(t.source, t.target); | ||
assert.deepEqual(actual, t.expected); | ||
}); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.