1+ import { describe , it , expect } from '@jest/globals' ;
2+ import { Finding } from '../../src/types' ;
3+
4+ describe ( 'Finding suggestedFix handling' , ( ) => {
5+ it ( 'should handle findings without suggestedFix' , ( ) => {
6+ const finding : Finding = {
7+ id : 'test-001' ,
8+ domain : 'deps' ,
9+ title : 'Test finding' ,
10+ description : 'Test description' ,
11+ evidence : { file : 'test.js' , snippet : 'test' } ,
12+ severity : 'high' ,
13+ confidence : 'high' ,
14+ impact : { type : 'security' , estimate : 'test' , confidence : 'high' } ,
15+ autoFixSafe : false
16+ } ;
17+
18+ const hasAutoFix = finding . suggestedFix ?. autoFixable ?? false ;
19+ expect ( hasAutoFix ) . toBe ( false ) ;
20+
21+ // Use !! to convert to boolean
22+ const canAutoFix = ! ! ( finding . autoFixSafe || finding . suggestedFix ?. autoFixable ) ;
23+ expect ( canAutoFix ) . toBe ( false ) ;
24+ } ) ;
25+
26+ it ( 'should handle findings with suggestedFix but no autoFixable' , ( ) => {
27+ const finding : Finding = {
28+ id : 'test-002' ,
29+ domain : 'deps' ,
30+ title : 'Test finding' ,
31+ description : 'Test description' ,
32+ evidence : { file : 'test.js' , snippet : 'test' } ,
33+ severity : 'medium' ,
34+ confidence : 'high' ,
35+ impact : { type : 'time' , estimate : 'test' , confidence : 'medium' } ,
36+ suggestedFix : {
37+ type : 'modify' ,
38+ file : 'test.js' ,
39+ description : 'Fix description' ,
40+ autoFixable : false
41+ } ,
42+ autoFixSafe : false
43+ } ;
44+
45+ const hasAutoFix = finding . suggestedFix ?. autoFixable ?? false ;
46+ expect ( hasAutoFix ) . toBe ( false ) ;
47+ } ) ;
48+
49+ it ( 'should handle findings with autoFixable' , ( ) => {
50+ const finding : Finding = {
51+ id : 'test-003' ,
52+ domain : 'deps' ,
53+ title : 'Test finding' ,
54+ description : 'Test description' ,
55+ evidence : { file : 'test.js' , snippet : 'test' } ,
56+ severity : 'low' ,
57+ confidence : 'high' ,
58+ impact : { type : 'size' , estimate : '100KB' , confidence : 'high' } ,
59+ suggestedFix : {
60+ type : 'modify' ,
61+ file : 'test.js' ,
62+ description : 'Fix description' ,
63+ autoFixable : true
64+ } ,
65+ autoFixSafe : true
66+ } ;
67+
68+ const hasAutoFix = finding . suggestedFix ?. autoFixable ?? false ;
69+ expect ( hasAutoFix ) . toBe ( true ) ;
70+
71+ // When both autoFixSafe and autoFixable are true, it's auto-fixable
72+ const canAutoFix = finding . autoFixSafe && finding . suggestedFix ?. autoFixable ;
73+ expect ( canAutoFix ) . toBe ( true ) ;
74+ } ) ;
75+ } ) ;
0 commit comments