2021-01-07 10:49:49 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe Jobs::ProcessShelvedNotifications do
|
2023-06-21 09:00:19 -05:00
|
|
|
subject(:job) { described_class.new }
|
|
|
|
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:user)
|
2021-01-07 10:49:49 -06:00
|
|
|
let(:post) { Fabricate(:post) }
|
|
|
|
|
|
|
|
it "removes all past do not disturb timings" do
|
|
|
|
future = Fabricate(:do_not_disturb_timing, ends_at: 1.day.from_now)
|
|
|
|
past = Fabricate(:do_not_disturb_timing, starts_at: 2.day.ago, ends_at: 1.minute.ago)
|
|
|
|
|
2023-12-06 16:25:00 -06:00
|
|
|
expect { job.execute({}) }.to change { DoNotDisturbTiming.count }.by(-1)
|
2021-01-07 10:49:49 -06:00
|
|
|
expect(DoNotDisturbTiming.find_by(id: future.id)).to eq(future)
|
|
|
|
expect(DoNotDisturbTiming.find_by(id: past.id)).to eq(nil)
|
|
|
|
end
|
|
|
|
|
2021-01-27 10:29:24 -06:00
|
|
|
it "does not process shelved_notifications when the user is in DND" do
|
2021-01-07 10:49:49 -06:00
|
|
|
user.do_not_disturb_timings.create(starts_at: 2.days.ago, ends_at: 2.days.from_now)
|
|
|
|
notification =
|
|
|
|
Notification.create(
|
|
|
|
read: false,
|
|
|
|
user_id: user.id,
|
|
|
|
topic_id: 2,
|
|
|
|
post_number: 1,
|
|
|
|
data: "{}",
|
|
|
|
notification_type: 1,
|
|
|
|
)
|
2021-01-27 10:29:24 -06:00
|
|
|
expect(notification.shelved_notification).to be_present
|
2023-06-21 09:00:19 -05:00
|
|
|
job.execute({})
|
2021-01-27 10:29:24 -06:00
|
|
|
expect(notification.shelved_notification).to be_present
|
2021-01-07 10:49:49 -06:00
|
|
|
end
|
|
|
|
|
2021-01-27 10:29:24 -06:00
|
|
|
it "processes and destroys shelved_notifications when the user leaves DND" do
|
2021-01-07 10:49:49 -06:00
|
|
|
user.do_not_disturb_timings.create(starts_at: 2.days.ago, ends_at: 2.days.from_now)
|
|
|
|
notification =
|
|
|
|
Notification.create(
|
|
|
|
read: false,
|
|
|
|
user_id: user.id,
|
|
|
|
topic_id: 2,
|
|
|
|
post_number: 1,
|
|
|
|
data: "{}",
|
|
|
|
notification_type: 1,
|
|
|
|
)
|
|
|
|
user.do_not_disturb_timings.last.update(ends_at: 1.days.ago)
|
|
|
|
|
2021-01-27 10:29:24 -06:00
|
|
|
expect(notification.shelved_notification).to be_present
|
2023-06-21 09:00:19 -05:00
|
|
|
job.execute({})
|
2021-01-27 10:29:24 -06:00
|
|
|
expect { notification.shelved_notification.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
2021-01-07 10:49:49 -06:00
|
|
|
end
|
|
|
|
end
|