2017-09-29 01:16:20 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe DeliveryFailureTracker do
|
|
|
|
subject { described_class.new('http://example.com/inbox') }
|
|
|
|
|
|
|
|
describe '#track_success!' do
|
|
|
|
before do
|
|
|
|
subject.track_failure!
|
|
|
|
subject.track_success!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'marks URL as available again' do
|
|
|
|
expect(described_class.available?('http://example.com/inbox')).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'resets days to 0' do
|
|
|
|
expect(subject.days).to be_zero
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#track_failure!' do
|
|
|
|
it 'marks URL as unavailable after 7 days of being called' do
|
2022-04-28 15:47:34 +00:00
|
|
|
6.times { |i| redis.sadd('exhausted_deliveries:example.com', i) }
|
2017-09-29 01:16:20 +00:00
|
|
|
subject.track_failure!
|
|
|
|
|
|
|
|
expect(subject.days).to eq 7
|
2020-04-15 18:33:24 +00:00
|
|
|
expect(described_class.available?('http://example.com/inbox')).to be false
|
2017-09-29 01:16:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'repeated calls on the same day do not count' do
|
|
|
|
subject.track_failure!
|
|
|
|
subject.track_failure!
|
|
|
|
|
|
|
|
expect(subject.days).to eq 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-15 18:33:24 +00:00
|
|
|
describe '.without_unavailable' do
|
2017-09-29 01:16:20 +00:00
|
|
|
before do
|
2020-04-15 18:33:24 +00:00
|
|
|
Fabricate(:unavailable_domain, domain: 'foo.bar')
|
2017-09-29 01:16:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes URLs that are unavailable' do
|
2020-04-15 18:33:24 +00:00
|
|
|
results = described_class.without_unavailable(['http://example.com/good/inbox', 'http://foo.bar/unavailable/inbox'])
|
2017-09-29 01:16:20 +00:00
|
|
|
|
2020-04-15 18:33:24 +00:00
|
|
|
expect(results).to include('http://example.com/good/inbox')
|
|
|
|
expect(results).to_not include('http://foo.bar/unavailable/inbox')
|
2017-09-29 01:16:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-15 18:33:24 +00:00
|
|
|
describe '.reset!' do
|
2017-09-29 01:16:20 +00:00
|
|
|
before do
|
2020-04-15 18:33:24 +00:00
|
|
|
Fabricate(:unavailable_domain, domain: 'foo.bar')
|
|
|
|
described_class.reset!('https://foo.bar/inbox')
|
2017-09-29 01:16:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'marks inbox URL as available again' do
|
2020-04-15 18:33:24 +00:00
|
|
|
expect(described_class.available?('http://foo.bar/inbox')).to be true
|
2017-09-29 01:16:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|