Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Ensure existing unread notifications are marked as read

Kabiru Mwenjacd74446e4caf
diff --git a/spec/factories/reminders_factory.rb b/spec/factories/reminders_factory.rb
index 982038d75e7..c1b1bd0d50d 100644
--- a/spec/factories/reminders_factory.rb
+++ b/spec/factories/reminders_factory.rb
@@ -39,13 +39,13 @@ FactoryBot.define do
trait :with_unread_notifications do
after(:create) do |reminder|
- create(:reminder_notification, reminder: reminder, notification: create(:notification, read_ian: false))
+ create(:reminder_notification, reminder:, notification: create(:notification, read_ian: false))
end
end
trait :with_read_notifications do
after(:create) do |reminder|
- create(:reminder_notification, reminder: reminder, notification: create(:notification, read_ian: true))
+ create(:reminder_notification, reminder:, notification: create(:notification, read_ian: true))
end
end
end
diff --git a/spec/services/reminders/update_service_spec.rb b/spec/services/reminders/update_service_spec.rb
index 1f4822a6f1d..441597c7fa9 100644
--- a/spec/services/reminders/update_service_spec.rb
+++ b/spec/services/reminders/update_service_spec.rb
@@ -39,7 +39,7 @@ RSpec.describe Reminders::UpdateService do
describe "remind_at changed" do
subject { described_class.new(user:, model: model_instance).call(call_attributes) }
- let(:model_instance) { create(:reminder, :scheduled, creator: user, job_id: 1) }
+ let(:model_instance) { create(:reminder, :scheduled, :with_unread_notifications, creator: user, job_id: 1) }
let(:user) { create(:admin) }
let(:call_attributes) { { remind_at: 2.days.from_now } }
@@ -64,6 +64,11 @@ RSpec.describe Reminders::UpdateService do
expect(job).to have_received(:destroy)
end
+ aggregate_failures "marks unread notifications as read" do
+ expect(model_instance.notifications.count).to eq(1)
+ expect(model_instance.unread_notifications.count).to eq(0)
+ end
+
aggregate_failures "schedule new job" do
expect(Reminders::ScheduleReminderJob).to have_received(:schedule).with(model_instance)
end