delivery_failure_tracker_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe DeliveryFailureTracker do
  4. subject { described_class.new('http://example.com/inbox') }
  5. describe '#track_success!' do
  6. before do
  7. subject.track_failure!
  8. subject.track_success!
  9. end
  10. it 'marks URL as available again' do
  11. expect(described_class.available?('http://example.com/inbox')).to be true
  12. end
  13. it 'resets days to 0' do
  14. expect(subject.days).to be_zero
  15. end
  16. end
  17. describe '#track_failure!' do
  18. it 'marks URL as unavailable after 7 days of being called' do
  19. 6.times { |i| Redis.current.sadd('exhausted_deliveries:example.com', i) }
  20. subject.track_failure!
  21. expect(subject.days).to eq 7
  22. expect(described_class.available?('http://example.com/inbox')).to be false
  23. end
  24. it 'repeated calls on the same day do not count' do
  25. subject.track_failure!
  26. subject.track_failure!
  27. expect(subject.days).to eq 1
  28. end
  29. end
  30. describe '.without_unavailable' do
  31. before do
  32. Fabricate(:unavailable_domain, domain: 'foo.bar')
  33. end
  34. it 'removes URLs that are unavailable' do
  35. results = described_class.without_unavailable(['http://example.com/good/inbox', 'http://foo.bar/unavailable/inbox'])
  36. expect(results).to include('http://example.com/good/inbox')
  37. expect(results).to_not include('http://foo.bar/unavailable/inbox')
  38. end
  39. end
  40. describe '.reset!' do
  41. before do
  42. Fabricate(:unavailable_domain, domain: 'foo.bar')
  43. described_class.reset!('https://foo.bar/inbox')
  44. end
  45. it 'marks inbox URL as available again' do
  46. expect(described_class.available?('http://foo.bar/inbox')).to be true
  47. end
  48. end
  49. end