Commit 847ae015 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'reduce-test-data-for-service-desk-issue-notifications' into 'master'

Reduce test data for service desk issue notifications

See merge request gitlab-org/gitlab!38195
parents 2d981327 cdc0e4d2
......@@ -292,6 +292,80 @@ RSpec.describe NotificationService, :mailer do
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
build_team(project)
project.add_maintainer(issue.author)
......@@ -313,8 +387,7 @@ RSpec.describe NotificationService, :mailer do
update_custom_notification(:new_note, @u_custom_global)
end
describe '#new_note' do
context do
context 'with users' do
before do
add_users(project)
add_user_subscriptions(issue)
......@@ -371,82 +444,10 @@ RSpec.describe NotificationService, :mailer do
it { expect { subject }.not_to have_enqueued_email(@u_lazy_participant.id, note.id, mail: "note_issue_email") }
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!
end
context 'in project that belongs to a group' do
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
note.project.namespace_id = group.id
group.add_user(@u_watcher, GroupMember::MAINTAINER)
......@@ -480,7 +481,8 @@ RSpec.describe NotificationService, :mailer do
end
end
let(:group) { create(:group) }
context 'which is a top-level group' do
let!(:group) { parent_group }
it_behaves_like 'new note notifications'
......@@ -488,17 +490,17 @@ RSpec.describe NotificationService, :mailer do
let(:notification_target) { note }
let(:notification_trigger) { notification.new_note(note) }
end
end
context 'which is a subgroup' do
let!(:parent) { create(:group) }
let!(:group) { create(:group, parent: parent) }
let!(:group) { create(:group, parent: parent_group) }
it_behaves_like 'new note notifications'
it 'overrides child objects with global level' do
user = create(:user)
parent.add_developer(user)
user.notification_settings_for(parent).watch!
parent_group.add_developer(user)
user.notification_settings_for(parent_group).watch!
reset_delivered_emails!
notification.new_note(note)
......@@ -508,6 +510,7 @@ RSpec.describe NotificationService, :mailer do
end
end
end
end
context 'confidential issue note' do
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