Skip to content

Commit 22572a7

Browse files
committed
adds betamode test
1 parent 5194688 commit 22572a7

File tree

1 file changed

+13
-125
lines changed

1 file changed

+13
-125
lines changed

tests/ConfigBetaMode.test.ts

Lines changed: 13 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -2,137 +2,25 @@ import { describe, expect, it } from "@jest/globals";
22
import * as path from "path";
33

44
import * as core from "../src";
5+
import { MissingMetadataDescription } from "../src/main/rules/MissingMetadataDescription";
56

6-
describe("Rule Configurations ", () => {
7+
describe("Beta Rule Handling", () => {
78
const example_uri1 = path.join(__dirname, "../assets/example-flows/force-app/main/default/flows/demo/Unconnected_Element.flow-meta.xml");
89

9-
// eslint-disable-next-line jest/no-disabled-tests
10-
it.skip("should use default when no configuration is provided", async () => {
10+
it("should include beta rule when betaMode is true and no rules are specified", async () => {
1111
const flows = await core.parse([example_uri1]);
12-
const results: core.ScanResult[] = core.scan(flows, undefined);
13-
const rules = [...core.getRules(), ...core.getBetaRules()];
14-
const allRuleNames = rules.map((r) => r.name);
15-
const allRuleResults = results[0].ruleResults.map((r) => r.ruleName);
16-
expect(allRuleNames).toEqual(allRuleResults);
17-
expect(results[0].ruleResults).toHaveLength(rules.length);
12+
const results = core.scan(flows, { betaMode: true, rules: {} });
13+
14+
// There should be at least 1 rule result (from beta rules)
15+
expect(results[0].ruleResults.length).toBeGreaterThan(0);
1816
});
1917

20-
// eslint-disable-next-line jest/no-disabled-tests
21-
it.skip("should use default and include beta", async () => {
18+
it("should not include beta rule if betaMode is false even if rule exists in beta", async () => {
2219
const flows = await core.parse([example_uri1]);
23-
const ruleConfig = {
24-
betaMode: true,
25-
exceptions: {
26-
CreateANewAccountWithChild: { DuplicateDMLOperation: ["ViewAccountId"] },
27-
},
28-
rules: {}
29-
};
30-
const results: core.ScanResult[] = core.scan(flows, ruleConfig);
31-
const rules = [...core.getRules(), ...core.getBetaRules()];
32-
const allRuleNames = rules.map((r) => r.name);
33-
const allRuleResults = results[0].ruleResults.map((r) => r.ruleName);
34-
expect(allRuleNames).toEqual(allRuleResults);
35-
expect(results[0].ruleResults).toHaveLength(rules.length);
36-
expect(results[0].ruleResults).toHaveLength(23);
37-
});
38-
39-
// eslint-disable-next-line jest/no-disabled-tests
40-
it.skip("should use default when no rules are specified", async () => {
41-
const flows = await core.parse([example_uri1]);
42-
const ruleConfig = {
43-
exceptions: {
44-
CreateANewAccountWithChild: { DuplicateDMLOperation: ["ViewAccountId"] },
45-
},
46-
rules: {}
47-
};
48-
const results: core.ScanResult[] = core.scan(flows, ruleConfig);
49-
const rules = [...core.getRules()];
50-
const allRuleNames = rules.map((r) => r.name);
51-
const allRuleResults = results[0].ruleResults.map((r) => r.ruleName);
52-
expect(allRuleNames).toEqual(allRuleResults);
53-
expect(results[0].ruleResults).toHaveLength(rules.length);
54-
});
55-
56-
it("incorrect rule severity configurations are defaulted", async () => {
57-
const flows = await core.parse([example_uri1]);
58-
const ruleConfig = {
59-
rules: {
60-
MissingNullHandler: {
61-
severity: "errorr",
62-
},
63-
},
64-
};
65-
const results: core.ScanResult[] = core.scan(flows, ruleConfig);
66-
expect(results[0].ruleResults).toHaveLength(1);
67-
});
68-
69-
it("incorrect rule configurations are skipped", async () => {
70-
const flows = await core.parse([example_uri1]);
71-
jest.spyOn(global.console, "error").mockImplementation(() => {});
72-
jest.spyOn(global.console, "log").mockImplementation(() => {});
73-
74-
const ruleConfig = {
75-
exceptions: {
76-
CreateANewAccountWithChild: { DuplicateDMLOperation: ["ViewAccountId"] },
77-
},
78-
rules: {
79-
MissingNullHandler: {
80-
severity: "error",
81-
},
82-
MissingNullHandler2: {
83-
severity: "error",
84-
},
85-
},
86-
};
87-
const results: core.ScanResult[] = core.scan(flows, ruleConfig);
88-
expect(results[0].ruleResults).toHaveLength(1);
89-
});
90-
91-
it("Multiple Expressions are individually checked", async () => {
92-
const flows = await core.parse([example_uri1]);
93-
const ruleConfig = {
94-
rules: {
95-
APIVersion: {
96-
expression: ">50",
97-
severity: "error",
98-
},
99-
CopyAPIName: {
100-
severity: "error",
101-
},
102-
DMLStatementInLoop: {
103-
severity: "error",
104-
},
105-
DuplicateDMLOperation: {
106-
severity: "error",
107-
},
108-
FlowDescription: {
109-
severity: "error",
110-
},
111-
FlowName: {
112-
expression: "[A-Za-z0-9]+_[A-Za-z0-9]+",
113-
severity: "error",
114-
},
115-
HardcodedId: {
116-
severity: "error",
117-
},
118-
MissingFaultPath: {
119-
severity: "error",
120-
},
121-
MissingNullHandler: {
122-
severity: "error",
123-
},
124-
SOQLQueryInLoop: {
125-
severity: "error",
126-
},
127-
UnconnectedElement: {
128-
severity: "error",
129-
},
130-
UnusedVariable: {
131-
severity: "error",
132-
},
133-
},
134-
};
135-
const results: core.ScanResult[] = core.scan(flows, ruleConfig);
136-
expect(results[0].ruleResults.find((r) => r.ruleName === "FlowName")?.occurs).toBe(false);
20+
const results = core.scan(flows, { betaMode: false });
21+
22+
// If the rule is only in beta and betaMode is false, it should not appear
23+
const ruleNames = results[0].ruleResults.map(r => r.ruleName);
24+
expect(ruleNames).not.toContain("MissingMetadataDescription");
13725
});
13826
});

0 commit comments

Comments
 (0)