feat: Add a job to clear notifications that were created before 1 month (#8732)
This commit is contained in:
24
spec/jobs/notification/remove_old_notification_job_spec.rb
Normal file
24
spec/jobs/notification/remove_old_notification_job_spec.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Notification::RemoveOldNotificationJob do
|
||||
let(:user) { create(:user) }
|
||||
let(:conversation) { create(:conversation) }
|
||||
|
||||
it 'enqueues the job' do
|
||||
notification = create(:notification, user: user, notification_type: 'conversation_creation', primary_actor: conversation)
|
||||
expect do
|
||||
described_class.perform_later(notification)
|
||||
end.to have_enqueued_job(described_class)
|
||||
.on_queue('low')
|
||||
end
|
||||
|
||||
it 'removes old notifications which are older than 1 month' do
|
||||
create(:notification, user: user, notification_type: 'conversation_creation', primary_actor: conversation, created_at: 2.months.ago)
|
||||
create(:notification, user: user, notification_type: 'conversation_creation', primary_actor: conversation, created_at: 1.month.ago)
|
||||
create(:notification, user: user, notification_type: 'conversation_creation', primary_actor: conversation, created_at: 1.day.ago)
|
||||
create(:notification, user: user, notification_type: 'conversation_creation', primary_actor: conversation, created_at: 1.hour.ago)
|
||||
|
||||
described_class.perform_now
|
||||
expect(Notification.count).to eq(2)
|
||||
end
|
||||
end
|
||||
@@ -40,5 +40,10 @@ RSpec.describe TriggerScheduledItemsJob do
|
||||
expect(Channels::Whatsapp::TemplatesSyncSchedulerJob).to receive(:perform_later).once
|
||||
described_class.perform_now
|
||||
end
|
||||
|
||||
it 'triggers Notification::RemoveOldNotificationJob' do
|
||||
expect(Notification::RemoveOldNotificationJob).to receive(:perform_later).once
|
||||
described_class.perform_now
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user