Commit cdc0e4d2 authored by Rémy Coutable's avatar Rémy Coutable

Reduce test data for service desk issue notifications

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent d0ed916b
...@@ -282,6 +282,80 @@ RSpec.describe NotificationService, :mailer do ...@@ -282,6 +282,80 @@ RSpec.describe NotificationService, :mailer do
subject { notification.new_note(note) } subject { notification.new_note(note) }
context 'on service desk issue' do
before do
allow(Notify).to receive(:service_desk_new_note_email)
.with(Integer, Integer).and_return(mailer)
allow(::Gitlab::IncomingEmail).to receive(:enabled?) { true }
allow(::Gitlab::IncomingEmail).to receive(:supports_wildcard?) { true }
end
let(:subject) { NotificationService.new }
let(:mailer) { double(deliver_later: true) }
def should_email!
expect(Notify).to receive(:service_desk_new_note_email)
.with(issue.id, note.id)
end
def should_not_email!
expect(Notify).not_to receive(:service_desk_new_note_email)
end
def execute!
subject.new_note(note)
end
def self.it_should_email!
it 'sends the email' do
should_email!
execute!
end
end
def self.it_should_not_email!
it 'doesn\'t send the email' do
should_not_email!
execute!
end
end
let(:issue) { create(:issue, author: User.support_bot) }
let(:project) { issue.project }
let(:note) { create(:note, noteable: issue, project: project) }
context 'a non-service-desk issue' do
it_should_not_email!
end
context 'a service-desk issue' do
before do
issue.update!(service_desk_reply_to: 'service.desk@example.com')
project.update!(service_desk_enabled: true)
end
it_should_email!
context 'where the project has disabled the feature' do
before do
project.update(service_desk_enabled: false)
end
it_should_not_email!
end
context 'when the support bot has unsubscribed' do
before do
issue.unsubscribe(User.support_bot, project)
end
it_should_not_email!
end
end
end
describe '#new_note' do
before do before do
build_team(project) build_team(project)
project.add_maintainer(issue.author) project.add_maintainer(issue.author)
...@@ -303,8 +377,7 @@ RSpec.describe NotificationService, :mailer do ...@@ -303,8 +377,7 @@ RSpec.describe NotificationService, :mailer do
update_custom_notification(:new_note, @u_custom_global) update_custom_notification(:new_note, @u_custom_global)
end end
describe '#new_note' do context 'with users' do
context do
before do before do
add_users(project) add_users(project)
add_user_subscriptions(issue) add_user_subscriptions(issue)
...@@ -361,82 +434,10 @@ RSpec.describe NotificationService, :mailer do ...@@ -361,82 +434,10 @@ RSpec.describe NotificationService, :mailer do
it { expect { subject }.not_to have_enqueued_email(@u_lazy_participant.id, note.id, mail: "note_issue_email") } it { expect { subject }.not_to have_enqueued_email(@u_lazy_participant.id, note.id, mail: "note_issue_email") }
end end
end end
end
context 'on service desk issue' do
before do
allow(Notify).to receive(:service_desk_new_note_email)
.with(Integer, Integer).and_return(mailer)
allow(::Gitlab::IncomingEmail).to receive(:enabled?) { true }
allow(::Gitlab::IncomingEmail).to receive(:supports_wildcard?) { true }
end
let(:subject) { NotificationService.new }
let(:mailer) { double(deliver_later: true) }
def should_email!
expect(Notify).to receive(:service_desk_new_note_email)
.with(issue.id, note.id)
end
def should_not_email!
expect(Notify).not_to receive(:service_desk_new_note_email)
end
def execute!
subject.new_note(note)
end
def self.it_should_email!
it 'sends the email' do
should_email!
execute!
end
end
def self.it_should_not_email!
it 'doesn\'t send the email' do
should_not_email!
execute!
end
end
let(:issue) { create(:issue, author: User.support_bot) }
let(:project) { issue.project }
let(:note) { create(:note, noteable: issue, project: project) }
context 'a non-service-desk issue' do
it_should_not_email!
end
context 'a service-desk issue' do
before do
issue.update!(service_desk_reply_to: 'service.desk@example.com')
project.update!(service_desk_enabled: true)
end
it_should_email!
context 'where the project has disabled the feature' do
before do
project.update(service_desk_enabled: false)
end
it_should_not_email! context 'in project that belongs to a group' do
end let_it_be(:parent_group) { create(:group) }
context 'when the support bot has unsubscribed' do
before do
issue.unsubscribe(User.support_bot, project)
end
it_should_not_email!
end
end
end
describe 'new note on issue in project that belongs to a group' do
before do before do
note.project.namespace_id = group.id note.project.namespace_id = group.id
group.add_user(@u_watcher, GroupMember::MAINTAINER) group.add_user(@u_watcher, GroupMember::MAINTAINER)
...@@ -470,7 +471,8 @@ RSpec.describe NotificationService, :mailer do ...@@ -470,7 +471,8 @@ RSpec.describe NotificationService, :mailer do
end end
end end
let(:group) { create(:group) } context 'which is a top-level group' do
let!(:group) { parent_group }
it_behaves_like 'new note notifications' it_behaves_like 'new note notifications'
...@@ -478,17 +480,17 @@ RSpec.describe NotificationService, :mailer do ...@@ -478,17 +480,17 @@ RSpec.describe NotificationService, :mailer do
let(:notification_target) { note } let(:notification_target) { note }
let(:notification_trigger) { notification.new_note(note) } let(:notification_trigger) { notification.new_note(note) }
end end
end
context 'which is a subgroup' do context 'which is a subgroup' do
let!(:parent) { create(:group) } let!(:group) { create(:group, parent: parent_group) }
let!(:group) { create(:group, parent: parent) }
it_behaves_like 'new note notifications' it_behaves_like 'new note notifications'
it 'overrides child objects with global level' do it 'overrides child objects with global level' do
user = create(:user) user = create(:user)
parent.add_developer(user) parent_group.add_developer(user)
user.notification_settings_for(parent).watch! user.notification_settings_for(parent_group).watch!
reset_delivered_emails! reset_delivered_emails!
notification.new_note(note) notification.new_note(note)
...@@ -498,6 +500,7 @@ RSpec.describe NotificationService, :mailer do ...@@ -498,6 +500,7 @@ RSpec.describe NotificationService, :mailer do
end end
end end
end end
end
context 'confidential issue note' do context 'confidential issue note' do
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment