mirror of
https://github.com/Evolix/chexpire.git
synced 2024-06-27 11:32:52 +02:00
9886e978fe
NB: domain recurrent failures notification conditions needs to be implemented.
55 lines
1.7 KiB
Ruby
55 lines
1.7 KiB
Ruby
require "test_helper"
|
|
|
|
module Notifier
|
|
class ProcessorTest < ActiveSupport::TestCase
|
|
test "#process_expires_soon sends an email for checks expiring soon" do
|
|
create_list(:notification, 3, :email, check: build(:check, :expires_next_week))
|
|
create(:notification, :email, check: build(:check, :nil_dates))
|
|
create(:notification, :email, check: build(:check, :inactive))
|
|
|
|
processor = Processor.new
|
|
assert_difference "ActionMailer::Base.deliveries.size", +3 do
|
|
processor.process_expires_soon
|
|
end
|
|
|
|
last_email = ActionMailer::Base.deliveries.last
|
|
assert_match "expires in 7 days", last_email.subject
|
|
end
|
|
|
|
test "#process_expires_soon respects the interval configuration between sends" do
|
|
create_list(:notification, 3, :email, check: build(:check, :expires_next_week))
|
|
test_interval_respected(:process_expires_soon, 3)
|
|
end
|
|
|
|
test "#process_recurrent_failures respects the interval configuration between sends" do
|
|
create_list(:notification, 3, :email, check: build(:check, :last_runs_failed))
|
|
test_interval_respected(:process_recurrent_failures, 3)
|
|
end
|
|
|
|
private
|
|
|
|
# rubocop:disable Metrics/MethodLength
|
|
def test_interval_respected(process_method, count_expected)
|
|
configuration = Minitest::Mock.new
|
|
count_expected.times do
|
|
configuration.expect(:interval, 0.000001)
|
|
end
|
|
processor = Processor.new(configuration)
|
|
|
|
mock = Minitest::Mock.new
|
|
assert_stub = lambda { |actual_time|
|
|
assert_equal 0.000001, actual_time
|
|
mock
|
|
}
|
|
|
|
processor.stub :sleep, assert_stub do
|
|
processor.public_send(process_method)
|
|
end
|
|
|
|
configuration.verify
|
|
mock.verify
|
|
end
|
|
# rubocop:enable Metrics/MethodLength
|
|
end
|
|
end
|