pull/10886/head
ulferts 2 years ago
parent 67e0039f72
commit a16dfcfad9
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 4
      app/services/notifications/create_from_model_service.rb
  2. 32
      spec/services/notifications/create_from_model_service_work_package_spec.rb

@ -87,7 +87,7 @@ class Notifications::CreateFromModelService
resource:, resource:,
journal:, journal:,
actor: user_with_fallback, actor: user_with_fallback,
reason: reason, reason:,
read_ian: strategy.supports_ian? ? false : nil, read_ian: strategy.supports_ian? ? false : nil,
mail_reminder_sent: strategy.supports_mail_digest? ? false : nil, mail_reminder_sent: strategy.supports_mail_digest? ? false : nil,
mail_alert_sent: strategy.supports_mail? ? false : nil mail_alert_sent: strategy.supports_mail? ? false : nil
@ -111,7 +111,7 @@ class Notifications::CreateFromModelService
def delete_outdated_notifications(current_recipient_ids) def delete_outdated_notifications(current_recipient_ids)
Notification Notification
.where(journal: journal) .where(journal:)
.where.not(recipient_id: current_recipient_ids) .where.not(recipient_id: current_recipient_ids)
.destroy_all .destroy_all
end end

@ -137,7 +137,7 @@ describe Notifications::CreateFromModelService,
end end
end end
context 'assignee has all notifications disabled' do context 'when assignee has all notifications disabled' do
let(:recipient_notification_settings) do let(:recipient_notification_settings) do
[ [
build(:notification_setting, **notification_settings_all_false) build(:notification_setting, **notification_settings_all_false)
@ -147,7 +147,7 @@ describe Notifications::CreateFromModelService,
it_behaves_like 'creates no notification' it_behaves_like 'creates no notification'
end end
context 'assignee has all in app notifications enabled but only involved for mail' do context 'when assignee has all in app notifications enabled but only involved for mail' do
let(:recipient_notification_settings) do let(:recipient_notification_settings) do
[ [
build(:notification_setting, **notification_settings_all_false.merge(involved: true)) build(:notification_setting, **notification_settings_all_false.merge(involved: true))
@ -166,13 +166,13 @@ describe Notifications::CreateFromModelService,
end end
end end
context 'assignee is not allowed to view work packages' do context 'when assignee is not allowed to view work packages' do
let(:permissions) { [] } let(:permissions) { [] }
it_behaves_like 'creates no notification' it_behaves_like 'creates no notification'
end end
context 'assignee is placeholder user' do context 'when assignee is placeholder user' do
let(:recipient) { create :placeholder_user } let(:recipient) { create :placeholder_user }
it_behaves_like 'creates no notification' it_behaves_like 'creates no notification'
@ -721,8 +721,8 @@ describe Notifications::CreateFromModelService,
end end
shared_examples_for 'group mention' do shared_examples_for 'group mention' do
context 'group member is allowed to view the work package' do context 'with a group member allowed to view the work package' do
context 'user wants to receive notifications' do context 'when the user wants to receive notifications' do
it_behaves_like 'creates notification' do it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do let(:notification_channel_reasons) do
{ {
@ -735,7 +735,7 @@ describe Notifications::CreateFromModelService,
end end
end end
context 'user disabled mention notifications' do context 'when the user disabled mention notifications' do
let(:recipient_notification_settings) do let(:recipient_notification_settings) do
[ [
build(:notification_setting, **notification_settings_all_false.merge(mentioned: false)) build(:notification_setting, **notification_settings_all_false.merge(mentioned: false))
@ -746,13 +746,13 @@ describe Notifications::CreateFromModelService,
end end
end end
context 'group is not allowed to view the work package' do context 'with the group not allowed to view the work package' do
let(:group_role) { create(:role, permissions: []) } let(:group_role) { create(:role, permissions: []) }
let(:permissions) { [] } let(:permissions) { [] }
it_behaves_like 'creates no notification' it_behaves_like 'creates no notification'
context 'but group member is allowed individually' do context 'with the group member allowed individually' do
let(:permissions) { [:view_work_packages] } let(:permissions) { [:view_work_packages] }
it_behaves_like 'creates notification' do it_behaves_like 'creates notification' do
@ -914,8 +914,8 @@ describe Notifications::CreateFromModelService,
it 'removes the existing notification' do it 'removes the existing notification' do
call call
expect(Notification.exists?(id: existing_notification.id)) expect(Notification)
.to be_falsey .not_to exist(id: existing_notification.id)
end end
end end
end end
@ -930,7 +930,7 @@ describe Notifications::CreateFromModelService,
end end
end end
context 'on a hash/id based mention' do context 'with a hash/id based mention' do
let(:note) do let(:note) do
"Hello group##{group.id}" "Hello group##{group.id}"
end end
@ -938,7 +938,7 @@ describe Notifications::CreateFromModelService,
it_behaves_like 'group mention' it_behaves_like 'group mention'
end end
context 'on a tag based mention with the type after' do context 'with a tag based mention with the type after' do
let(:note) do let(:note) do
<<~NOTE <<~NOTE
Hello <mention class="mention" data-id="#{group.id}" data-type="group" data-text="@#{group.name}">@#{group.name}</mention> Hello <mention class="mention" data-id="#{group.id}" data-type="group" data-text="@#{group.name}">@#{group.name}</mention>
@ -948,7 +948,7 @@ describe Notifications::CreateFromModelService,
it_behaves_like 'group mention' it_behaves_like 'group mention'
end end
context 'on a tag based mention with the type before' do context 'with a tag based mention with the type before' do
let(:note) do let(:note) do
<<~NOTE <<~NOTE
Hello <mention data-type="group" class="mention" data-id="#{group.id}" data-text="@#{group.name}">@#{group.name}</mention> Hello <mention data-type="group" class="mention" data-id="#{group.id}" data-text="@#{group.name}">@#{group.name}</mention>
@ -1027,8 +1027,8 @@ describe Notifications::CreateFromModelService,
it 'removes the existing notifications' do it 'removes the existing notifications' do
call call
expect(Notification.exists?(id: existing_notification.id)) expect(Notification)
.to be_falsey .not_to exist(id: existing_notification.id)
end end
end end

Loading…
Cancel
Save