Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(RuleEngine): add unit tests for same record field updates #142

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
});
});