-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(RuleEngine): trigger order on record triggered flows
- Loading branch information
Showing
5 changed files
with
225 additions
and
1 deletion.
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
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,45 @@ | ||
import * as core from "../internals/internals"; | ||
import { RuleCommon } from "../models/RuleCommon"; | ||
|
||
export class TriggerOrder extends RuleCommon implements core.IRuleDefinition { | ||
protected qualifiedRecordTriggerTypes: Set<string> = new Set<string>(["Create", "Update"]); | ||
|
||
constructor() { | ||
super( | ||
{ | ||
name: "TriggerOrder", | ||
label: "Trigger Order", | ||
description: | ||
"With flow trigger ordering, introduced in Spring '22, admins can now assign a priority value to their flows and guarantee their execution order. This priority value is not an absolute value, so the values need not be sequentially numbered as 1, 2, 3, and so on.", | ||
supportedTypes: [core.FlowType.autolaunchedType], | ||
docRefs: [ | ||
{ | ||
label: "Learn more about flow ordering orchestration", | ||
path: "https://architect.salesforce.com/decision-guides/trigger-automation#Ordering___Orchestration", | ||
}, | ||
], | ||
isConfigurable: false, | ||
autoFixable: false, | ||
}, | ||
{ severity: "warning" } | ||
); | ||
} | ||
|
||
public execute(flow: core.Flow): core.RuleResult { | ||
const results: core.ResultDetails[] = []; | ||
|
||
const qualifiedFlowType = "object" in flow.start; | ||
|
||
if (!qualifiedFlowType) { | ||
return new core.RuleResult(this, results); | ||
} | ||
|
||
results.push( | ||
new core.ResultDetails( | ||
new core.FlowAttribute("TriggerOrder", "TriggerOrder", "10, 20, 30 ...") | ||
) | ||
); | ||
|
||
return new core.RuleResult(this, results); | ||
} | ||
} |
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,174 @@ | ||
import "mocha"; | ||
|
||
import { ParsedFlow } from "../src/main/models/ParsedFlow"; | ||
import { TriggerOrder } from "../src/main/rules/TriggerOrder"; | ||
import { RuleResult, Flow, parse, scan, ScanResult } from "../src"; | ||
import * as path from "path-browserify"; | ||
|
||
describe("TriggerOrder", () => { | ||
let expect; | ||
let rule; | ||
before(async () => { | ||
expect = (await import("chai")).expect; | ||
rule = new TriggerOrder(); | ||
}); | ||
|
||
it("should not trigger from default configuration on store", async () => { | ||
let example_uri1 = path.join(__dirname, "./xmlfiles/Same_Record_Field_Updates.flow-meta.xml"); | ||
let flows = await parse([example_uri1]); | ||
const ruleConfig = { | ||
rules: {}, | ||
exceptions: {}, | ||
}; | ||
const results: ScanResult[] = scan(flows, ruleConfig); | ||
const scanResults = results.pop(); | ||
|
||
scanResults?.ruleResults.forEach((rule) => { | ||
expect(rule.occurs).to.be.false; | ||
}); | ||
}); | ||
|
||
it("should trigger when opt-in configuration", async () => { | ||
let example_uri1 = path.join(__dirname, "./xmlfiles/Same_Record_Field_Updates.flow-meta.xml"); | ||
let flows = await parse([example_uri1]); | ||
const ruleConfig = { | ||
rules: { | ||
TriggerOrder: { | ||
severity: "error", | ||
}, | ||
}, | ||
exceptions: {}, | ||
}; | ||
const results: ScanResult[] = scan(flows, ruleConfig); | ||
const scanResults = results.pop(); | ||
|
||
const expectedRule = scanResults?.ruleResults.find((rule) => rule.ruleName === "TriggerOrder"); | ||
expect(expectedRule).to.be.ok; | ||
expect(expectedRule?.occurs).to.be.true; | ||
expect(expectedRule?.details[0].details).to.deep.eq({ expression: "10, 20, 30 ..." }); | ||
}); | ||
|
||
it("should flag trigger order when not present", async () => { | ||
const testData: ParsedFlow = { | ||
flow: { | ||
start: { | ||
locationX: "50", | ||
locationY: "0", | ||
connector: { targetReference: "Update_triggering_records" }, | ||
object: "Account", | ||
recordTriggerType: "Create", | ||
triggerType: "RecordBeforeSave", | ||
}, | ||
elements: [ | ||
{ | ||
element: { | ||
locationX: "50", | ||
locationY: "0", | ||
connector: { targetReference: "Update_triggering_records" }, | ||
object: "Account", | ||
recordTriggerType: "Create", | ||
triggerType: "RecordBeforeSave", | ||
}, | ||
subtype: "start", | ||
metaType: "node", | ||
connectors: [ | ||
{ | ||
element: { targetReference: "Update_triggering_records" }, | ||
processed: false, | ||
type: "connector", | ||
reference: "Update_triggering_records", | ||
}, | ||
], | ||
name: "flowstart", | ||
locationX: "50", | ||
locationY: "0", | ||
}, | ||
], | ||
}, | ||
} as {} as ParsedFlow; | ||
|
||
const ruleResult: RuleResult = rule.execute(testData.flow as Flow); | ||
|
||
expect(ruleResult.occurs).to.be.true; | ||
}); | ||
|
||
it("should not flag trigger order when present", async () => { | ||
const testData: ParsedFlow = { | ||
flow: { | ||
triggerOrder: 10, | ||
start: { | ||
locationX: "50", | ||
locationY: "0", | ||
connector: { targetReference: "Update_triggering_records" }, | ||
object: "Account", | ||
recordTriggerType: "Create", | ||
triggerType: "RecordBeforeSave", | ||
}, | ||
elements: [ | ||
{ | ||
element: { | ||
locationX: "50", | ||
locationY: "0", | ||
connector: { targetReference: "Update_triggering_records" }, | ||
object: "Account", | ||
recordTriggerType: "Create", | ||
triggerType: "RecordBeforeSave", | ||
}, | ||
subtype: "start", | ||
metaType: "node", | ||
connectors: [ | ||
{ | ||
element: { targetReference: "Update_triggering_records" }, | ||
processed: false, | ||
type: "connector", | ||
reference: "Update_triggering_records", | ||
}, | ||
], | ||
name: "flowstart", | ||
locationX: "50", | ||
locationY: "0", | ||
}, | ||
], | ||
}, | ||
} as {} as ParsedFlow; | ||
|
||
const ruleResult: RuleResult = rule.execute(testData.flow as Flow); | ||
|
||
expect(ruleResult.occurs).to.be.true; | ||
}); | ||
|
||
it("should not flag trigger order when autolaunched flow", async () => { | ||
const testData: ParsedFlow = { | ||
flow: { | ||
start: { | ||
locationX: "50", | ||
locationY: "0", | ||
connector: { targetReference: "Update_triggering_records" }, | ||
}, | ||
elements: [ | ||
{ | ||
element: { | ||
description: "test", | ||
name: "Update_triggering_records", | ||
label: "Update triggering records", | ||
locationX: "176", | ||
locationY: "287", | ||
inputAssignments: { field: "Active__c", value: { stringValue: "Yes" } }, | ||
inputReference: "$Record", | ||
}, | ||
subtype: "recordUpdates", | ||
metaType: "node", | ||
connectors: [], | ||
name: "Update_triggering_records", | ||
locationX: "176", | ||
locationY: "287", | ||
}, | ||
], | ||
}, | ||
} as {} as ParsedFlow; | ||
|
||
const ruleResult: RuleResult = rule.execute(testData.flow as Flow); | ||
|
||
expect(ruleResult.occurs).to.be.false; | ||
}); | ||
}); |