diff --git a/src/features/BinaryRiskMatrix/BinaryRiskMatrixForm/BinaryRiskMatrixForm.js b/src/features/BinaryRiskMatrix/BinaryRiskMatrixForm/BinaryRiskMatrixForm.js index d0b626e..6608670 100644 --- a/src/features/BinaryRiskMatrix/BinaryRiskMatrixForm/BinaryRiskMatrixForm.js +++ b/src/features/BinaryRiskMatrix/BinaryRiskMatrixForm/BinaryRiskMatrixForm.js @@ -7,6 +7,10 @@ import calculateRisk from "../BinaryRiskMatrixLogic/calculateRisk"; import { calculateHarmCapacity } from "../BinaryRiskMatrixLogic/calculateImpact/calculateHarmCapacity/calculateHarmCapacity"; import { calculateImpactValuation } from "../BinaryRiskMatrixLogic/calculateImpact/calculateImpactValuation/calculateImpactValuation"; +import { calculateThreatScope } from "../BinaryRiskMatrixLogic/calculateLikelihood/calculateThreatScope/calculateThreatScope"; +import { calculateProtectionWeakness } from "../BinaryRiskMatrixLogic/calculateLikelihood/calculateProtectionWeakness/calculateProtectionWeakness"; +import { calculateAttackEfficiency } from "../BinaryRiskMatrixLogic/calculateLikelihood/calculateAttackEfficiency/calculateAttackEfficiency"; +import { calculateOccurrence } from "../BinaryRiskMatrixLogic/calculateLikelihood/calculateOccurrence/calculateOccurrence"; const calculateValues = (userResponses) => { const values = {}; @@ -22,6 +26,26 @@ const calculateValues = (userResponses) => { ); values.threatImpact = calculateImpact(values.impactValuation); + values.threatScore = calculateThreatScope(userResponses[0], userResponses[1]); + values.protectionWeakness = calculateProtectionWeakness( + values.threatScore, + userResponses[2], + userResponses[3] + ); + values.attackEfficiency = calculateAttackEfficiency( + values.protectionWeakness + ); + values.occurrence = calculateOccurrence( + values.attackEfficiency, + userResponses[4], + userResponses[5] + ); + values.threatLikelihood = calculateLikelihood(values.occurrence); + + values.threatRisk = calculateRisk( + values.threatLikelihood, + values.threatImpact + ); return values; }; @@ -57,24 +81,18 @@ export const BinaryRiskMatrixForm = () => { e.preventDefault(); const values = [Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10]; - const likelihoodResults = calculateLikelihood(values); - const impactResults = calculateImpact(values); const calculatedValues = calculateValues(values); appendHarmCapacity(calculatedValues.harmCapacity); appendImpactValuation(calculatedValues.impactValuation); - - appendThreatScore(likelihoodResults[0]); - appendProtectionWeakness(likelihoodResults[1]); - appendAttackEfficiency(likelihoodResults[2]); - appendOccurrence(likelihoodResults[3]); - - appendLikelihood(likelihoodResults[4]); + appendThreatScore(calculatedValues.threatScore); + appendProtectionWeakness(calculatedValues.protectionWeakness); + appendAttackEfficiency(calculatedValues.attackEfficiency); + appendOccurrence(calculatedValues.occurrence); + appendLikelihood(calculatedValues.threatLikelihood); appendImpact(calculatedValues.threatImpact); - - const risk = calculateRisk(likelihoodResults[4], impactResults[2]); - appendRisk(risk); + appendRisk(calculatedValues.threatRisk); }; return ( diff --git a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateAttackEfficiency/calculateAttackEfficiency.js b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateAttackEfficiency/calculateAttackEfficiency.js new file mode 100644 index 0000000..e9bd522 --- /dev/null +++ b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateAttackEfficiency/calculateAttackEfficiency.js @@ -0,0 +1,8 @@ +/** + * + * @param {string} protectionWeakness The protection weakness (see calculateProtectionWeakness) + * @returns {string} The attack efficiency + */ +export const calculateAttackEfficiency = (protectionWeakness) => { + return protectionWeakness; +}; diff --git a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateAttackEfficiency/calculateAttackEfficiency.test.js b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateAttackEfficiency/calculateAttackEfficiency.test.js new file mode 100644 index 0000000..03a4df2 --- /dev/null +++ b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateAttackEfficiency/calculateAttackEfficiency.test.js @@ -0,0 +1,21 @@ +import { calculateAttackEfficiency } from "./calculateAttackEfficiency"; + +describe("testing the calculateAttackEfficiency function", () => { + it("should return High if the protectionWeakness is High", () => { + const expectValue = "High"; + const protectionWeakness = "High"; + expect(calculateAttackEfficiency(protectionWeakness)).toBe(expectValue); + }); + + it("should return Medium if the protectionWeakness is Medium", () => { + const expectValue = "Medium"; + const protectionWeakness = "Medium"; + expect(calculateAttackEfficiency(protectionWeakness)).toBe(expectValue); + }); + + it("should return Low if the protectionWeakness is Low", () => { + const expectValue = "Low"; + const protectionWeakness = "Low"; + expect(calculateAttackEfficiency(protectionWeakness)).toBe(expectValue); + }); +}); diff --git a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.js b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.js index b091fa0..a403d43 100644 --- a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.js +++ b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.js @@ -1,110 +1,4 @@ -/** - * - * @param {boolean[]} values The users selected values for the questions in the binary risk matrix. - * @returns {string} The threat likelihood. - */ -export const calculateLikelihood = (values) => { - const threatScore = calculateThreatScope(values[0], values[1]); - const protectionWeakness = calculateProtectionWeakness( - threatScore, - values[2], - values[3] - ); - const attackEfficiency = calculateAttackEfficiency(protectionWeakness); - const occurrence = calculateOccurrence( - attackEfficiency, - values[4], - values[5] - ); - +export const calculateLikelihood = (occurrence) => { const threatLikelihood = occurrence; - const likelihoodResults = [ - threatScore, - protectionWeakness, - attackEfficiency, - occurrence, - threatLikelihood, - ]; - return likelihoodResults; -}; - -/** - * - * @param {boolean} Q1 The users answer for Q1. - * @param {boolean} Q2 The users answer for Q2. - * @returns {string} The threat scope - */ -export const calculateThreatScope = (Q1, Q2) => { - if (Q1 === true && Q2 === true) { - return "High"; - } else { - if (Q1 === true || Q2 === true) { - return "Medium"; - } else { - return "Low"; - } - } -}; - -/** - * - * @param {string} threatScore - * @param {boolean} Q3 - * @param {boolean} Q4 - * @returns {string} The protection weakness - */ -export const calculateProtectionWeakness = (threatScore, Q3, Q4) => { - if (Q3 === true && Q4 === true) { - if (threatScore === "Low") { - return "Medium"; - } else { - return "High"; - } - } else { - if (Q3 === true || Q4 === true) { - return threatScore; - } else { - if (threatScore === "High") { - return "Medium"; - } else { - return "Low"; - } - } - } -}; - -/** - * - * @param {string} protectionWeakness The protection weakness (see calculateProtectionWeakness) - * @returns {string} The attack efficiency - */ -export const calculateAttackEfficiency = (protectionWeakness) => { - return protectionWeakness; -}; - -/** - * - * @param {string} attackEfficiency The attack efficiency - * @param {boolean} Q5 The answer to Q5. - * @param {boolean} Q6 The answer to Q6. - * @returns {string} The threat occurrence - */ -export const calculateOccurrence = (attackEfficiency, Q5, Q6) => { - if (Q5 === true && Q6 === true) { - if (attackEfficiency === "Low") { - return "Medium"; - } else { - return "High"; - } - } else { - if (Q5 === true || Q6 === true) { - return attackEfficiency; - } else { - if (attackEfficiency === "High") { - return "Medium"; - } else { - return "Low"; - } - } - } + return threatLikelihood; }; diff --git a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.test.js b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.test.js index 1e2f8f9..986fa7b 100644 --- a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.test.js +++ b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateLikelihood.test.js @@ -1,300 +1,21 @@ -import { - calculateThreatScope, - calculateProtectionWeakness, - calculateAttackEfficiency, - calculateOccurrence, -} from "./calculateLikelihood"; +import { calculateLikelihood } from "./calculateLikelihood"; -describe("testing the calculateThreatScope function", () => { - it("should return High if Q1 & Q2 are both true", () => { +describe("testing the calculateLikelihood function", () => { + it("should return High if the occurrence is High", () => { const expectValue = "High"; - const Q1Value = true; - const Q2Value = true; - expect(calculateThreatScope(Q1Value, Q2Value)).toBe(expectValue); + const occurrence = "High"; + expect(calculateLikelihood(occurrence)).toBe(expectValue); }); - it("should return Low if Q1 & Q2 are both true", () => { - const expectValue = "Low"; - const Q1Value = false; - const Q2Value = false; - expect(calculateThreatScope(Q1Value, Q2Value)).toBe(expectValue); - }); - - it("should return Medium if Q1 is true & Q2 is false", () => { - const expectValue = "Medium"; - const Q1Value = true; - const Q2Value = false; - expect(calculateThreatScope(Q1Value, Q2Value)).toBe(expectValue); - }); - - it("should return Medium if Q1 is false & Q2 is true", () => { + it("should return Medium if the occurrence is Medium", () => { const expectValue = "Medium"; - const Q1Value = false; - const Q2Value = true; - expect(calculateThreatScope(Q1Value, Q2Value)).toBe(expectValue); - }); -}); - -describe("testing the calculateProtectionWeakness function", () => { - it("should return Medium if the threat score is Low, and Q3 & Q4 are both true", () => { - const expectValue = "Medium"; - const threatScore = "Low"; - const Q3Value = true; - const Q4Value = true; - expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( - expectValue - ); - }); - - it("should return Low if the threat score is Low, and Q3 & Q4 are both false", () => { - const expectValue = "Low"; - const threatScore = "Low"; - const Q3Value = false; - const Q4Value = false; - expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( - expectValue - ); - }); - - it("should return Low if the threat score is Low, and Q3 is true & Q4 is false", () => { - const expectValue = "Low"; - const threatScore = "Low"; - const Q3Value = true; - const Q4Value = false; - expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( - expectValue - ); - }); - - it("should return Low if the threat score is Low, and Q3 is false & Q4 is true", () => { - const expectValue = "Low"; - const threatScore = "Low"; - const Q3Value = false; - const Q4Value = true; - expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( - expectValue - ); - }); - - it("should return High if the threat score is Medium, and Q3 & Q4 are both true", () => { - const expectValue = "High"; - const threatScore = "Medium"; - const Q3Value = true; - const Q4Value = true; - expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( - expectValue - ); + const occurrence = "Medium"; + expect(calculateLikelihood(occurrence)).toBe(expectValue); }); - it("should return Low if the threat score is Medium, and Q3 & Q4 are both false", () => { + it("should return Low if the occurrence is Low", () => { const expectValue = "Low"; - const threatScore = "Medium"; - const Q3Value = false; - const Q4Value = false; - expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( - expectValue - ); - }); - - it("should return Medium if the threat score is Medium, and Q3 is true & Q4 is false", () => { - const expectValue = "Medium"; - const threatScore = "Medium"; - const Q3Value = true; - const Q4Value = false; - expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( - expectValue - ); - }); - - it("should return Medium if the threat score is Medium, and Q3 is false & Q4 is true", () => { - const expectValue = "Medium"; - const threatScore = "Medium"; - const Q3Value = false; - const Q4Value = true; - expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( - expectValue - ); - }); - - it("should return High if the threat score is High, and Q3 & Q4 are both true", () => { - const expectValue = "High"; - const threatScore = "High"; - const Q3Value = true; - const Q4Value = true; - expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( - expectValue - ); - }); - - it("should return Medium if the threat score is High, and Q3 & Q4 are both false", () => { - const expectValue = "Medium"; - const threatScore = "High"; - const Q3Value = false; - const Q4Value = false; - expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( - expectValue - ); - }); - - it("should return High if the threat score is High, and Q3 is true & Q4 is false", () => { - const expectValue = "High"; - const threatScore = "High"; - const Q3Value = true; - const Q4Value = false; - expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( - expectValue - ); - }); - - it("should return High if the threat score is High, and Q3 is false & Q4 is true", () => { - const expectValue = "High"; - const threatScore = "High"; - const Q3Value = false; - const Q4Value = true; - expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( - expectValue - ); - }); -}); - -describe("testing the calculateAttackEfficiency function", () => { - it("should return High if the protectionWeakness is High", () => { - const expectValue = "High"; - const protectionWeakness = "High"; - expect(calculateAttackEfficiency(protectionWeakness)).toBe(expectValue); - }); - - it("should return Medium if the protectionWeakness is Medium", () => { - const expectValue = "Medium"; - const protectionWeakness = "Medium"; - expect(calculateAttackEfficiency(protectionWeakness)).toBe(expectValue); - }); - - it("should return Low if the protectionWeakness is Low", () => { - const expectValue = "Low"; - const protectionWeakness = "Low"; - 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 - ); + const occurrence = "Low"; + expect(calculateLikelihood(occurrence)).toBe(expectValue); }); }); diff --git a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateOccurrence/calculateOccurrence.js b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateOccurrence/calculateOccurrence.js new file mode 100644 index 0000000..528364c --- /dev/null +++ b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateOccurrence/calculateOccurrence.js @@ -0,0 +1,26 @@ +/** + * + * @param {string} attackEfficiency The attack efficiency + * @param {boolean} Q5 The answer to Q5. + * @param {boolean} Q6 The answer to Q6. + * @returns {string} The threat occurrence + */ +export const calculateOccurrence = (attackEfficiency, Q5, Q6) => { + if (Q5 === true && Q6 === true) { + if (attackEfficiency === "Low") { + return "Medium"; + } else { + return "High"; + } + } else { + if (Q5 === true || Q6 === true) { + return attackEfficiency; + } else { + if (attackEfficiency === "High") { + return "Medium"; + } else { + return "Low"; + } + } + } +}; diff --git a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateOccurrence/calculateOccurrence.test.js b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateOccurrence/calculateOccurrence.test.js new file mode 100644 index 0000000..9b81207 --- /dev/null +++ b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateOccurrence/calculateOccurrence.test.js @@ -0,0 +1,123 @@ +import { calculateOccurrence } from "./calculateOccurrence"; + +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 + ); + }); +}); diff --git a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateProtectionWeakness/calculateProtectionWeakness.js b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateProtectionWeakness/calculateProtectionWeakness.js new file mode 100644 index 0000000..a91ed47 --- /dev/null +++ b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateProtectionWeakness/calculateProtectionWeakness.js @@ -0,0 +1,26 @@ +/** + * + * @param {string} threatScore + * @param {boolean} Q3 + * @param {boolean} Q4 + * @returns {string} The protection weakness + */ +export const calculateProtectionWeakness = (threatScore, Q3, Q4) => { + if (Q3 === true && Q4 === true) { + if (threatScore === "Low") { + return "Medium"; + } else { + return "High"; + } + } else { + if (Q3 === true || Q4 === true) { + return threatScore; + } else { + if (threatScore === "High") { + return "Medium"; + } else { + return "Low"; + } + } + } +}; diff --git a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateProtectionWeakness/calculateProtectionWeakness.test.js b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateProtectionWeakness/calculateProtectionWeakness.test.js new file mode 100644 index 0000000..5719488 --- /dev/null +++ b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateProtectionWeakness/calculateProtectionWeakness.test.js @@ -0,0 +1,123 @@ +import { calculateProtectionWeakness } from "./calculateProtectionWeakness"; + +describe("testing the calculateProtectionWeakness function", () => { + it("should return Medium if the threat score is Low, and Q3 & Q4 are both true", () => { + const expectValue = "Medium"; + const threatScore = "Low"; + const Q3Value = true; + const Q4Value = true; + expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( + expectValue + ); + }); + + it("should return Low if the threat score is Low, and Q3 & Q4 are both false", () => { + const expectValue = "Low"; + const threatScore = "Low"; + const Q3Value = false; + const Q4Value = false; + expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( + expectValue + ); + }); + + it("should return Low if the threat score is Low, and Q3 is true & Q4 is false", () => { + const expectValue = "Low"; + const threatScore = "Low"; + const Q3Value = true; + const Q4Value = false; + expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( + expectValue + ); + }); + + it("should return Low if the threat score is Low, and Q3 is false & Q4 is true", () => { + const expectValue = "Low"; + const threatScore = "Low"; + const Q3Value = false; + const Q4Value = true; + expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( + expectValue + ); + }); + + it("should return High if the threat score is Medium, and Q3 & Q4 are both true", () => { + const expectValue = "High"; + const threatScore = "Medium"; + const Q3Value = true; + const Q4Value = true; + expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( + expectValue + ); + }); + + it("should return Low if the threat score is Medium, and Q3 & Q4 are both false", () => { + const expectValue = "Low"; + const threatScore = "Medium"; + const Q3Value = false; + const Q4Value = false; + expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( + expectValue + ); + }); + + it("should return Medium if the threat score is Medium, and Q3 is true & Q4 is false", () => { + const expectValue = "Medium"; + const threatScore = "Medium"; + const Q3Value = true; + const Q4Value = false; + expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( + expectValue + ); + }); + + it("should return Medium if the threat score is Medium, and Q3 is false & Q4 is true", () => { + const expectValue = "Medium"; + const threatScore = "Medium"; + const Q3Value = false; + const Q4Value = true; + expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( + expectValue + ); + }); + + it("should return High if the threat score is High, and Q3 & Q4 are both true", () => { + const expectValue = "High"; + const threatScore = "High"; + const Q3Value = true; + const Q4Value = true; + expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( + expectValue + ); + }); + + it("should return Medium if the threat score is High, and Q3 & Q4 are both false", () => { + const expectValue = "Medium"; + const threatScore = "High"; + const Q3Value = false; + const Q4Value = false; + expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( + expectValue + ); + }); + + it("should return High if the threat score is High, and Q3 is true & Q4 is false", () => { + const expectValue = "High"; + const threatScore = "High"; + const Q3Value = true; + const Q4Value = false; + expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( + expectValue + ); + }); + + it("should return High if the threat score is High, and Q3 is false & Q4 is true", () => { + const expectValue = "High"; + const threatScore = "High"; + const Q3Value = false; + const Q4Value = true; + expect(calculateProtectionWeakness(threatScore, Q3Value, Q4Value)).toBe( + expectValue + ); + }); +}); diff --git a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateThreatScope/calculateThreatScope.js b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateThreatScope/calculateThreatScope.js new file mode 100644 index 0000000..e3c6809 --- /dev/null +++ b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateThreatScope/calculateThreatScope.js @@ -0,0 +1,17 @@ +/** + * + * @param {boolean} Q1 The users answer for Q1. + * @param {boolean} Q2 The users answer for Q2. + * @returns {string} The threat scope + */ +export const calculateThreatScope = (Q1, Q2) => { + if (Q1 === true && Q2 === true) { + return "High"; + } else { + if (Q1 === true || Q2 === true) { + return "Medium"; + } else { + return "Low"; + } + } +}; diff --git a/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateThreatScope/calculateThreatScope.test.js b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateThreatScope/calculateThreatScope.test.js new file mode 100644 index 0000000..8b36f0a --- /dev/null +++ b/src/features/BinaryRiskMatrix/BinaryRiskMatrixLogic/calculateLikelihood/calculateThreatScope/calculateThreatScope.test.js @@ -0,0 +1,31 @@ +import { calculateThreatScope } from "./calculateThreatScope"; + +describe("testing the calculateThreatScope function", () => { + it("should return High if Q1 & Q2 are both true", () => { + const expectValue = "High"; + const Q1Value = true; + const Q2Value = true; + expect(calculateThreatScope(Q1Value, Q2Value)).toBe(expectValue); + }); + + it("should return Low if Q1 & Q2 are both true", () => { + const expectValue = "Low"; + const Q1Value = false; + const Q2Value = false; + expect(calculateThreatScope(Q1Value, Q2Value)).toBe(expectValue); + }); + + it("should return Medium if Q1 is true & Q2 is false", () => { + const expectValue = "Medium"; + const Q1Value = true; + const Q2Value = false; + expect(calculateThreatScope(Q1Value, Q2Value)).toBe(expectValue); + }); + + it("should return Medium if Q1 is false & Q2 is true", () => { + const expectValue = "Medium"; + const Q1Value = false; + const Q2Value = true; + expect(calculateThreatScope(Q1Value, Q2Value)).toBe(expectValue); + }); +});