DEV: Replace 'processed' column on notifications with new table (#11864)

This commit is contained in:
Mark VanLandingham
2021-01-27 10:29:24 -06:00
committed by GitHub
parent 60f10e9067
commit 809274fe0d
12 changed files with 61 additions and 46 deletions
@@ -17,21 +17,21 @@ describe Jobs::ProcessShelvedNotifications do
expect(DoNotDisturbTiming.find_by(id: past.id)).to eq(nil)
end
it "does not process unprocessed notifications when the user is in DND" do
it "does not process shelved_notifications when the user is in DND" do
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)
expect(notification.reload.processed).to eq(false)
expect(notification.shelved_notification).to be_present
subject.execute({})
expect(notification.reload.processed).to eq(false)
expect(notification.shelved_notification).to be_present
end
it "processes unprocessed notifications when the user leaves DND" do
it "processes and destroys shelved_notifications when the user leaves DND" do
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)
expect(notification.reload.processed).to eq(false)
expect(notification.shelved_notification).to be_present
subject.execute({})
expect(notification.reload.processed).to eq(true)
expect { notification.shelved_notification.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
+6 -7
View File
@@ -495,7 +495,6 @@ describe Notification do
expect { notification.reload }.to raise_error(ActiveRecord::RecordNotFound)
notification = Notification.last
expect(notification.processed).to eq(true)
expect(notification.notification_type).to eq(Notification.types[:membership_request_consolidated])
data = notification.data_hash
@@ -516,7 +515,7 @@ describe Notification do
notification = Notification.last
expect(notification.notification_type).to eq(Notification.types[:membership_request_consolidated])
expect(notification.processed).to eq(false)
expect(notification.shelved_notification).to be_present
end
end
end
@@ -543,18 +542,18 @@ describe Notification do
end
end
describe "processed" do
describe "do not disturb" do
fab!(:user) { Fabricate(:user) }
it "is false after creation when the user is in do not disturb" do
it "creates a shelved_notification record when created while user is in DND" do
user.do_not_disturb_timings.create(starts_at: Time.now, ends_at: 3.days.from_now)
notification = Notification.create(read: false, user_id: user.id, topic_id: 2, post_number: 1, data: '{}', notification_type: 1)
expect(notification.processed).to be(false)
expect(notification.shelved_notification).to be_present
end
it "is true after creation when the user isn't in do not disturb" do
it "doesn't create a shelved_notification record when created while user is isn't DND" do
notification = Notification.create(read: false, user_id: user.id, topic_id: 2, post_number: 1, data: '{}', notification_type: 1)
expect(notification.processed).to be(true)
expect(notification.shelved_notification).to be_nil
end
end
end
@@ -44,13 +44,14 @@ describe DoNotDisturbController do
end
describe "#destroy" do
it "process notifications that came in during DND" do
it "process shelved notifications that came in during DND" do
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)
expect(notification.processed).to eq(false)
expect(notification.shelved_notification).to be_present
delete "/do-not-disturb.json"
expect(notification.reload.processed).to eq(true)
expect { notification.shelved_notification.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect(user.do_not_disturb?).to eq(false)
end
end
end