Skip to content

Commit

Permalink
DML/SOQL StatementsInLoop exclude visual flows
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenHalman committed Mar 20, 2024
1 parent 82daf16 commit db12bf2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/main/libs/ScanFlows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export function ScanFlows(flows: core.Flow[], rulesConfig?: Map<string, {}>): co
} catch (error) {
throw new error("Something went wrong while executing " + rule.name + " in the Flow: '" + flow.name + "'");
}
} else {
ruleResults.push(new core.RuleResult(rule, []));
}
}
flowResults.push(new core.ScanResult(flow, ruleResults));
Expand Down
2 changes: 1 addition & 1 deletion src/main/rules/DMLStatementInLoop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class DMLStatementInLoop extends RuleCommon implements core.IRuleDefiniti
label: 'DML Statement In A Loop',
description: "To prevent exceeding Apex governor limits, it is advisable to consolidate all your database operations, including record creation, updates, or deletions, at the conclusion of the flow.",
type: 'pattern',
supportedTypes: [...core.FlowType.backEndTypes, ...core.FlowType.visualTypes],
supportedTypes: core.FlowType.backEndTypes,
docRefs: [{ 'label': 'Flow Best Practices', 'path': 'https://help.salesforce.com/s/articleView?id=sf.flow_prep_bestpractices.htm&type=5' }],
isConfigurable: false
});
Expand Down
2 changes: 1 addition & 1 deletion src/main/rules/SOQLQueryInLoop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class SOQLQueryInLoop extends RuleCommon implements core.IRuleDefinition
label: 'SOQL Query In A Loop',
description: "To prevent exceeding Apex governor limits, it is advisable to consolidate all your SOQL queries at the conclusion of the flow.",
type: 'pattern',
supportedTypes: [...core.FlowType.backEndTypes, ...core.FlowType.visualTypes],
supportedTypes: core.FlowType.backEndTypes,
docRefs: [{ 'label': 'Flow Best Practices', 'path': 'https://help.salesforce.com/s/articleView?id=sf.flow_prep_bestpractices.htm&type=5' }],
isConfigurable: false
});
Expand Down
2 changes: 1 addition & 1 deletion tests/DuplicateDMLOperationTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('The DuplicateDMLOperation Rule ', () => {
},
};
const results: core.ScanResult[] = core.scan([flow], ruleConfig);
expect(results[0].ruleResults.length).to.equal(0);
expect(results[0].ruleResults[0].occurs).to.equal(false);
});

it('should have no result in a flow with dmls and unconnected screens', () => {
Expand Down
44 changes: 24 additions & 20 deletions tests/RuleConfigurations.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
import { assert, expect } from 'chai';
import 'mocha';
import * as core from '../src'
import CreateANewAccount from './testfiles/CreateANewAccount.json';
import CreateANewAccountWithChild from './testfiles/CreateANewAccountWithChild.json';
import CreateANewAccountImproved from './testfiles/CreateANewAccountImproved.json';
import unconnectedElement from './testfiles/UnconnectedElement.json';
import waitForOnly from './testfiles/WaitForOnly.json';

describe('When scaning without specified rules in the rule config', () => {
describe('Rule Configurations ', () => {

let flow: core.Flow;
let flow2: core.Flow;
let flows: core.Flow[];

before('arrange', () => {
flow = new core.Flow({
path: './testfiles/CreateANewAccountWithChild.flow-meta.xml',
xmldata: CreateANewAccount,
it(' should use default when no configuration is provided', () => {
flow2 = new core.Flow({
path: './testfiles/unconnectedElement.flow-meta.xml',
xmldata: unconnectedElement,
});
});

it('all default rules should be used when no configuration is provided', () => {

const results: core.ScanResult[] = core.scan([flow], undefined);
const results: core.ScanResult[] = core.scan([flow2], undefined);
const rules = core.getRules();
expect(results[0].ruleResults.length).to.equal(rules.length);
});

it('all default rules should be used when no rules are specified', () => {
it(' should use default when no rules are specified', () => {
flow2 = new core.Flow({
path: './testfiles/unconnectedElement.flow-meta.xml',
xmldata: unconnectedElement,
});
const ruleConfig = {
rules:
{
Expand All @@ -37,12 +34,16 @@ describe('When scaning without specified rules in the rule config', () => {
{"DuplicateDMLOperation":["ViewAccountId"]}
}
};
const results: core.ScanResult[] = core.scan([flow], ruleConfig);
const results: core.ScanResult[] = core.scan([flow2], ruleConfig);
const rules = core.getRules();
expect(results[0].ruleResults.length).to.equal(rules.length);
});

it('incorrect rule severity configurations are defaulted', () => {
flow2 = new core.Flow({
path: './testfiles/unconnectedElement.flow-meta.xml',
xmldata: unconnectedElement,
});
const ruleConfig = {
rules:
{
Expand All @@ -52,13 +53,16 @@ describe('When scaning without specified rules in the rule config', () => {
}
}
};
const results: core.ScanResult[] = core.scan([flow], ruleConfig);
const rules = core.getRules();
const results: core.ScanResult[] = core.scan([flow2], ruleConfig);
expect(results[0].ruleResults.length).to.equal(1);
});


it('incorrect rule configurations are skipped', () => {
flow2 = new core.Flow({
path: './testfiles/unconnectedElement.flow-meta.xml',
xmldata: unconnectedElement,
});
const ruleConfig = {
rules:
{
Expand All @@ -77,7 +81,7 @@ describe('When scaning without specified rules in the rule config', () => {
{"DuplicateDMLOperation":["ViewAccountId"]}
}
};
const results: core.ScanResult[] = core.scan([flow], ruleConfig);
const results: core.ScanResult[] = core.scan([flow2], ruleConfig);
expect(results[0].ruleResults.length).to.equal(1);
});

Expand Down

0 comments on commit db12bf2

Please sign in to comment.