From e6ef94a80e383b7c3f689008b40360b57a20338f Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 17 Mar 2024 21:08:13 +0100 Subject: [PATCH] add test case --- tests/UnusedVariables.test.ts | 30 +++++ tests/testfiles/SendEmailFlow.json | 184 +++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+) create mode 100644 tests/UnusedVariables.test.ts create mode 100644 tests/testfiles/SendEmailFlow.json diff --git a/tests/UnusedVariables.test.ts b/tests/UnusedVariables.test.ts new file mode 100644 index 0000000..54794b6 --- /dev/null +++ b/tests/UnusedVariables.test.ts @@ -0,0 +1,30 @@ +import { expect } from 'chai'; +import 'mocha'; +import * as core from '../src' +import SendEmailFlow from './testfiles/SendEmailFlow.json'; + + +describe('The Unused Variables Rule', () => { + let flow: core.Flow; + + it('there should be no result for variables used in text elements', () => { + const ruleConfig = { + rules: + { + UnusedVariable: + { + severity: 'error', + }, + } + }; + flow = new core.Flow({ + path: './testfiles/SendEmailFlow.flow', + xmldata: SendEmailFlow, + }); + const results: core.ScanResult[] = core.scan([flow], ruleConfig); + const occurringResults = results[0].ruleResults.filter((rule) => rule.occurs); + expect(occurringResults.length).to.equal(0); + }); + +}); + diff --git a/tests/testfiles/SendEmailFlow.json b/tests/testfiles/SendEmailFlow.json new file mode 100644 index 0000000..ba030c3 --- /dev/null +++ b/tests/testfiles/SendEmailFlow.json @@ -0,0 +1,184 @@ +{ + "Flow": { + "$": { + "xmlns": "http://soap.sforce.com/2006/04/metadata" + }, + "actionCalls": [ + { + "name": [ + "Send_Email" + ], + "label": [ + "Send Email" + ], + "locationX": [ + "176" + ], + "locationY": [ + "323" + ], + "actionName": [ + "emailSimple" + ], + "actionType": [ + "emailSimple" + ], + "flowTransactionModel": [ + "CurrentTransaction" + ], + "inputParameters": [ + { + "name": [ + "emailSubject" + ], + "value": [ + { + "stringValue": [ + "My Subject" + ] + } + ] + }, + { + "name": [ + "emailBody" + ], + "value": [ + { + "elementReference": [ + "myTextTemplate" + ] + } + ] + }, + { + "name": [ + "recipientId" + ], + "value": [ + { + "elementReference": [ + "$User.Id" + ] + } + ] + } + ], + "nameSegment": [ + "emailSimple" + ], + "versionSegment": [ + "1" + ] + } + ], + "apiVersion": [ + "60.0" + ], + "environments": [ + "Default" + ], + "formulas": [ + { + "name": [ + "myFormula" + ], + "dataType": [ + "DateTime" + ], + "expression": [ + "NOW()" + ] + } + ], + "interviewLabel": [ + "SendEmailFlow {!$Flow.CurrentDateTime}" + ], + "label": [ + "SendEmailFlow" + ], + "processMetadataValues": [ + { + "name": [ + "BuilderType" + ], + "value": [ + { + "stringValue": [ + "LightningFlowBuilder" + ] + } + ] + }, + { + "name": [ + "CanvasMode" + ], + "value": [ + { + "stringValue": [ + "AUTO_LAYOUT_CANVAS" + ] + } + ] + }, + { + "name": [ + "OriginBuilderType" + ], + "value": [ + { + "stringValue": [ + "LightningFlowBuilder" + ] + } + ] + } + ], + "processType": [ + "AutoLaunchedFlow" + ], + "start": [ + { + "locationX": [ + "50" + ], + "locationY": [ + "0" + ], + "connector": [ + { + "targetReference": [ + "Send_Email" + ] + } + ], + "object": [ + "Account" + ], + "recordTriggerType": [ + "Create" + ], + "triggerType": [ + "RecordAfterSave" + ] + } + ], + "status": [ + "Draft" + ], + "textTemplates": [ + { + "name": [ + "myTextTemplate" + ], + "isViewedAsPlainText": [ + "false" + ], + "text": [ + "

{!myFormula}

" + ] + } + ] + } +} \ No newline at end of file