diff --git a/src/main/libs/ScanFlows.ts b/src/main/libs/ScanFlows.ts index 72342f1..278412b 100644 --- a/src/main/libs/ScanFlows.ts +++ b/src/main/libs/ScanFlows.ts @@ -34,6 +34,8 @@ export function ScanFlows(flows: core.Flow[], rulesConfig?: Map): 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)); diff --git a/src/main/rules/DMLStatementInLoop.ts b/src/main/rules/DMLStatementInLoop.ts index 615ea7e..ad91fdf 100644 --- a/src/main/rules/DMLStatementInLoop.ts +++ b/src/main/rules/DMLStatementInLoop.ts @@ -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 }); diff --git a/src/main/rules/SOQLQueryInLoop.ts b/src/main/rules/SOQLQueryInLoop.ts index 188069e..fd3b9a6 100644 --- a/src/main/rules/SOQLQueryInLoop.ts +++ b/src/main/rules/SOQLQueryInLoop.ts @@ -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 }); diff --git a/tests/DuplicateDMLOperationTest.test.ts b/tests/DuplicateDMLOperationTest.test.ts index c3a5412..eb75378 100644 --- a/tests/DuplicateDMLOperationTest.test.ts +++ b/tests/DuplicateDMLOperationTest.test.ts @@ -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', () => { diff --git a/tests/RuleConfigurations.test.ts b/tests/RuleConfigurations.test.ts index 087f9eb..b12403c 100644 --- a/tests/RuleConfigurations.test.ts +++ b/tests/RuleConfigurations.test.ts @@ -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: { @@ -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: { @@ -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: { @@ -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); });