@@ -17,18 +17,31 @@ func TestImageFilterService_NewService(t *testing.T) {
1717 t .Error ("Service should have default config when nil is passed" )
1818 }
1919
20- // Verify default values
21- defaultConfig := service .DefaultFilterConfig ()
22- if defaultConfig .FilterWindowDays != 30 {
23- t .Errorf ("Default FilterWindowDays = %d, want 30" , defaultConfig .FilterWindowDays )
20+ // Verify default values from service config
21+ if service .config .DefaultWindowDays != 30 {
22+ t .Errorf ("Default DefaultWindowDays = %d, want 30" , service .config .DefaultWindowDays )
23+ }
24+
25+ if service .config .DefaultMaxFilterRatio != 0.8 {
26+ t .Errorf ("Default DefaultMaxFilterRatio = %.2f, want 0.8" , service .config .DefaultMaxFilterRatio )
27+ }
28+
29+ if ! service .config .Enabled {
30+ t .Error ("Default config should be enabled" )
2431 }
2532
33+ // Verify DefaultFilterConfig method
34+ defaultConfig := service .DefaultFilterConfig ()
2635 if defaultConfig .MaxFilterRatio != 0.8 {
2736 t .Errorf ("Default MaxFilterRatio = %.2f, want 0.8" , defaultConfig .MaxFilterRatio )
2837 }
2938
3039 if ! defaultConfig .Enabled {
31- t .Error ("Default config should be enabled" )
40+ t .Error ("Default FilterConfig should be enabled" )
41+ }
42+
43+ if ! defaultConfig .SessionEnabled {
44+ t .Error ("Default FilterConfig should have session filtering enabled" )
3245 }
3346}
3447
@@ -47,14 +60,36 @@ func TestImageFilterService_WithConfig(t *testing.T) {
4760 t .Error ("Service should use provided config" )
4861 }
4962
50- defaultConfig := service .DefaultFilterConfig ()
51- if defaultConfig .FilterWindowDays != 15 {
52- t .Errorf ("Custom FilterWindowDays = %d, want 15" , defaultConfig .FilterWindowDays )
63+ // Test service config fields directly
64+ if service .config .DefaultWindowDays != 15 {
65+ t .Errorf ("Custom DefaultWindowDays = %d, want 15" , service .config .DefaultWindowDays )
66+ }
67+
68+ if service .config .DefaultMaxFilterRatio != 0.6 {
69+ t .Errorf ("Custom DefaultMaxFilterRatio = %.2f, want 0.6" , service .config .DefaultMaxFilterRatio )
70+ }
71+
72+ if service .config .SearchExpansionRatio != 3.0 {
73+ t .Errorf ("Custom SearchExpansionRatio = %.1f, want 3.0" , service .config .SearchExpansionRatio )
74+ }
75+
76+ if service .config .EnableDegradation {
77+ t .Error ("EnableDegradation should be false" )
78+ }
79+
80+ if service .config .EnableMetrics {
81+ t .Error ("EnableMetrics should be false" )
5382 }
5483
84+ // Test DefaultFilterConfig method uses custom values
85+ defaultConfig := service .DefaultFilterConfig ()
5586 if defaultConfig .MaxFilterRatio != 0.6 {
5687 t .Errorf ("Custom MaxFilterRatio = %.2f, want 0.6" , defaultConfig .MaxFilterRatio )
5788 }
89+
90+ if ! defaultConfig .Enabled {
91+ t .Error ("FilterConfig should be enabled when config is enabled" )
92+ }
5893}
5994
6095func TestDegradationStrategy_String (t * testing.T ) {
@@ -86,36 +121,45 @@ func TestFilterConfig_Validation(t *testing.T) {
86121 {
87122 name : "Valid config" ,
88123 config : FilterConfig {
89- FilterWindowDays : 30 ,
90- MaxFilterRatio : 0.8 ,
91- Enabled : true ,
124+ MaxFilterRatio : 0.8 ,
125+ SessionEnabled : true ,
126+ Enabled : true ,
127+ },
128+ expectError : false ,
129+ },
130+ {
131+ name : "Session disabled" ,
132+ config : FilterConfig {
133+ MaxFilterRatio : 0.8 ,
134+ SessionEnabled : false ,
135+ Enabled : true ,
92136 },
93137 expectError : false ,
94138 },
95139 {
96- name : "Zero window days " ,
140+ name : "Zero filter ratio " ,
97141 config : FilterConfig {
98- FilterWindowDays : 0 ,
99- MaxFilterRatio : 0.8 ,
100- Enabled : true ,
142+ MaxFilterRatio : 0 ,
143+ SessionEnabled : true ,
144+ Enabled : true ,
101145 },
102- expectError : false , // Zero is valid, means no time filtering
146+ expectError : false , // Zero is valid, means no filtering limit
103147 },
104148 {
105- name : "Invalid filter ratio too high " ,
149+ name : "High filter ratio" ,
106150 config : FilterConfig {
107- FilterWindowDays : 30 ,
108- MaxFilterRatio : 1.5 ,
109- Enabled : true ,
151+ MaxFilterRatio : 1.0 ,
152+ SessionEnabled : true ,
153+ Enabled : true ,
110154 },
111- expectError : false , // Values > 1 are allowed in our implementation
155+ expectError : false , // Values up to 1.0 are allowed
112156 },
113157 {
114158 name : "Disabled config" ,
115159 config : FilterConfig {
116- FilterWindowDays : 30 ,
117- MaxFilterRatio : 0.8 ,
118- Enabled : false ,
160+ MaxFilterRatio : 0.8 ,
161+ SessionEnabled : true ,
162+ Enabled : false ,
119163 },
120164 expectError : false ,
121165 },
@@ -126,12 +170,12 @@ func TestFilterConfig_Validation(t *testing.T) {
126170 // For now, we just verify the config can be created without panicking
127171 // In a real scenario, you'd add validation methods to FilterConfig
128172 config := test .config
129- if config .FilterWindowDays < 0 {
130- t .Error ("FilterWindowDays should not be negative" )
131- }
132173 if config .MaxFilterRatio < 0 {
133174 t .Error ("MaxFilterRatio should not be negative" )
134175 }
176+ if config .MaxFilterRatio > 1.0 {
177+ t .Error ("MaxFilterRatio should not exceed 1.0" )
178+ }
135179 })
136180 }
137181}
@@ -190,7 +234,7 @@ func TestFilterContext_Initialization(t *testing.T) {
190234 QueryID : "test-query" ,
191235 Query : "test query" ,
192236 RequestedCount : 10 ,
193- Config : & FilterConfig {FilterWindowDays : 30 , MaxFilterRatio : 0.8 , Enabled : true },
237+ Config : & FilterConfig {MaxFilterRatio : 0.8 , SessionEnabled : true , Enabled : true },
194238 DegradationUsed : DegradationNone ,
195239 Metrics : & FilterMetrics {},
196240 }
@@ -214,4 +258,17 @@ func TestFilterContext_Initialization(t *testing.T) {
214258 if ctx .Metrics == nil {
215259 t .Error ("FilterContext Metrics should not be nil" )
216260 }
217- }
261+
262+ // Verify config fields
263+ if ctx .Config .MaxFilterRatio != 0.8 {
264+ t .Errorf ("FilterContext MaxFilterRatio = %.2f, want 0.8" , ctx .Config .MaxFilterRatio )
265+ }
266+
267+ if ! ctx .Config .SessionEnabled {
268+ t .Error ("FilterContext SessionEnabled should be true" )
269+ }
270+
271+ if ! ctx .Config .Enabled {
272+ t .Error ("FilterContext Enabled should be true" )
273+ }
274+ }
0 commit comments