From a6ded900268b12db793b053f7e989bbf82324dff Mon Sep 17 00:00:00 2001 From: Kyle Date: Wed, 30 Oct 2024 13:30:18 -0400 Subject: [PATCH] add tests for core.fix --- tests/UnconnectedElement.test.ts | 21 +++++++++++++++++++++ tests/UnusedVariable.test.ts | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/tests/UnconnectedElement.test.ts b/tests/UnconnectedElement.test.ts index c9e82b8..f2297fe 100644 --- a/tests/UnconnectedElement.test.ts +++ b/tests/UnconnectedElement.test.ts @@ -40,4 +40,25 @@ describe("UnconnectedElement", () => { expect(ruleDetail.name).to.equal("UnconnectedElementTestOnAsync"); }); }); + + it("should fix the unconnected element error", async () => { + const connectedElementTestFile = path.join( + __dirname, + "./xmlfiles/Unconnected_Element.flow-meta.xml" + ); + let flows = await core.parse([connectedElementTestFile]); + const ruleConfig = { + rules: { + UnconnectedElement: { + severity: "error", + }, + }, + }; + const results: core.ScanResult[] = core.scan(flows, ruleConfig); + const fixedResults: core.ScanResult[] = core.fix(results); + const fixedFlow: ParsedFlow = new ParsedFlow(connectedElementTestFile, fixedResults[0].flow); + const newResults: core.ScanResult[] = core.scan([fixedFlow], ruleConfig); + const fixedResultsOccurring = newResults[0].ruleResults.filter((rule) => rule.occurs); + expect(fixedResultsOccurring.length).to.equal(0); + }); }); diff --git a/tests/UnusedVariable.test.ts b/tests/UnusedVariable.test.ts index f2889fd..6b20805 100644 --- a/tests/UnusedVariable.test.ts +++ b/tests/UnusedVariable.test.ts @@ -1,6 +1,7 @@ import "mocha"; import * as core from "../src"; import * as path from "path-browserify"; +import { ParsedFlow } from "../src/main/models/ParsedFlow"; describe("UnusedVariable Rule", () => { let expect; @@ -38,4 +39,21 @@ describe("UnusedVariable Rule", () => { const occurringResults = results[0].ruleResults.filter((rule) => rule.occurs); expect(occurringResults.length).to.equal(0); }); + + it("should fix the unused variable error", async () => { + let flows = await core.parse([example_uri]); + const ruleConfig = { + rules: { + UnusedVariable: { + severity: "error", + }, + }, + }; + const results: core.ScanResult[] = core.scan(flows, ruleConfig); + const fixedResults: core.ScanResult[] = core.fix(results); + const fixedFlow: ParsedFlow = new ParsedFlow(example_uri, fixedResults[0].flow); + const newResults: core.ScanResult[] = core.scan([fixedFlow], ruleConfig); + const fixedResultsOccurring = newResults[0].ruleResults.filter((rule) => rule.occurs); + expect(fixedResultsOccurring.length).to.equal(0); + }); });