All files / src/utils businessValueUtils.ts

100% Statements 3/3
50% Branches 1/2
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                                                              48x             48x         48x    
import roiEstimatesData from "../data/security/roiEstimatesData";
import { SecurityLevel } from "../types/cia";
import { ROIEstimate } from "../types/cia-services";
import { calculateOverallSecurityLevel } from "./securityLevelUtils";
 
/**
 * Calculates ROI estimate based on security levels
 *
 * @param availabilityLevel - Availability security level
 * @param integrityLevel - Integrity security level
 * @param confidentialityLevel - Confidentiality security level
 * @returns ROI estimate object with value and description
 *
 * @example
 * ```typescript
 * // Calculate ROI for high security configuration
 * const roi = calculateROIEstimate('High', 'High', 'Moderate');
 * console.log(`ROI: ${roi.value}, ${roi.description}`);
 * // Output: ROI: 150-250%, Significant risk reduction
 *
 * // Calculate ROI for moderate security
 * const moderateROI = calculateROIEstimate('Moderate', 'Moderate', 'Low');
 * console.log(moderateROI.value); // "100-150%"
 * ```
 */
export function calculateROIEstimate(
  availabilityLevel: SecurityLevel,
  integrityLevel: SecurityLevel,
  confidentialityLevel: SecurityLevel,
): ROIEstimate {
  // Calculate overall security level for consistent ROI estimation
  const securityLevel = calculateOverallSecurityLevel(
    availabilityLevel,
    integrityLevel,
    confidentialityLevel,
  );
 
  // Convert security level to ROI key format (e.g., "Very High" -> "VERY_HIGH")
  const roiKey = securityLevel
    .toUpperCase()
    .replace(" ", "_") as keyof typeof roiEstimatesData;
 
  // Return the ROI estimate from the existing data
  return roiEstimatesData[roiKey] || roiEstimatesData.MODERATE;
}