diff options
Diffstat (limited to 'spec/services/notification_service_spec.rb')
-rw-r--r-- | spec/services/notification_service_spec.rb | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 07a1be6c12b..120bfc6d0ca 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -2315,6 +2315,7 @@ describe NotificationService, :mailer do user = create_user_with_notification(:custom, 'custom_enabled') update_custom_notification(:success_pipeline, user, resource: project) update_custom_notification(:failed_pipeline, user, resource: project) + update_custom_notification(:fixed_pipeline, user, resource: project) user end @@ -2322,6 +2323,7 @@ describe NotificationService, :mailer do user = create_user_with_notification(:custom, 'custom_disabled') update_custom_notification(:success_pipeline, user, resource: project, value: false) update_custom_notification(:failed_pipeline, user, resource: project, value: false) + update_custom_notification(:fixed_pipeline, user, resource: project, value: false) user end @@ -2514,6 +2516,85 @@ describe NotificationService, :mailer do end end end + + context 'with a fixed pipeline' do + let(:ref_status) { 'fixed' } + + context 'when the creator has no custom notification set' do + let(:pipeline) { create_pipeline(u_member, :success) } + + it 'emails only the creator' do + notification.pipeline_finished(pipeline, ref_status: ref_status) + + should_only_email(u_member, kind: :bcc) + end + + it_behaves_like 'project emails are disabled' do + let(:notification_target) { pipeline } + let(:notification_trigger) { notification.pipeline_finished(pipeline, ref_status: ref_status) } + end + + context 'when the creator has group notification email set' do + let(:group_notification_email) { 'user+group@example.com' } + + before do + group = create(:group) + + project.update(group: group) + create(:notification_setting, user: u_member, source: group, notification_email: group_notification_email) + end + + it 'sends to group notification email' do + notification.pipeline_finished(pipeline, ref_status: ref_status) + + expect(email_recipients(kind: :bcc).first).to eq(group_notification_email) + end + end + end + + context 'when the creator has watch set' do + before do + pipeline = create_pipeline(u_watcher, :success) + notification.pipeline_finished(pipeline, ref_status: ref_status) + end + + it 'emails only the creator' do + should_only_email(u_watcher, kind: :bcc) + end + end + + context 'when the creator has custom notifications, but without any set' do + before do + pipeline = create_pipeline(u_custom_notification_unset, :success) + notification.pipeline_finished(pipeline, ref_status: ref_status) + end + + it 'emails only the creator' do + should_only_email(u_custom_notification_unset, kind: :bcc) + end + end + + context 'when the creator has custom notifications disabled' do + before do + pipeline = create_pipeline(u_custom_notification_disabled, :success) + notification.pipeline_finished(pipeline, ref_status: ref_status) + end + + it 'notifies nobody' do + should_not_email_anyone + end + end + + context 'when the creator has custom notifications set' do + it 'emails only the creator' do + pipeline = create_pipeline(u_custom_notification_enabled, :success) + + notification.pipeline_finished(pipeline, ref_status: ref_status) + + should_only_email(u_custom_notification_enabled, kind: :bcc) + end + end + end end end |