2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-16 14:49:42 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Jobs::TopicReminder do
|
|
|
|
let(:admin) { Fabricate(:admin) }
|
2017-07-24 01:13:23 -04:00
|
|
|
|
|
|
|
let(:topic) do
|
|
|
|
Fabricate(:topic_timer,
|
|
|
|
user: admin,
|
|
|
|
status_type: TopicTimer.types[:reminder]
|
|
|
|
).topic
|
|
|
|
end
|
2017-05-16 14:49:42 -04:00
|
|
|
|
|
|
|
it "should be able to create a reminder" do
|
|
|
|
topic_timer = topic.topic_timers.first
|
2017-07-24 09:17:42 -04:00
|
|
|
freeze_time 1.day.from_now
|
|
|
|
|
|
|
|
expect {
|
|
|
|
described_class.new.execute(topic_timer_id: topic_timer.id)
|
|
|
|
}.to change { Notification.count }.by(1)
|
2017-07-27 21:20:09 -04:00
|
|
|
expect(admin.notifications.where(notification_type: Notification.types[:topic_reminder]).first&.topic_id).to eq(topic.id)
|
|
|
|
expect(TopicTimer.where(id: topic_timer.id).first).to be_nil
|
2017-05-16 14:49:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does nothing if it was trashed before the scheduled time" do
|
|
|
|
topic_timer = topic.topic_timers.first
|
|
|
|
topic_timer.trash!(Discourse.system_user)
|
2017-07-24 09:17:42 -04:00
|
|
|
|
|
|
|
freeze_time(1.day.from_now)
|
|
|
|
|
|
|
|
expect {
|
|
|
|
described_class.new.execute(topic_timer_id: topic_timer.id)
|
|
|
|
}.to_not change { Notification.count }
|
2017-05-16 14:49:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does nothing if job runs too early" do
|
|
|
|
topic_timer = topic.topic_timers.first
|
|
|
|
topic_timer.update_attribute(:execute_at, 8.hours.from_now)
|
2017-07-24 09:17:42 -04:00
|
|
|
|
|
|
|
freeze_time(6.hours.from_now)
|
|
|
|
|
|
|
|
expect {
|
|
|
|
described_class.new.execute(topic_timer_id: topic_timer.id)
|
|
|
|
}.to_not change { Notification.count }
|
2017-05-16 14:49:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does nothing if topic was deleted" do
|
|
|
|
topic_timer = topic.topic_timers.first
|
|
|
|
topic.trash!
|
2017-07-24 09:17:42 -04:00
|
|
|
|
|
|
|
freeze_time(1.day.from_now)
|
|
|
|
|
|
|
|
expect {
|
|
|
|
described_class.new.execute(topic_timer_id: topic_timer.id)
|
|
|
|
}.to_not change { Notification.count }
|
2017-05-16 14:49:42 -04:00
|
|
|
end
|
2017-07-24 01:13:23 -04:00
|
|
|
|
2017-05-16 21:37:11 -04:00
|
|
|
end
|