From 69c22c102f36faba678cdbc0e8227a3758b95cfa Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 17 Mar 2024 19:30:05 +0100 Subject: [PATCH] add test case --- tests/MissingNullHandler.test.ts | 26 +- .../testfiles/Subflow_MissingNullHandler.json | 409 ++++++++++++++++++ 2 files changed, 430 insertions(+), 5 deletions(-) create mode 100644 tests/testfiles/Subflow_MissingNullHandler.json diff --git a/tests/MissingNullHandler.test.ts b/tests/MissingNullHandler.test.ts index ef98306..40dcefa 100644 --- a/tests/MissingNullHandler.test.ts +++ b/tests/MissingNullHandler.test.ts @@ -1,21 +1,32 @@ import { assert, expect } from 'chai'; import 'mocha'; import * as core from '../src' - import CreateANewAccountWithChild from './testfiles/MissingNullHandler.json'; +import Subflow_MissingNullHandler from './testfiles/Subflow_MissingNullHandler.json'; -describe('When scanning a flow without null handlers', () => { +describe('The MissingNullHandler Rule', () => { let flow: core.Flow; - before('arrange', () => { - // ARRANGE + it('Should have a result when missing', () => { + const ruleConfig = { + rules: + { + MissingNullHandler: + { + severity: 'error', + }, + } + }; flow = new core.Flow({ path: './testfiles/tc.flow-meta.xml', xmldata: CreateANewAccountWithChild, }); + const results: core.ScanResult[] = core.scan([flow], ruleConfig); + expect(results[0].ruleResults[0].ruleName).to.equal('MissingNullHandler') + expect(results[0].ruleResults[0].occurs).to.equal(true); }); - it('missing null handler should have a result', () => { + it('Should have no result for subflow output variables ', () => { const ruleConfig = { rules: { @@ -25,8 +36,13 @@ describe('When scanning a flow without null handlers', () => { }, } }; + flow = new core.Flow({ + path: './testfiles/Subflow_MissingNullHandler.flow-meta.xml', + xmldata: Subflow_MissingNullHandler, + }); const results: core.ScanResult[] = core.scan([flow], ruleConfig); expect(results[0].ruleResults[0].ruleName).to.equal('MissingNullHandler') expect(results[0].ruleResults[0].occurs).to.equal(true); + expect(results[0].ruleResults[0].details.length).to.equal(1); }); }); diff --git a/tests/testfiles/Subflow_MissingNullHandler.json b/tests/testfiles/Subflow_MissingNullHandler.json new file mode 100644 index 0000000..1e5f56e --- /dev/null +++ b/tests/testfiles/Subflow_MissingNullHandler.json @@ -0,0 +1,409 @@ +{ + "Flow": { + "$": { + "xmlns": "http://soap.sforce.com/2006/04/metadata" + }, + "apiVersion": [ + "60.0" + ], + "assignments": [ + { + "name": [ + "Set_Error_Message" + ], + "label": [ + "Set Error Message" + ], + "locationX": [ + "314" + ], + "locationY": [ + "350" + ], + "assignmentItems": [ + { + "assignToReference": [ + "errorMessage" + ], + "operator": [ + "Assign" + ], + "value": [ + { + "stringValue": [ + "Error when retrieving records" + ] + } + ] + } + ] + } + ], + "decisions": [ + { + "name": [ + "Check_object_type" + ], + "label": [ + "Check object type" + ], + "locationX": [ + "578" + ], + "locationY": [ + "134" + ], + "defaultConnectorLabel": [ + "Default Outcome" + ], + "rules": [ + { + "name": [ + "User" + ], + "conditionLogic": [ + "and" + ], + "conditions": [ + { + "leftValueReference": [ + "recordId" + ], + "operator": [ + "StartsWith" + ], + "rightValue": [ + { + "stringValue": [ + "005" + ] + } + ] + } + ], + "connector": [ + { + "targetReference": [ + "Get_User" + ] + } + ], + "label": [ + "User" + ] + }, + { + "name": [ + "Queue" + ], + "conditionLogic": [ + "and" + ], + "conditions": [ + { + "leftValueReference": [ + "recordId" + ], + "operator": [ + "StartsWith" + ], + "rightValue": [ + { + "stringValue": [ + "00G" + ] + } + ] + } + ], + "connector": [ + { + "targetReference": [ + "Get_Queue" + ] + } + ], + "label": [ + "Queue" + ] + } + ] + } + ], + "description": [ + "Subflow that throws MissingNullHandler" + ], + "environments": [ + "Default" + ], + "interviewLabel": [ + "Subflow_Missing {!$Flow.CurrentDateTime}" + ], + "label": [ + "Subflow_MissingNullHandler" + ], + "processMetadataValues": [ + { + "name": [ + "BuilderType" + ], + "value": [ + { + "stringValue": [ + "LightningFlowBuilder" + ] + } + ] + }, + { + "name": [ + "CanvasMode" + ], + "value": [ + { + "stringValue": [ + "AUTO_LAYOUT_CANVAS" + ] + } + ] + }, + { + "name": [ + "OriginBuilderType" + ], + "value": [ + { + "stringValue": [ + "LightningFlowBuilder" + ] + } + ] + } + ], + "processType": [ + "AutoLaunchedFlow" + ], + "recordLookups": [ + { + "name": [ + "Get_Queue" + ], + "label": [ + "Get Queue" + ], + "locationX": [ + "578" + ], + "locationY": [ + "242" + ], + "assignNullValuesIfNoRecordsFound": [ + "true" + ], + "faultConnector": [ + { + "isGoTo": [ + "true" + ], + "targetReference": [ + "Set_Error_Message" + ] + } + ], + "filterLogic": [ + "and" + ], + "filters": [ + { + "field": [ + "Type" + ], + "operator": [ + "EqualTo" + ], + "value": [ + { + "stringValue": [ + "Queue" + ] + } + ] + }, + { + "field": [ + "Id" + ], + "operator": [ + "EqualTo" + ], + "value": [ + { + "elementReference": [ + "recordId" + ] + } + ] + } + ], + "object": [ + "Group" + ], + "outputReference": [ + "queueRecord" + ], + "queriedFields": [ + "Id" + ] + }, + { + "name": [ + "Get_User" + ], + "label": [ + "Get User" + ], + "locationX": [ + "50" + ], + "locationY": [ + "242" + ], + "assignNullValuesIfNoRecordsFound": [ + "true" + ], + "faultConnector": [ + { + "targetReference": [ + "Set_Error_Message" + ] + } + ], + "filterLogic": [ + "and" + ], + "filters": [ + { + "field": [ + "Id" + ], + "operator": [ + "EqualTo" + ], + "value": [ + { + "elementReference": [ + "recordId" + ] + } + ] + } + ], + "object": [ + "User" + ], + "outputReference": [ + "userRecord" + ], + "queriedFields": [ + "Id" + ] + } + ], + "start": [ + { + "locationX": [ + "452" + ], + "locationY": [ + "0" + ], + "connector": [ + { + "targetReference": [ + "Check_object_type" + ] + } + ] + } + ], + "status": [ + "Draft" + ], + "variables": [ + { + "name": [ + "errorMessage" + ], + "dataType": [ + "String" + ], + "isCollection": [ + "false" + ], + "isInput": [ + "false" + ], + "isOutput": [ + "true" + ] + }, + { + "name": [ + "queueRecord" + ], + "dataType": [ + "SObject" + ], + "isCollection": [ + "false" + ], + "isInput": [ + "false" + ], + "isOutput": [ + "true" + ], + "objectType": [ + "Group" + ] + }, + { + "name": [ + "recordId" + ], + "dataType": [ + "String" + ], + "isCollection": [ + "false" + ], + "isInput": [ + "true" + ], + "isOutput": [ + "false" + ] + }, + { + "name": [ + "userRecord" + ], + "dataType": [ + "SObject" + ], + "isCollection": [ + "false" + ], + "isInput": [ + "false" + ], + "isOutput": [ + "true" + ], + "objectType": [ + "User" + ] + } + ] + } +} \ No newline at end of file