diff --git a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.js b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.js index 0afa22b..b091fa0 100644 --- a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.js +++ b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.js @@ -89,7 +89,7 @@ export const calculateAttackEfficiency = (protectionWeakness) => { * @param {boolean} Q6 The answer to Q6. * @returns {string} The threat occurrence */ -const calculateOccurrence = (attackEfficiency, Q5, Q6) => { +export const calculateOccurrence = (attackEfficiency, Q5, Q6) => { if (Q5 === true && Q6 === true) { if (attackEfficiency === "Low") { return "Medium"; diff --git a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.test.js b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.test.js index 26e20fe..1e2f8f9 100644 --- a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.test.js +++ b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.test.js @@ -2,6 +2,7 @@ import { calculateThreatScope, calculateProtectionWeakness, calculateAttackEfficiency, + calculateOccurrence, } from "./calculateLikelihood"; describe("testing the calculateThreatScope function", () => { @@ -175,3 +176,125 @@ describe("testing the calculateAttackEfficiency function", () => { expect(calculateAttackEfficiency(protectionWeakness)).toBe(expectValue); }); }); + +describe("testing the calculateOccurrence function", () => { + it("should return Medium if the attackEfficiency is Low, and Q5 & Q6 are both true", () => { + const expectValue = "Medium"; + const attackEfficiency = "Low"; + const Q5Value = true; + const Q6Value = true; + expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe( + expectValue + ); + }); + + it("should return Low if the attackEfficiency is Low, and Q5 & Q6 are both false", () => { + const expectValue = "Low"; + const attackEfficiency = "Low"; + const Q5Value = false; + const Q6Value = false; + expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe( + expectValue + ); + }); + + it("should return Low if the attackEfficiency is Low, and Q5 is true & Q6 is false", () => { + const expectValue = "Low"; + const attackEfficiency = "Low"; + const Q5Value = true; + const Q6Value = false; + expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe( + expectValue + ); + }); + + it("should return Low if the attackEfficiency is Low, and Q5 is false & Q6 is true", () => { + const expectValue = "Low"; + const attackEfficiency = "Low"; + const Q5Value = false; + const Q6Value = true; + expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe( + expectValue + ); + }); + + it("should return High if the attackEfficiency is Medium, and Q5 & Q6 are both true", () => { + const expectValue = "High"; + const attackEfficiency = "Medium"; + const Q5Value = true; + const Q6Value = true; + expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe( + expectValue + ); + }); + + it("should return Low if the attackEfficiency is Medium, and Q5 & Q6 are both false", () => { + const expectValue = "Low"; + const attackEfficiency = "Medium"; + const Q5Value = false; + const Q6Value = false; + expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe( + expectValue + ); + }); + + it("should return Medium if the attackEfficiency is Medium, and Q5 is true & Q6 is false", () => { + const expectValue = "Medium"; + const attackEfficiency = "Medium"; + const Q5Value = true; + const Q6Value = false; + expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe( + expectValue + ); + }); + + it("should return Medium if the attackEfficiency is Medium, and Q5 is false & Q6 is true", () => { + const expectValue = "Medium"; + const attackEfficiency = "Medium"; + const Q5Value = false; + const Q6Value = true; + expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe( + expectValue + ); + }); + + it("should return High if the attackEfficiency is High, and Q5 & Q6 are both true", () => { + const expectValue = "High"; + const attackEfficiency = "High"; + const Q5Value = true; + const Q6Value = true; + expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe( + expectValue + ); + }); + + it("should return Medium if the attackEfficiency is High, and Q5 & Q6 are both false", () => { + const expectValue = "Medium"; + const attackEfficiency = "High"; + const Q5Value = false; + const Q6Value = false; + expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe( + expectValue + ); + }); + + it("should return High if the attackEfficiency is High, and Q5 is true & Q6 is false", () => { + const expectValue = "High"; + const attackEfficiency = "High"; + const Q5Value = true; + const Q6Value = false; + expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe( + expectValue + ); + }); + + it("should return High if the attackEfficiency is High, and Q5 is false & Q6 is true", () => { + const expectValue = "High"; + const attackEfficiency = "High"; + const Q5Value = false; + const Q6Value = true; + expect(calculateOccurrence(attackEfficiency, Q5Value, Q6Value)).toBe( + expectValue + ); + }); +});