All files / src/utils businessValueUtils.ts

50% Statements 4/8
100% Branches 2/2
100% Functions 2/2
50% Lines 4/8

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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107                                                                                                    8x             48x         48x                               48x                                                        
import roiEstimatesData from "../data/security/roiEstimatesData";
import { SecurityLevel } from "../types/cia";
import { ROIEstimate } from "../types/cia-services";
import {
  calculateImplementationCost as calculateImplCost,
  Industry,
  OrganizationSize,
} from "./costCalculationUtils";
import {
  calculateOverallSecurityLevel,
  getSecurityLevelValue,
} from "./securityLevelUtils";
 
/**
 * Interface for representing implementation timeline
 */
export interface ImplementationTimeline {
  total: string;
  phases?: Array<{
    name: string;
    duration: string;
  }>;
}
 
/**
 * 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;
}
 
/**
 * Calculates implementation timeline based on security levels
 * @param availabilityLevel - Availability security level
 * @param integrityLevel - Integrity security level
 * @param confidentialityLevel - Confidentiality security level
 * @returns Implementation timeline object
 */
export function calculateImplementationTimeline(
  availabilityLevel: SecurityLevel,
  integrityLevel: SecurityLevel,
  confidentialityLevel: SecurityLevel
): ImplementationTimeline {
  // Get security level values
  const availabilityValue = getSecurityLevelValue(availabilityLevel);
  const integrityValue = getSecurityLevelValue(integrityLevel);
  const confidentialityValue = getSecurityLevelValue(confidentialityLevel);
 
  // Calculate total weeks based on security levels
  const totalWeeks = Math.round(
    (availabilityValue + integrityValue + confidentialityValue) * 1.5
  );
 
  // Calculate phases based on total time
  return {
    total: `${totalWeeks} weeks`,
    phases: [
      {
        name: "Planning",
        duration: `${Math.round(totalWeeks * 0.3)} weeks`,
      },
      {
        name: "Implementation",
        duration: `${Math.round(totalWeeks * 0.5)} weeks`,
      },
      {
        name: "Testing & Adoption",
        duration: `${Math.round(totalWeeks * 0.2)} weeks`,
      },
    ],
  };
}