summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorEugenia Grieff <egrieff@gitlab.com>2019-06-12 15:55:09 +0000
committerNick Thomas <nick@gitlab.com>2019-06-12 15:55:09 +0000
commitef5235cb2d3491e453dc72ca2553dd5a384354ba (patch)
treea4a87fa5fa77a238c96339bb56a78f0650c81f5e /spec/models
parent14fef15194ba7e2989aa5e9cdef85772028a8ce3 (diff)
downloadgitlab-ce-ef5235cb2d3491e453dc72ca2553dd5a384354ba.tar.gz
Resolve "Email notifications do not work properly (issue due date)"
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/notification_recipient_spec.rb233
1 files changed, 233 insertions, 0 deletions
diff --git a/spec/models/notification_recipient_spec.rb b/spec/models/notification_recipient_spec.rb
index 1b1ede6b14c..20278d81f6d 100644
--- a/spec/models/notification_recipient_spec.rb
+++ b/spec/models/notification_recipient_spec.rb
@@ -91,4 +91,237 @@ describe NotificationRecipient do
end
end
end
+
+ describe '#suitable_notification_level?' do
+ context 'when notification level is mention' do
+ before do
+ user.notification_settings_for(project).mention!
+ end
+
+ context 'when type is mention' do
+ let(:recipient) { described_class.new(user, :mention, target: target, project: project) }
+
+ it 'returns true' do
+ expect(recipient.suitable_notification_level?).to eq true
+ end
+ end
+
+ context 'when type is not mention' do
+ it 'returns false' do
+ expect(recipient.suitable_notification_level?).to eq false
+ end
+ end
+ end
+
+ context 'when notification level is participating' do
+ let(:notification_setting) { user.notification_settings_for(project) }
+
+ context 'when type is participating' do
+ let(:recipient) { described_class.new(user, :participating, target: target, project: project) }
+
+ it 'returns true' do
+ expect(recipient.suitable_notification_level?).to eq true
+ end
+ end
+
+ context 'when type is mention' do
+ let(:recipient) { described_class.new(user, :mention, target: target, project: project) }
+
+ it 'returns true' do
+ expect(recipient.suitable_notification_level?).to eq true
+ end
+ end
+
+ context 'with custom action' do
+ context "when action is failed_pipeline" do
+ let(:recipient) do
+ described_class.new(
+ user,
+ :watch,
+ custom_action: :failed_pipeline,
+ target: target,
+ project: project
+ )
+ end
+
+ before do
+ notification_setting.update!(failed_pipeline: true)
+ end
+
+ it 'returns true' do
+ expect(recipient.suitable_notification_level?).to eq true
+ end
+ end
+
+ context "when action is not failed_pipeline" do
+ let(:recipient) do
+ described_class.new(
+ user,
+ :watch,
+ custom_action: :success_pipeline,
+ target: target,
+ project: project
+ )
+ end
+
+ before do
+ notification_setting.update!(success_pipeline: true)
+ end
+
+ it 'returns false' do
+ expect(recipient.suitable_notification_level?).to eq false
+ end
+ end
+ end
+ end
+
+ context 'when notification level is custom' do
+ before do
+ user.notification_settings_for(project).custom!
+ end
+
+ context 'when type is participating' do
+ let(:notification_setting) { user.notification_settings_for(project) }
+ let(:recipient) do
+ described_class.new(
+ user,
+ :participating,
+ custom_action: :new_note,
+ target: target,
+ project: project
+ )
+ end
+
+ context 'with custom event enabled' do
+ before do
+ notification_setting.update!(new_note: true)
+ end
+
+ it 'returns true' do
+ expect(recipient.suitable_notification_level?).to eq true
+ end
+ end
+
+ context 'without custom event enabled' do
+ before do
+ notification_setting.update!(new_note: false)
+ end
+
+ it 'returns true' do
+ expect(recipient.suitable_notification_level?).to eq true
+ end
+ end
+ end
+
+ context 'when type is mention' do
+ let(:notification_setting) { user.notification_settings_for(project) }
+ let(:recipient) do
+ described_class.new(
+ user,
+ :mention,
+ custom_action: :new_issue,
+ target: target,
+ project: project
+ )
+ end
+
+ context 'with custom event enabled' do
+ before do
+ notification_setting.update!(new_issue: true)
+ end
+
+ it 'returns true' do
+ expect(recipient.suitable_notification_level?).to eq true
+ end
+ end
+
+ context 'without custom event enabled' do
+ before do
+ notification_setting.update!(new_issue: false)
+ end
+
+ it 'returns true' do
+ expect(recipient.suitable_notification_level?).to eq true
+ end
+ end
+ end
+
+ context 'when type is watch' do
+ let(:notification_setting) { user.notification_settings_for(project) }
+ let(:recipient) do
+ described_class.new(
+ user,
+ :watch,
+ custom_action: :failed_pipeline,
+ target: target,
+ project: project
+ )
+ end
+
+ context 'with custom event enabled' do
+ before do
+ notification_setting.update!(failed_pipeline: true)
+ end
+
+ it 'returns true' do
+ expect(recipient.suitable_notification_level?).to eq true
+ end
+ end
+
+ context 'without custom event enabled' do
+ before do
+ notification_setting.update!(failed_pipeline: false)
+ end
+
+ it 'returns false' do
+ expect(recipient.suitable_notification_level?).to eq false
+ end
+ end
+ end
+ end
+
+ context 'when notification level is watch' do
+ before do
+ user.notification_settings_for(project).watch!
+ end
+
+ context 'when type is watch' do
+ context 'without excluded watcher events' do
+ it 'returns true' do
+ expect(recipient.suitable_notification_level?).to eq true
+ end
+ end
+
+ context 'with excluded watcher events' do
+ let(:recipient) do
+ described_class.new(user, :watch, custom_action: :issue_due, target: target, project: project)
+ end
+
+ it 'returns false' do
+ expect(recipient.suitable_notification_level?).to eq false
+ end
+ end
+ end
+
+ context 'when type is not watch' do
+ context 'without excluded watcher events' do
+ let(:recipient) { described_class.new(user, :participating, target: target, project: project) }
+
+ it 'returns true' do
+ expect(recipient.suitable_notification_level?).to eq true
+ end
+ end
+
+ context 'with excluded watcher events' do
+ let(:recipient) do
+ described_class.new(user, :participating, custom_action: :issue_due, target: target, project: project)
+ end
+
+ it 'returns true' do
+ expect(recipient.suitable_notification_level?).to eq true
+ end
+ end
+ end
+ end
+ end
end