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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | 19x 19x 4x 3x 2x 1x 1x 4x 2x 2x 1x 5x 5x | /**
* Mock factory utilities for CIA Compliance Manager.
*
* This file consolidates mock creation functions.
*
* @packageDocumentation
*/
import { vi } from "vitest";
import { CIAContentService } from "../../services/ciaContentService";
import { CIAComponent, SecurityLevel } from "../../types/cia";
import { createCIAOptionsMock } from "../testMocks/ciaOptionsMocks";
// Re-export from existing mock files or provide implementations
export { createCIAOptionsMock } from "../testMocks/ciaOptionsMocks";
/**
* Creates a test instance of CIAContentService
* @returns Mocked CIAContentService
*/
export function createTestCIAContentService() {
const ciaOptions = createCIAOptionsMock();
return {
// Core Methods
getOptions: vi.fn().mockReturnValue(ciaOptions),
getCIAOptions: vi.fn().mockImplementation((component: CIAComponent) => {
if (component === "availability") return ciaOptions.availabilityOptions;
if (component === "integrity") return ciaOptions.integrityOptions;
if (component === "confidentiality")
return ciaOptions.confidentialityOptions;
// Return an object with a None property for invalid components
return { None: { description: "Invalid component" } };
}),
// CIA Component Details
getComponentDetails: vi.fn().mockImplementation((component, level) => {
// Return undefined for null or invalid inputs
if (
component === null ||
level === null ||
component === undefined ||
level === undefined ||
component === "invalid" ||
level === "Invalid"
) {
return undefined;
}
return {
description: "Test component description",
technical: "Test technical details",
businessImpact: "Test business impact",
recommendations: ["Test recommendation"],
capex: 10000,
opex: 2000,
};
}),
getCIATriadDetails: vi.fn().mockReturnValue({
availability: { description: "Test availability description" },
integrity: { description: "Test integrity description" },
confidentiality: { description: "Test confidentiality description" },
}),
getDetailBySecurityLevel: vi.fn().mockReturnValue({
description: "Test security level description",
recommendations: ["Test recommendation 1", "Test recommendation 2"],
}),
// ROI Methods
getROIEstimate: vi.fn().mockReturnValue({
returnRate: "150%",
description: "Test ROI description",
value: "Good",
}),
getROIEstimates: vi.fn().mockReturnValue({
returnRate: "150%",
description: "Test ROI description",
value: "Good",
}),
getAllROIEstimates: vi.fn().mockReturnValue({
NONE: { returnRate: "0%", description: "No ROI" },
LOW: { returnRate: "50%", description: "Low ROI" },
MODERATE: { returnRate: "150%", description: "Moderate ROI" },
HIGH: { returnRate: "300%", description: "High ROI" },
VERY_HIGH: { returnRate: "500%", description: "Very high ROI" },
}),
calculateRoi: vi.fn().mockReturnValue({
value: "$100,000",
percentage: "150%",
description: "Good ROI",
}),
// Business Impact Methods
getBusinessImpact: vi.fn().mockReturnValue({
summary: "Test business impact summary",
financial: { description: "Financial impact", riskLevel: "Medium" },
operational: { description: "Operational impact", riskLevel: "Low" },
reputational: { description: "Reputational impact", riskLevel: "High" },
}),
getDetailedDescription: vi.fn().mockReturnValue({
summary: "Test detailed description",
financial: { description: "Financial details", riskLevel: "Medium" },
operational: { description: "Operational details", riskLevel: "Low" },
reputational: { description: "Reputational details", riskLevel: "High" },
}),
getBusinessImpactDescription: vi
.fn()
.mockReturnValue("Test business impact description"),
// Technical Implementation Methods
getTechnicalDescription: vi
.fn()
.mockReturnValue("Test technical description"),
getTechnicalImplementation: vi.fn().mockReturnValue({
description: "Test implementation",
implementationSteps: ["Step 1", "Step 2"],
effort: {
// Added effort property to fix test
development: "Weeks (2-4)",
maintenance: "Regular (monthly review)",
expertise: "Security professional",
},
}),
// Compliance Methods
getComplianceStatus: vi.fn().mockReturnValue({
compliantFrameworks: ["NIST"],
partiallyCompliantFrameworks: ["ISO27001"],
nonCompliantFrameworks: ["HIPAA"],
remediationSteps: ["Implement security controls"],
status: "Compliant", // Added the missing status property
}),
// Security Methods
getSecurityMetrics: vi.fn().mockReturnValue({
score: 75,
maxScore: 100,
percentage: "75%",
}),
getComponentMetrics: vi.fn().mockImplementation((component) => {
return {
component: component, // Add this missing property
level: "Moderate",
value: 2,
percentage: "50%",
};
}),
getImpactMetrics: vi.fn().mockReturnValue({
securityLevel: "Moderate",
riskReduction: "50%",
}),
// Component Information Methods
getComponentContent: vi.fn().mockReturnValue({
description: "Test content",
technical: "Technical details",
businessImpact: "Business impact",
recommendations: ["Recommendation"],
}),
getBusinessImpactContent: vi
.fn()
.mockReturnValue("## Business Impact Summary\nTest impact"),
getSummaryContent: vi
.fn()
.mockReturnValue("## Security Profile Summary\nTest profile"),
// Helper Methods
getRecommendations: vi
.fn()
.mockReturnValue(["Test recommendation 1", "Test recommendation 2"]),
getImplementationConsiderations: vi
.fn()
.mockReturnValue("Test implementation considerations"),
getSecurityLevelDescription: vi
.fn()
.mockReturnValue("Test security level description"),
getRiskBadgeVariant: vi.fn().mockReturnValue("warning"),
getSecurityIcon: vi.fn().mockReturnValue("🔒"),
getSecurityResources: vi
.fn()
.mockReturnValue([
{ id: "1", title: "Resource 1", url: "https://example.com/1" },
]),
getInformationSensitivity: vi.fn().mockImplementation((level) => {
const labels = {
None: "Public Data",
Low: "Internal Data",
Moderate: "Sensitive Data",
High: "Confidential Data",
"Very High": "Restricted Data",
};
return labels[level as SecurityLevel] || "Unknown";
}),
getComplianceDescription: vi
.fn()
.mockReturnValue("Test compliance description"),
getKeyValuePoints: vi.fn().mockReturnValue(["Key point 1", "Key point 2"]),
// Integration Methods
getTotalImplementationTime: vi.fn().mockReturnValue("2-4 months"),
getRequiredExpertise: vi.fn().mockReturnValue("Security professional"),
getRecommendedImplementationPlan: vi
.fn()
.mockReturnValue("Step 1: Plan\nStep 2: Implement"),
// Additional methods used in tests
getImplementationTime: vi.fn().mockReturnValue("2-4 months"),
getCategoryIcon: vi.fn().mockReturnValue("📊"),
getBusinessPerspective: vi
.fn()
.mockReturnValue("Test business perspective"),
getProtectionLevel: vi.fn().mockReturnValue("Standard protection"),
getComponentImplementationDetails: vi.fn().mockReturnValue({
description: "Test implementation details",
implementationSteps: ["Step 1", "Step 2"],
effort: {
development: "2-4 weeks",
maintenance: "Monthly",
expertise: "Security professional",
},
}),
} as unknown as CIAContentService;
}
/**
* Creates a test instance of ComplianceService
* @returns Mocked ComplianceService
*/
|