Skip to content

Commit

Permalink
Merge pull request #135 from Lightning-Flow-Scanner/add-tests-for-fix…
Browse files Browse the repository at this point in the history
…-flows
  • Loading branch information
junners authored Oct 30, 2024
2 parents 13d715d + a6ded90 commit 685553a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/UnconnectedElement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
18 changes: 18 additions & 0 deletions tests/UnusedVariable.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
});
});

0 comments on commit 685553a

Please sign in to comment.