2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
require 'email_spec'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Emails::MergeRequests do
|
2016-09-13 17:45:13 +05:30
|
|
|
include EmailSpec::Matchers
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
include_context 'gitlab email notification'
|
|
|
|
|
|
|
|
let_it_be(:current_user, reload: true) { create(:user, email: "current@email.com", name: 'www.example.com') }
|
|
|
|
let_it_be(:assignee, reload: true) { create(:user, email: 'assignee@example.com', name: 'John Doe') }
|
|
|
|
let_it_be(:reviewer, reload: true) { create(:user, email: 'reviewer@example.com', name: 'Jane Doe') }
|
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
let_it_be(:merge_request) do
|
2023-07-09 08:55:56 +05:30
|
|
|
create(
|
|
|
|
:merge_request,
|
|
|
|
source_project: project,
|
|
|
|
target_project: project,
|
|
|
|
author: current_user,
|
|
|
|
assignees: [assignee],
|
|
|
|
reviewers: [reviewer],
|
|
|
|
description: 'Awesome description'
|
|
|
|
)
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
let(:recipient) { assignee }
|
|
|
|
let(:current_user_sanitized) { 'www_example_com' }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe '#new_mention_in_merge_request_email' do
|
|
|
|
subject { Notify.new_mention_in_merge_request_email(recipient.id, merge_request.id, current_user.id) }
|
|
|
|
|
|
|
|
it 'has the correct subject and body' do
|
|
|
|
aggregate_failures do
|
|
|
|
is_expected.to have_referable_subject(merge_request, reply: true)
|
|
|
|
is_expected.to have_body_text(project_merge_request_path(project, merge_request))
|
2021-04-29 21:17:54 +05:30
|
|
|
is_expected.to have_body_text('You have been mentioned in merge request')
|
2021-04-17 20:07:23 +05:30
|
|
|
is_expected.to have_link(merge_request.to_reference, href: project_merge_request_url(merge_request.target_project, merge_request))
|
|
|
|
is_expected.to have_text_part_content(assignee.name)
|
|
|
|
is_expected.to have_text_part_content(reviewer.name)
|
|
|
|
is_expected.to have_html_part_content(assignee.name)
|
|
|
|
is_expected.to have_html_part_content(reviewer.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#merge_request_unmergeable_email' do
|
|
|
|
subject { Notify.merge_request_unmergeable_email(recipient.id, merge_request.id) }
|
|
|
|
|
|
|
|
it_behaves_like 'an answer to an existing thread with reply-by-email enabled' do
|
|
|
|
let(:model) { merge_request }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a multiple recipients email'
|
|
|
|
it_behaves_like 'it should show Gmail Actions View Merge request link'
|
|
|
|
it_behaves_like 'an unsubscribeable thread'
|
|
|
|
it_behaves_like 'appearance header and footer enabled'
|
|
|
|
it_behaves_like 'appearance header and footer not enabled'
|
|
|
|
|
|
|
|
it 'is sent as the merge request author' do
|
2021-04-29 21:17:54 +05:30
|
|
|
expect_sender(merge_request.author)
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the correct subject and body' do
|
|
|
|
aggregate_failures do
|
|
|
|
is_expected.to have_referable_subject(merge_request, reply: true)
|
|
|
|
is_expected.to have_body_text(project_merge_request_path(project, merge_request))
|
|
|
|
is_expected.to have_body_text('due to conflict.')
|
|
|
|
is_expected.to have_link(merge_request.to_reference, href: project_merge_request_url(merge_request.target_project, merge_request))
|
|
|
|
is_expected.to have_text_part_content(assignee.name)
|
2022-07-16 23:28:13 +05:30
|
|
|
is_expected.to have_html_part_content(assignee.name)
|
2021-04-17 20:07:23 +05:30
|
|
|
is_expected.to have_text_part_content(reviewer.name)
|
2022-07-16 23:28:13 +05:30
|
|
|
is_expected.to have_html_part_content(reviewer.name)
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#closed_merge_request_email' do
|
|
|
|
subject { Notify.closed_merge_request_email(recipient.id, merge_request.id, current_user.id) }
|
|
|
|
|
|
|
|
it_behaves_like 'an answer to an existing thread with reply-by-email enabled' do
|
|
|
|
let(:model) { merge_request }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'it should show Gmail Actions View Merge request link'
|
|
|
|
it_behaves_like 'an unsubscribeable thread'
|
|
|
|
it_behaves_like 'appearance header and footer enabled'
|
|
|
|
it_behaves_like 'appearance header and footer not enabled'
|
|
|
|
|
|
|
|
it 'is sent as the author' do
|
2021-04-29 21:17:54 +05:30
|
|
|
expect_sender(current_user)
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the correct subject and body' do
|
|
|
|
aggregate_failures do
|
|
|
|
is_expected.to have_referable_subject(merge_request, reply: true)
|
|
|
|
is_expected.to have_body_text('closed')
|
|
|
|
is_expected.to have_body_text(current_user_sanitized)
|
|
|
|
is_expected.to have_body_text(project_merge_request_path(project, merge_request))
|
|
|
|
is_expected.to have_link(merge_request.to_reference, href: project_merge_request_url(merge_request.target_project, merge_request))
|
|
|
|
|
|
|
|
expect(subject.text_part).to have_content(assignee.name)
|
|
|
|
expect(subject.text_part).to have_content(reviewer.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#merged_merge_request_email' do
|
|
|
|
let(:merge_author) { assignee }
|
|
|
|
|
|
|
|
subject { Notify.merged_merge_request_email(recipient.id, merge_request.id, merge_author.id) }
|
|
|
|
|
|
|
|
it_behaves_like 'a multiple recipients email'
|
|
|
|
it_behaves_like 'an answer to an existing thread with reply-by-email enabled' do
|
|
|
|
let(:model) { merge_request }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'it should show Gmail Actions View Merge request link'
|
|
|
|
it_behaves_like 'an unsubscribeable thread'
|
|
|
|
it_behaves_like 'appearance header and footer enabled'
|
|
|
|
it_behaves_like 'appearance header and footer not enabled'
|
|
|
|
|
|
|
|
it 'is sent as the merge author' do
|
2021-04-29 21:17:54 +05:30
|
|
|
expect_sender(merge_author)
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the correct subject and body' do
|
|
|
|
aggregate_failures do
|
|
|
|
is_expected.to have_referable_subject(merge_request, reply: true)
|
|
|
|
is_expected.to have_body_text('merged')
|
|
|
|
is_expected.to have_body_text(project_merge_request_path(project, merge_request))
|
|
|
|
is_expected.to have_link(merge_request.to_reference, href: project_merge_request_url(merge_request.target_project, merge_request))
|
|
|
|
|
|
|
|
expect(subject.text_part).to have_content(assignee.name)
|
|
|
|
expect(subject.text_part).to have_content(reviewer.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#merge_request_status_email' do
|
|
|
|
let(:status) { 'reopened' }
|
|
|
|
|
|
|
|
subject { Notify.merge_request_status_email(recipient.id, merge_request.id, status, current_user.id) }
|
|
|
|
|
|
|
|
it_behaves_like 'an answer to an existing thread with reply-by-email enabled' do
|
|
|
|
let(:model) { merge_request }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'it should show Gmail Actions View Merge request link'
|
|
|
|
it_behaves_like 'an unsubscribeable thread'
|
|
|
|
it_behaves_like 'appearance header and footer enabled'
|
|
|
|
it_behaves_like 'appearance header and footer not enabled'
|
|
|
|
|
|
|
|
it 'is sent as the author' do
|
2021-04-29 21:17:54 +05:30
|
|
|
expect_sender(current_user)
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the correct subject and body' do
|
|
|
|
aggregate_failures do
|
|
|
|
is_expected.to have_referable_subject(merge_request, reply: true)
|
|
|
|
is_expected.to have_body_text(status)
|
|
|
|
is_expected.to have_body_text(current_user_sanitized)
|
|
|
|
is_expected.to have_body_text(project_merge_request_path(project, merge_request))
|
|
|
|
is_expected.to have_link(merge_request.to_reference, href: project_merge_request_url(merge_request.target_project, merge_request))
|
|
|
|
|
|
|
|
expect(subject.text_part).to have_content(assignee.name)
|
|
|
|
expect(subject.text_part).to have_content(reviewer.name)
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
describe "#merge_when_pipeline_succeeds_email" do
|
|
|
|
let(:title) { "Merge request #{merge_request.to_reference} was scheduled to merge after pipeline succeeds by #{current_user.name}" }
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
subject { Notify.merge_when_pipeline_succeeds_email(recipient.id, merge_request.id, current_user.id) }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
it "has required details" do
|
2021-04-17 20:07:23 +05:30
|
|
|
aggregate_failures do
|
|
|
|
is_expected.to have_content(title)
|
|
|
|
is_expected.to have_content(merge_request.to_reference)
|
|
|
|
is_expected.to have_content(current_user.name)
|
|
|
|
is_expected.to have_text_part_content(assignee.name)
|
|
|
|
is_expected.to have_html_part_content(assignee.name)
|
|
|
|
is_expected.to have_text_part_content(reviewer.name)
|
|
|
|
is_expected.to have_html_part_content(reviewer.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
describe '#approved_merge_request_email' do
|
|
|
|
subject { Notify.approved_merge_request_email(recipient.id, merge_request.id, current_user.id) }
|
|
|
|
|
|
|
|
it 'has the correct body' do
|
|
|
|
aggregate_failures do
|
|
|
|
is_expected.to have_body_text('was approved by')
|
|
|
|
is_expected.to have_body_text(current_user.name)
|
|
|
|
is_expected.to have_text_part_content(assignee.name)
|
|
|
|
is_expected.to have_html_part_content(assignee.name)
|
|
|
|
is_expected.to have_text_part_content(reviewer.name)
|
|
|
|
is_expected.to have_html_part_content(reviewer.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#unapproved_merge_request_email' do
|
|
|
|
subject { Notify.unapproved_merge_request_email(recipient.id, merge_request.id, current_user.id) }
|
|
|
|
|
|
|
|
it 'has the correct body' do
|
|
|
|
aggregate_failures do
|
|
|
|
is_expected.to have_body_text('was unapproved by')
|
|
|
|
is_expected.to have_body_text(current_user.name)
|
|
|
|
is_expected.to have_text_part_content(assignee.name)
|
|
|
|
is_expected.to have_html_part_content(assignee.name)
|
|
|
|
is_expected.to have_text_part_content(reviewer.name)
|
|
|
|
is_expected.to have_html_part_content(reviewer.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe "#resolved_all_discussions_email" do
|
|
|
|
subject { Notify.resolved_all_discussions_email(recipient.id, merge_request.id, current_user.id) }
|
|
|
|
|
|
|
|
it "includes the name of the resolver" do
|
|
|
|
expect(subject).to have_body_text current_user_sanitized
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
describe '#merge_requests_csv_email' do
|
|
|
|
let(:merge_requests) { create_list(:merge_request, 10) }
|
|
|
|
let(:export_status) do
|
|
|
|
{
|
|
|
|
rows_expected: 10,
|
|
|
|
rows_written: 10,
|
|
|
|
truncated: false
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:csv_data) { MergeRequests::ExportCsvService.new(MergeRequest.all, project).csv_data }
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
subject { Notify.merge_requests_csv_email(recipient, project, csv_data, export_status) }
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
it { expect(subject.subject).to eq("#{project.name} | Exported merge requests") }
|
2021-04-17 20:07:23 +05:30
|
|
|
it { expect(subject.to).to contain_exactly(recipient.notification_email_for(project.group)) }
|
2021-01-29 00:20:46 +05:30
|
|
|
it { expect(subject.html_part).to have_content("Your CSV export of 10 merge requests from project") }
|
|
|
|
it { expect(subject.text_part).to have_content("Your CSV export of 10 merge requests from project") }
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
context 'when truncated' do
|
|
|
|
let(:export_status) do
|
|
|
|
{
|
|
|
|
rows_expected: 10,
|
|
|
|
rows_written: 10,
|
|
|
|
truncated: true
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it { expect(subject).to have_content('attachment has been truncated to avoid exceeding the maximum allowed attachment size of 15 MB.') }
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
def expect_sender(user)
|
|
|
|
sender = subject.header[:from].addrs[0]
|
|
|
|
expect(sender.display_name).to eq("#{user.name} (@#{user.username})")
|
|
|
|
expect(sender.address).to eq(gitlab_sender)
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|