21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-05 18:25:09 +02:00
chexpire/test/services/notifier/channels/base_test.rb
Colin Darie ea610ee185
Notifications grouped of checks in error to user email.
This is not dependent of Notificatioon model.
2018-08-01 23:09:08 +02:00

62 lines
1.5 KiB
Ruby

require "test_helper"
module Notifier
module Channels
class BaseTest < ActiveSupport::TestCase
setup do
class FakeChannel < Base
def supports?(notification)
notification.interval < 1_000
end
def domain_notify_expires_soon(*); end
end
@channel = FakeChannel.new
end
test "#notify change the status of the notification" do
notification = create(:notification)
@channel.notify(notification)
notification.reload
assert notification.ongoing?
assert_just_now notification.sent_at
end
test "#notify raises an exception for a non supported check kind" do
notification = Minitest::Mock.new
notification.expect :ongoing!, true
notification.expect :interval, 10
check = Minitest::Mock.new
check.expect(:kind, :invalid_kind)
check.expect(:kind, :invalid_kind) # twice (second call for exception message)
notification.expect :check, check
notification.expect :check, check
assert_raises ArgumentError do
@channel.notify(notification)
end
check.verify
notification.verify
end
test "#notify does nothing when channel doesn't support a notification whatever the reason" do
notification = create(:notification, interval: 10_000)
@channel.notify(notification)
notification.reload
assert notification.pending?
assert_nil notification.sent_at
end
end
end
end