Skip to content

Commit

Permalink
tests(RuleEngine): add unit tests for same record field updates
Browse files Browse the repository at this point in the history
  • Loading branch information
junners committed Nov 16, 2024
1 parent 0eacd2f commit 9d82827
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/rules/SameRecordFieldUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,27 @@ export class SameRecordFieldUpdates extends RuleCommon implements core.IRuleDefi
);

if (!isBeforeSaveType || !isQualifiedTriggerTypes) {
return new core.RuleResult(this, []);
return new core.RuleResult(this, results);
}

const resultDetails: core.ResultDetails[] = [];

const potentialElements = flow.elements?.filter(
(node) => node.subtype === "recordUpdates"
) as core.FlowNode[];

if (potentialElements == null || typeof potentialElements[Symbol.iterator] !== "function") {
return new core.RuleResult(this, results);
}

for (const node of potentialElements) {
if (
typeof node.element === "object" &&
"inputReference" in node.element &&
node.element.inputReference === "$Record"
) {
resultDetails.push(new core.ResultDetails(node));
results.push(new core.ResultDetails(node));
}
}

return new core.RuleResult(this, resultDetails);
return new core.RuleResult(this, results);
}
}
72 changes: 72 additions & 0 deletions tests/SameRecordFieldUpdates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,76 @@ describe("SameRecordFieldUpdates", () => {
expect(expectedRule).to.be.ok;
expect(expectedRule?.occurs).to.be.true;
});

it("should not error when start element is not existing", async () => {
const testData: ParsedFlow = {
flow: {
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",
},
{
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.false;
});

it("should not error when elements are missing", async () => {
const testData: ParsedFlow = {
flow: {
start: {
locationX: "50",
locationY: "0",
connector: { targetReference: "Update_triggering_records" },
object: "Account",
recordTriggerType: "Create",
triggerType: "RecordBeforeSave",
},
},
} as {} as ParsedFlow;

const ruleResult: RuleResult = rule.execute(testData.flow as Flow);

expect(ruleResult.occurs).to.be.false;
});
});

0 comments on commit 9d82827

Please sign in to comment.