diff options
Diffstat (limited to 'spec/mailers')
-rw-r--r-- | spec/mailers/emails/in_product_marketing_spec.rb | 44 | ||||
-rw-r--r-- | spec/mailers/emails/merge_requests_spec.rb | 200 | ||||
-rw-r--r-- | spec/mailers/emails/pipelines_spec.rb | 2 | ||||
-rw-r--r-- | spec/mailers/emails/profile_spec.rb | 9 | ||||
-rw-r--r-- | spec/mailers/emails/service_desk_spec.rb | 11 | ||||
-rw-r--r-- | spec/mailers/notify_spec.rb | 112 |
6 files changed, 253 insertions, 125 deletions
diff --git a/spec/mailers/emails/in_product_marketing_spec.rb b/spec/mailers/emails/in_product_marketing_spec.rb new file mode 100644 index 00000000000..e4157eaf5dc --- /dev/null +++ b/spec/mailers/emails/in_product_marketing_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'email_spec' + +RSpec.describe Emails::InProductMarketing do + include EmailSpec::Matchers + include InProductMarketingHelper + + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group) } + + describe '#in_product_marketing_email' do + using RSpec::Parameterized::TableSyntax + + where(:track, :series) do + :create | 0 + :create | 1 + :create | 2 + :verify | 0 + :verify | 1 + :verify | 2 + :trial | 0 + :trial | 1 + :trial | 2 + :team | 0 + :team | 1 + :team | 2 + end + + with_them do + subject { Notify.in_product_marketing_email(user.id, group.id, track, series) } + + it 'has the correct subject and content' do + aggregate_failures do + is_expected.to have_subject(subject_line(track, series)) + is_expected.to have_body_text(in_product_marketing_title(track, series)) + is_expected.to have_body_text(in_product_marketing_subtitle(track, series)) + is_expected.to have_body_text(in_product_marketing_cta_text(track, series)) + end + end + end + end +end diff --git a/spec/mailers/emails/merge_requests_spec.rb b/spec/mailers/emails/merge_requests_spec.rb index 34665d943ab..0c0dae6d7e6 100644 --- a/spec/mailers/emails/merge_requests_spec.rb +++ b/spec/mailers/emails/merge_requests_spec.rb @@ -6,37 +6,199 @@ require 'email_spec' RSpec.describe Emails::MergeRequests do include EmailSpec::Matchers - describe "#resolved_all_discussions_email" do - let(:user) { create(:user) } - let(:merge_request) { create(:merge_request) } - let(:current_user) { create(:user) } + 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 + create(:merge_request, source_project: project, + target_project: project, + author: current_user, + assignees: [assignee], + reviewers: [reviewer], + description: 'Awesome description') + end - subject { Notify.resolved_all_discussions_email(user.id, merge_request.id, current_user.id) } + let(:recipient) { assignee } + let(:current_user_sanitized) { 'www_example_com' } - it "includes the name of the resolver" do - expect(subject).to have_body_text current_user.name + 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)) + is_expected.to have_body_text('You have been mentioned in Merge Request') + 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 + sender = subject.header[:from].addrs[0] + expect(sender.display_name).to eq(merge_request.author.name) + expect(sender.address).to eq(gitlab_sender) + 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) + is_expected.to have_text_part_content(reviewer.name) + 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 + sender = subject.header[:from].addrs[0] + expect(sender.display_name).to eq(current_user.name) + expect(sender.address).to eq(gitlab_sender) + 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 + sender = subject.header[:from].addrs[0] + expect(sender.display_name).to eq(merge_author.name) + expect(sender.address).to eq(gitlab_sender) + 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 + sender = subject.header[:from].addrs[0] + expect(sender.display_name).to eq(current_user.name) + expect(sender.address).to eq(gitlab_sender) + 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 end end describe "#merge_when_pipeline_succeeds_email" do - let(:user) { create(:user) } - let(:merge_request) { create(:merge_request) } - let(:current_user) { create(:user) } - let(:project) { create(:project, :repository) } let(:title) { "Merge request #{merge_request.to_reference} was scheduled to merge after pipeline succeeds by #{current_user.name}" } - subject { Notify.merge_when_pipeline_succeeds_email(user.id, merge_request.id, current_user.id) } + subject { Notify.merge_when_pipeline_succeeds_email(recipient.id, merge_request.id, current_user.id) } it "has required details" do - expect(subject).to have_content title - expect(subject).to have_content merge_request.to_reference - expect(subject).to have_content current_user.name + 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 + + 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 end end describe '#merge_requests_csv_email' do - let(:user) { create(:user) } - let(:project) { create(:project) } let(:merge_requests) { create_list(:merge_request, 10) } let(:export_status) do { @@ -48,10 +210,10 @@ RSpec.describe Emails::MergeRequests do let(:csv_data) { MergeRequests::ExportCsvService.new(MergeRequest.all, project).csv_data } - subject { Notify.merge_requests_csv_email(user, project, csv_data, export_status) } + subject { Notify.merge_requests_csv_email(recipient, project, csv_data, export_status) } it { expect(subject.subject).to eq("#{project.name} | Exported merge requests") } - it { expect(subject.to).to contain_exactly(user.notification_email_for(project.group)) } + it { expect(subject.to).to contain_exactly(recipient.notification_email_for(project.group)) } 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") } diff --git a/spec/mailers/emails/pipelines_spec.rb b/spec/mailers/emails/pipelines_spec.rb index 3ac68721357..a29835f3439 100644 --- a/spec/mailers/emails/pipelines_spec.rb +++ b/spec/mailers/emails/pipelines_spec.rb @@ -89,7 +89,7 @@ RSpec.describe Emails::Pipelines do let(:sha) { project.commit(ref).sha } it_behaves_like 'correct pipeline information' do - let(:status) { 'Succesful' } + let(:status) { 'Successful' } let(:status_text) { "Pipeline ##{pipeline.id} has passed!" } end end diff --git a/spec/mailers/emails/profile_spec.rb b/spec/mailers/emails/profile_spec.rb index fdff2d837f8..a32e566fc90 100644 --- a/spec/mailers/emails/profile_spec.rb +++ b/spec/mailers/emails/profile_spec.rb @@ -125,8 +125,9 @@ RSpec.describe Emails::Profile do describe 'user personal access token is about to expire' do let_it_be(:user) { create(:user) } + let_it_be(:expiring_token) { create(:personal_access_token, user: user, expires_at: 5.days.from_now) } - subject { Notify.access_token_about_to_expire_email(user) } + subject { Notify.access_token_about_to_expire_email(user, [expiring_token.name]) } it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' @@ -137,13 +138,17 @@ RSpec.describe Emails::Profile do end it 'has the correct subject' do - is_expected.to have_subject /^Your Personal Access Tokens will expire in 7 days or less$/i + is_expected.to have_subject /^Your personal access tokens will expire in 7 days or less$/i end it 'mentions the access tokens will expire' do is_expected.to have_body_text /One or more of your personal access tokens will expire in 7 days or less/ end + it 'provides the names of expiring tokens' do + is_expected.to have_body_text /#{expiring_token.name}/ + end + it 'includes a link to personal access tokens page' do is_expected.to have_body_text /#{profile_personal_access_tokens_path}/ end diff --git a/spec/mailers/emails/service_desk_spec.rb b/spec/mailers/emails/service_desk_spec.rb index 7d04b373be6..cb74194020d 100644 --- a/spec/mailers/emails/service_desk_spec.rb +++ b/spec/mailers/emails/service_desk_spec.rb @@ -13,8 +13,13 @@ RSpec.describe Emails::ServiceDesk do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:issue) { create(:issue, project: project) } + let_it_be(:email) { 'someone@gitlab.com' } let(:template) { double(content: template_content) } + before_all do + issue.issue_email_participants.create!(email: email) + end + before do stub_const('ServiceEmailClass', Class.new(ApplicationMailer)) @@ -72,6 +77,10 @@ RSpec.describe Emails::ServiceDesk do let(:template_content) { 'custom text' } let(:issue) { create(:issue, project: project)} + before do + issue.issue_email_participants.create!(email: email) + end + context 'when a template is in the repository' do let(:project) { create(:project, :custom_repo, files: { ".gitlab/service_desk_templates/#{template_key}.md" => template_content }) } @@ -151,7 +160,7 @@ RSpec.describe Emails::ServiceDesk do let_it_be(:note) { create(:note_on_issue, noteable: issue, project: project) } let_it_be(:default_text) { note.note } - subject { ServiceEmailClass.service_desk_new_note_email(issue.id, note.id) } + subject { ServiceEmailClass.service_desk_new_note_email(issue.id, note.id, email) } it_behaves_like 'read template from repository', 'new_note' diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 89cf1aaedd2..79358d3e40c 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -16,12 +16,14 @@ RSpec.describe Notify do let_it_be(:user, reload: true) { create(:user) } 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(:merge_request) do create(:merge_request, source_project: project, target_project: project, author: current_user, assignees: [assignee], + reviewers: [reviewer], description: 'Awesome description') end @@ -342,6 +344,7 @@ RSpec.describe Notify do is_expected.to have_body_text(project_merge_request_path(project, merge_request)) is_expected.to have_body_text(merge_request.source_branch) is_expected.to have_body_text(merge_request.target_branch) + is_expected.to have_body_text(reviewer.name) end end @@ -362,7 +365,11 @@ RSpec.describe Notify do it 'contains a link to merge request author' do is_expected.to have_body_text merge_request.author_name - is_expected.to have_body_text 'created a merge request:' + is_expected.to have_body_text 'created a' + end + + it 'contains a link to the merge request url' do + is_expected.to have_link('merge request', href: project_merge_request_url(merge_request.target_project, merge_request)) end end @@ -461,106 +468,6 @@ RSpec.describe Notify do end end - describe 'status changed' do - let(:status) { 'reopened' } - - subject { described_class.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 - sender = subject.header[:from].addrs[0] - expect(sender.display_name).to eq(current_user.name) - expect(sender.address).to eq(gitlab_sender) - 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)) - end - end - end - - describe 'that are merged' do - let(:merge_author) { create(:user) } - - subject { described_class.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 - sender = subject.header[:from].addrs[0] - expect(sender.display_name).to eq(merge_author.name) - expect(sender.address).to eq(gitlab_sender) - 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)) - end - end - end - - describe 'that are unmergeable' do - let_it_be(:merge_request) do - create(:merge_request, :conflict, - source_project: project, - target_project: project, - author: current_user, - assignees: [assignee], - description: 'Awesome description') - end - - subject { described_class.merge_request_unmergeable_email(recipient.id, merge_request.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 request author' do - sender = subject.header[:from].addrs[0] - expect(sender.display_name).to eq(merge_request.author.name) - expect(sender.address).to eq(gitlab_sender) - 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)) - end - end - end - shared_examples 'a push to an existing merge request' do let(:push_user) { create(:user) } @@ -1311,6 +1218,7 @@ RSpec.describe Notify do context 'for service desk issues' do before do issue.update!(external_author: 'service.desk@example.com') + issue.issue_email_participants.create!(email: 'service.desk@example.com') end def expect_sender(username) @@ -1359,7 +1267,7 @@ RSpec.describe Notify do describe 'new note email' do let_it_be(:first_note) { create(:discussion_note_on_issue, note: 'Hello world') } - subject { described_class.service_desk_new_note_email(issue.id, first_note.id) } + subject { described_class.service_desk_new_note_email(issue.id, first_note.id, 'service.desk@example.com') } it_behaves_like 'an unsubscribeable thread' |