mirror of https://github.com/Evolix/chexpire.git
notifications tests use reliable test dates
This commit is contained in:
parent
a7010d7689
commit
d15ee5b300
|
@ -5,64 +5,62 @@ require "test_helper"
|
||||||
|
|
||||||
class NotificationsMailerTest < ActionMailer::TestCase # rubocop:disable Metrics/ClassLength
|
class NotificationsMailerTest < ActionMailer::TestCase # rubocop:disable Metrics/ClassLength
|
||||||
test "domain_expires_soon" do
|
test "domain_expires_soon" do
|
||||||
check = create(:check, domain_expires_at: Time.new(2018, 6, 10, 12, 0, 5, "+02:00"))
|
expiration_date = 8.days.from_now.utc
|
||||||
|
check = create(:check, domain_expires_at: expiration_date)
|
||||||
notification = build(:notification, interval: 10, recipient: "colin@example.org")
|
notification = build(:notification, interval: 10, recipient: "colin@example.org")
|
||||||
check_notification = build(:check_notification, check: check, notification: notification)
|
check_notification = build(:check_notification, check: check, notification: notification)
|
||||||
|
|
||||||
Date.stub :today, Date.new(2018, 6, 2) do
|
mail = NotificationsMailer.with(check_notification: check_notification).domain_expires_soon
|
||||||
mail = NotificationsMailer.with(check_notification: check_notification).domain_expires_soon
|
|
||||||
|
|
||||||
assert_emails 1 do
|
assert_emails 1 do
|
||||||
mail.deliver_now
|
mail.deliver_now
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_match "domain.fr", mail.subject
|
assert_match "domain.fr", mail.subject
|
||||||
assert_match "in 8 days", mail.subject
|
assert_match "in 8 days", mail.subject
|
||||||
assert_equal ["colin@example.org"], mail.to
|
assert_equal ["colin@example.org"], mail.to
|
||||||
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
||||||
|
|
||||||
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
||||||
|
|
||||||
parts.each do |part|
|
parts.each do |part|
|
||||||
assert_match "domain.fr", part
|
assert_match "domain.fr", part
|
||||||
assert_match "Sun, 10 Jun 2018 10:00:05 +0000", part
|
assert_match I18n.l(expiration_date, locale: :en), part
|
||||||
assert_match "10 days", part
|
assert_match "10 days", part
|
||||||
assert_match "/checks/#{check.id}/edit", part
|
assert_match "/checks/#{check.id}/edit", part
|
||||||
assert_no_match "comment", part
|
assert_no_match "comment", part
|
||||||
assert_no_match "vendor", part
|
assert_no_match "vendor", part
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "domain_expires_soon FR" do
|
test "domain_expires_soon FR" do
|
||||||
|
expiration_date = 8.days.from_now.utc
|
||||||
check = create(:check,
|
check = create(:check,
|
||||||
domain_expires_at: Time.new(2018, 6, 10, 12, 0, 5, "+02:00"),
|
domain_expires_at: expiration_date,
|
||||||
user: build(:user, :fr))
|
user: build(:user, :fr))
|
||||||
notification = build(:notification, interval: 10, recipient: "colin@example.org")
|
notification = build(:notification, interval: 10, recipient: "colin@example.org")
|
||||||
check_notification = build(:check_notification, check: check, notification: notification)
|
check_notification = build(:check_notification, check: check, notification: notification)
|
||||||
|
|
||||||
Date.stub :today, Date.new(2018, 6, 2) do
|
mail = NotificationsMailer.with(check_notification: check_notification).domain_expires_soon
|
||||||
mail = NotificationsMailer.with(check_notification: check_notification).domain_expires_soon
|
|
||||||
|
|
||||||
assert_emails 1 do
|
assert_emails 1 do
|
||||||
mail.deliver_now
|
mail.deliver_now
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_match "domain.fr", mail.subject
|
assert_match "domain.fr", mail.subject
|
||||||
assert_match "dans 8 jours", mail.subject
|
assert_match "dans 8 jours", mail.subject
|
||||||
assert_equal ["colin@example.org"], mail.to
|
assert_equal ["colin@example.org"], mail.to
|
||||||
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
||||||
|
|
||||||
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
||||||
|
|
||||||
parts.each do |part|
|
parts.each do |part|
|
||||||
assert_match "domain.fr", part
|
assert_match "domain.fr", part
|
||||||
assert_match "dim 10 juin 2018 10:00:05 +0000", part
|
assert_match I18n.l(expiration_date, locale: :fr), part
|
||||||
assert_match "10 jours", part
|
assert_match "10 jours", part
|
||||||
assert_match "/checks/#{check.id}/edit", part
|
assert_match "/checks/#{check.id}/edit", part
|
||||||
assert_no_match "commentaire", part
|
assert_no_match "commentaire", part
|
||||||
assert_no_match "fournisseur", part
|
assert_no_match "fournisseur", part
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -159,66 +157,64 @@ class NotificationsMailerTest < ActionMailer::TestCase # rubocop:disable Metrics
|
||||||
end
|
end
|
||||||
|
|
||||||
test "ssl_expires_soon" do
|
test "ssl_expires_soon" do
|
||||||
check = create(:check, :ssl, domain_expires_at: Time.new(2018, 6, 10, 12, 0, 5, "+02:00"))
|
expiration_date = 8.days.from_now.utc
|
||||||
|
check = create(:check, :ssl, domain_expires_at: 8.days.from_now)
|
||||||
notification = build(:notification, interval: 10, recipient: "colin@example.org")
|
notification = build(:notification, interval: 10, recipient: "colin@example.org")
|
||||||
check_notification = build(:check_notification, check: check, notification: notification)
|
check_notification = build(:check_notification, check: check, notification: notification)
|
||||||
|
|
||||||
Date.stub :today, Date.new(2018, 6, 2) do
|
mail = NotificationsMailer.with(check_notification: check_notification).ssl_expires_soon
|
||||||
mail = NotificationsMailer.with(check_notification: check_notification).ssl_expires_soon
|
|
||||||
|
|
||||||
assert_emails 1 do
|
assert_emails 1 do
|
||||||
mail.deliver_now
|
mail.deliver_now
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_match "domain.fr", mail.subject
|
assert_match "domain.fr", mail.subject
|
||||||
assert_match "SSL", mail.subject
|
assert_match "SSL", mail.subject
|
||||||
assert_match "in 8 days", mail.subject
|
assert_match "in 8 days", mail.subject
|
||||||
assert_equal ["colin@example.org"], mail.to
|
assert_equal ["colin@example.org"], mail.to
|
||||||
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
||||||
|
|
||||||
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
||||||
|
|
||||||
parts.each do |part|
|
parts.each do |part|
|
||||||
assert_match "domain.fr", part
|
assert_match "domain.fr", part
|
||||||
assert_match "Sun, 10 Jun 2018 10:00:05 +0000", part
|
assert_match I18n.l(expiration_date, locale: :en), part
|
||||||
assert_match "10 days", part
|
assert_match "10 days", part
|
||||||
assert_match "/checks/#{check.id}/edit", part
|
assert_match "/checks/#{check.id}/edit", part
|
||||||
assert_no_match "comment", part
|
assert_no_match "comment", part
|
||||||
assert_no_match "vendor", part
|
assert_no_match "vendor", part
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "ssl_expires_soon - FR" do
|
test "ssl_expires_soon - FR" do
|
||||||
|
expiration_date = 8.days.from_now.utc
|
||||||
check = create(:check, :ssl,
|
check = create(:check, :ssl,
|
||||||
domain_expires_at: Time.new(2018, 6, 10, 12, 0, 5, "+02:00"),
|
domain_expires_at: expiration_date,
|
||||||
user: build(:user, :fr))
|
user: build(:user, :fr))
|
||||||
notification = build(:notification, interval: 10, recipient: "colin@example.org")
|
notification = build(:notification, interval: 10, recipient: "colin@example.org")
|
||||||
check_notification = build(:check_notification, check: check, notification: notification)
|
check_notification = build(:check_notification, check: check, notification: notification)
|
||||||
|
|
||||||
Date.stub :today, Date.new(2018, 6, 2) do
|
mail = NotificationsMailer.with(check_notification: check_notification).ssl_expires_soon
|
||||||
mail = NotificationsMailer.with(check_notification: check_notification).ssl_expires_soon
|
|
||||||
|
|
||||||
assert_emails 1 do
|
assert_emails 1 do
|
||||||
mail.deliver_now
|
mail.deliver_now
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_match "domain.fr", mail.subject
|
assert_match "domain.fr", mail.subject
|
||||||
assert_match "SSL", mail.subject
|
assert_match "SSL", mail.subject
|
||||||
assert_match "dans 8 jours", mail.subject
|
assert_match "dans 8 jours", mail.subject
|
||||||
assert_equal ["colin@example.org"], mail.to
|
assert_equal ["colin@example.org"], mail.to
|
||||||
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
||||||
|
|
||||||
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
||||||
|
|
||||||
parts.each do |part|
|
parts.each do |part|
|
||||||
assert_match "domain.fr", part
|
assert_match "domain.fr", part
|
||||||
assert_match "dim 10 juin 2018 10:00:05 +0000", part
|
assert_match I18n.l(expiration_date, locale: :fr), part
|
||||||
assert_match "10 jours", part
|
assert_match "10 jours", part
|
||||||
assert_match "/checks/#{check.id}/edit", part
|
assert_match "/checks/#{check.id}/edit", part
|
||||||
assert_no_match "commentaire", part
|
assert_no_match "commentaire", part
|
||||||
assert_no_match "fournisseur", part
|
assert_no_match "fournisseur", part
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue