|
278 | 278 | }.to raise_error(Flipper::Adapters::Http::Error) |
279 | 279 | end |
280 | 280 |
|
| 281 | + it "skips If-None-Match header when cache_bust is true" do |
| 282 | + features_response = { |
| 283 | + "features" => [ |
| 284 | + { |
| 285 | + "key" => "search", |
| 286 | + "gates" => [ |
| 287 | + {"key" => "boolean", "value" => true} |
| 288 | + ] |
| 289 | + } |
| 290 | + ] |
| 291 | + } |
| 292 | + |
| 293 | + # First request - populate the ETag cache |
| 294 | + stub_request(:get, "http://app.com/flipper/features?exclude_gate_names=true") |
| 295 | + .to_return( |
| 296 | + status: 200, |
| 297 | + body: JSON.generate(features_response), |
| 298 | + headers: { 'ETag' => '"abc123"' } |
| 299 | + ) |
| 300 | + |
| 301 | + adapter = described_class.new(url: 'http://app.com/flipper') |
| 302 | + adapter.get_all |
| 303 | + |
| 304 | + # Second request with cache_bust - should NOT send If-None-Match |
| 305 | + cache_bust_stub = stub_request(:get, %r{/flipper/features\?_cb=\d+&exclude_gate_names=true}) |
| 306 | + .to_return( |
| 307 | + status: 200, |
| 308 | + body: JSON.generate(features_response), |
| 309 | + headers: { 'ETag' => '"def456"' } |
| 310 | + ) |
| 311 | + |
| 312 | + adapter.get_all(cache_bust: true) |
| 313 | + |
| 314 | + expect(cache_bust_stub).to have_been_requested.once |
| 315 | + expect( |
| 316 | + a_request(:get, %r{/flipper/features\?_cb=\d+&exclude_gate_names=true}) |
| 317 | + .with { |req| req.headers['If-None-Match'].nil? } |
| 318 | + ).to have_been_made.once |
| 319 | + end |
| 320 | + |
| 321 | + it "returns fresh data on cache_bust even when ETag is cached" do |
| 322 | + stale_response = { |
| 323 | + "features" => [ |
| 324 | + { |
| 325 | + "key" => "search", |
| 326 | + "gates" => [ |
| 327 | + {"key" => "boolean", "value" => nil} |
| 328 | + ] |
| 329 | + } |
| 330 | + ] |
| 331 | + } |
| 332 | + |
| 333 | + fresh_response = { |
| 334 | + "features" => [ |
| 335 | + { |
| 336 | + "key" => "search", |
| 337 | + "gates" => [ |
| 338 | + {"key" => "boolean", "value" => true} |
| 339 | + ] |
| 340 | + } |
| 341 | + ] |
| 342 | + } |
| 343 | + |
| 344 | + # First request - populate ETag cache with feature disabled |
| 345 | + stub_request(:get, "http://app.com/flipper/features?exclude_gate_names=true") |
| 346 | + .to_return( |
| 347 | + status: 200, |
| 348 | + body: JSON.generate(stale_response), |
| 349 | + headers: { 'ETag' => '"abc123"' } |
| 350 | + ) |
| 351 | + |
| 352 | + adapter = described_class.new(url: 'http://app.com/flipper') |
| 353 | + stale_result = adapter.get_all |
| 354 | + |
| 355 | + expect(stale_result["search"][:boolean]).to be_nil |
| 356 | + |
| 357 | + # Cache bust request returns fresh data (feature now enabled) |
| 358 | + stub_request(:get, %r{/flipper/features\?_cb=\d+&exclude_gate_names=true}) |
| 359 | + .to_return( |
| 360 | + status: 200, |
| 361 | + body: JSON.generate(fresh_response), |
| 362 | + headers: { 'ETag' => '"def456"' } |
| 363 | + ) |
| 364 | + |
| 365 | + fresh_result = adapter.get_all(cache_bust: true) |
| 366 | + |
| 367 | + expect(fresh_result["search"][:boolean]).to eq("true") |
| 368 | + end |
| 369 | + |
281 | 370 | it "does not send If-None-Match for other endpoints" do |
282 | 371 | stub_request(:get, "http://app.com/flipper/features/search") |
283 | 372 | .to_return(status: 404) |
|
0 commit comments