Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a job to reopen snoozed notifications (#8545)
- Loading branch information
Showing
4 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Notification::ReopenSnoozedNotificationsJob < ApplicationJob | ||
queue_as :low | ||
|
||
def perform | ||
# rubocop:disable Rails/SkipsModelValidations | ||
Notification.where(snoozed_until: 3.days.ago..Time.current) | ||
.update_all(snoozed_until: nil, updated_at: Time.current, last_activity_at: Time.current) | ||
# rubocop:enable Rails/SkipsModelValidations | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
spec/jobs/notification/reopen_snoozed_notifications_job_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Notification::ReopenSnoozedNotificationsJob do | ||
let!(:snoozed_till_5_minutes_ago) { create(:notification, snoozed_until: 5.minutes.ago) } | ||
let!(:snoozed_till_tomorrow) { create(:notification, snoozed_until: 1.day.from_now) } | ||
let!(:snoozed_indefinitely) { create(:notification) } | ||
|
||
it 'enqueues the job' do | ||
expect { described_class.perform_later }.to have_enqueued_job(described_class) | ||
.on_queue('low') | ||
end | ||
|
||
context 'when called' do | ||
it 'reopens snoozed notifications whose snooze until has passed' do | ||
described_class.perform_now | ||
|
||
expect(snoozed_till_5_minutes_ago.reload.snoozed_until).to be_nil | ||
expect(snoozed_till_tomorrow.reload.snoozed_until.to_date).to eq 1.day.from_now.to_date | ||
expect(snoozed_indefinitely.reload.snoozed_until).to be_nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters