diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/mailers | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/mailers')
-rw-r--r-- | spec/mailers/emails/in_product_marketing_spec.rb | 49 | ||||
-rw-r--r-- | spec/mailers/emails/pipelines_spec.rb | 21 | ||||
-rw-r--r-- | spec/mailers/notify_spec.rb | 87 |
3 files changed, 129 insertions, 28 deletions
diff --git a/spec/mailers/emails/in_product_marketing_spec.rb b/spec/mailers/emails/in_product_marketing_spec.rb index 99beef92dea..3b92b049e42 100644 --- a/spec/mailers/emails/in_product_marketing_spec.rb +++ b/spec/mailers/emails/in_product_marketing_spec.rb @@ -47,22 +47,31 @@ RSpec.describe Emails::InProductMarketing do end 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 - :experience | 0 + :create | 0 + :create | 1 + :create | 2 + :verify | 0 + :verify | 1 + :verify | 2 + :trial | 0 + :trial | 1 + :trial | 2 + :team | 0 + :team | 1 + :team | 2 + :experience | 0 + :team_short | 0 + :trial_short | 0 + :admin_verify | 0 + :invite_team | 0 end with_them do + before do + stub_experiments(invite_members_for_task: :candidate) + group.add_owner(user) + end + it 'has the correct subject and content' do message = Gitlab::Email::Message::InProductMarketing.for(track).new(group: group, user: user, series: series) @@ -76,6 +85,20 @@ RSpec.describe Emails::InProductMarketing do else is_expected.to have_body_text(CGI.unescapeHTML(message.cta_link)) end + + if track =~ /(create|verify)/ + is_expected.to have_body_text(message.invite_text) + is_expected.to have_body_text(CGI.unescapeHTML(message.invite_link)) + else + is_expected.not_to have_body_text(message.invite_text) + is_expected.not_to have_body_text(CGI.unescapeHTML(message.invite_link)) + end + + if track == :invite_team + is_expected.not_to have_body_text(/This is email \d of \d/) + else + is_expected.to have_body_text(message.progress) + end end end end diff --git a/spec/mailers/emails/pipelines_spec.rb b/spec/mailers/emails/pipelines_spec.rb index b9bc53625ac..3a2eb105964 100644 --- a/spec/mailers/emails/pipelines_spec.rb +++ b/spec/mailers/emails/pipelines_spec.rb @@ -71,10 +71,19 @@ RSpec.describe Emails::Pipelines do end end + shared_examples_for 'only accepts a single recipient' do + let(:recipient) { ['test@gitlab.com', 'test2@gitlab.com'] } + + it 'raises an ArgumentError' do + expect { subject.deliver_now }.to raise_error(ArgumentError) + end + end + describe '#pipeline_success_email' do - subject { Notify.pipeline_success_email(pipeline, pipeline.user.try(:email)) } + subject { Notify.pipeline_success_email(pipeline, recipient) } let(:pipeline) { create(:ci_pipeline, project: project, ref: ref, sha: sha) } + let(:recipient) { pipeline.user.try(:email) } let(:ref) { 'master' } let(:sha) { project.commit(ref).sha } @@ -93,12 +102,15 @@ RSpec.describe Emails::Pipelines do stub_config_setting(email_subject_suffix: email_subject_suffix) end end + + it_behaves_like 'only accepts a single recipient' end describe '#pipeline_failed_email' do - subject { Notify.pipeline_failed_email(pipeline, pipeline.user.try(:email)) } + subject { Notify.pipeline_failed_email(pipeline, recipient) } let(:pipeline) { create(:ci_pipeline, project: project, ref: ref, sha: sha) } + let(:recipient) { pipeline.user.try(:email) } let(:ref) { 'master' } let(:sha) { project.commit(ref).sha } @@ -106,12 +118,15 @@ RSpec.describe Emails::Pipelines do let(:status) { 'Failed' } let(:status_text) { "Pipeline ##{pipeline.id} has failed!" } end + + it_behaves_like 'only accepts a single recipient' end describe '#pipeline_fixed_email' do subject { Notify.pipeline_fixed_email(pipeline, pipeline.user.try(:email)) } let(:pipeline) { create(:ci_pipeline, project: project, ref: ref, sha: sha) } + let(:recipient) { pipeline.user.try(:email) } let(:ref) { 'master' } let(:sha) { project.commit(ref).sha } @@ -119,5 +134,7 @@ RSpec.describe Emails::Pipelines do let(:status) { 'Fixed' } let(:status_text) { "Pipeline has been fixed and ##{pipeline.id} has passed!" } end + + it_behaves_like 'only accepts a single recipient' end end diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index f39037cf744..a5e3350ec2e 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Notify do include EmailSpec::Matchers include EmailHelpers include RepoHelpers + include MembersHelper include_context 'gitlab email notification' @@ -720,11 +721,8 @@ RSpec.describe Notify do end describe 'project access denied' do - let(:project) { create(:project, :public) } - let(:project_member) do - project.request_access(user) - project.requesters.find_by(user_id: user.id) - end + let_it_be(:project) { create(:project, :public) } + let_it_be(:project_member) { create(:project_member, :developer, :access_request, user: user, source: project) } subject { described_class.member_access_denied_email('project', project.id, user.id) } @@ -739,6 +737,17 @@ RSpec.describe Notify do is_expected.to have_body_text project.full_name is_expected.to have_body_text project.web_url end + + context 'when user can not read project' do + let_it_be(:project) { create(:project, :private) } + + it 'hides project name from subject and body' do + is_expected.to have_subject "Access to the Hidden project was denied" + is_expected.to have_body_text "Hidden project" + is_expected.not_to have_body_text project.full_name + is_expected.not_to have_body_text project.web_url + end + end end describe 'project access changed' do @@ -761,10 +770,21 @@ RSpec.describe Notify do is_expected.to have_body_text project_member.human_access is_expected.to have_body_text 'leave the project' is_expected.to have_body_text project_url(project, leave: 1) + is_expected.not_to have_body_text 'You were assigned the following tasks:' + end + + context 'with tasks to be done present' do + let(:project_member) { create(:project_member, project: project, user: user, tasks_to_be_done: [:ci, :code]) } + + it 'contains the assigned tasks to be done' do + is_expected.to have_body_text 'You were assigned the following tasks:' + is_expected.to have_body_text localized_tasks_to_be_done_choices[:ci] + is_expected.to have_body_text localized_tasks_to_be_done_choices[:code] + end end end - def invite_to_project(project, inviter:, user: nil) + def invite_to_project(project, inviter:, user: nil, tasks_to_be_done: []) create( :project_member, :developer, @@ -772,7 +792,8 @@ RSpec.describe Notify do invite_token: '1234', invite_email: 'toto@example.com', user: user, - created_by: inviter + created_by: inviter, + tasks_to_be_done: tasks_to_be_done ) end @@ -804,6 +825,7 @@ RSpec.describe Notify do is_expected.to have_content("#{inviter.name} invited you to join the") is_expected.to have_content('Project details') is_expected.to have_content("What's it about?") + is_expected.not_to have_body_text 'and has assigned you the following tasks:' end end @@ -890,6 +912,16 @@ RSpec.describe Notify do end end end + + context 'with tasks to be done present', :aggregate_failures do + let(:project_member) { invite_to_project(project, inviter: inviter, tasks_to_be_done: [:ci, :code]) } + + it 'contains the assigned tasks to be done' do + is_expected.to have_body_text 'and has assigned you the following tasks:' + is_expected.to have_body_text localized_tasks_to_be_done_choices[:ci] + is_expected.to have_body_text localized_tasks_to_be_done_choices[:code] + end + end end describe 'project invitation accepted' do @@ -1351,10 +1383,8 @@ RSpec.describe Notify do end describe 'group access denied' do - let(:group_member) do - group.request_access(user) - group.requesters.find_by(user_id: user.id) - end + let_it_be(:group) { create(:group, :public) } + let_it_be(:group_member) { create(:group_member, :developer, :access_request, user: user, source: group) } let(:recipient) { user } @@ -1372,6 +1402,17 @@ RSpec.describe Notify do is_expected.to have_body_text group.name is_expected.to have_body_text group.web_url end + + context 'when user can not read group' do + let_it_be(:group) { create(:group, :private) } + + it 'hides group name from subject and body' do + is_expected.to have_subject "Access to the Hidden group was denied" + is_expected.to have_body_text "Hidden group" + is_expected.not_to have_body_text group.name + is_expected.not_to have_body_text group.web_url + end + end end describe 'group access changed' do @@ -1398,7 +1439,7 @@ RSpec.describe Notify do end end - def invite_to_group(group, inviter:, user: nil) + def invite_to_group(group, inviter:, user: nil, tasks_to_be_done: []) create( :group_member, :developer, @@ -1406,7 +1447,8 @@ RSpec.describe Notify do invite_token: '1234', invite_email: 'toto@example.com', user: user, - created_by: inviter + created_by: inviter, + tasks_to_be_done: tasks_to_be_done ) end @@ -1431,6 +1473,7 @@ RSpec.describe Notify do is_expected.to have_body_text group.name is_expected.to have_body_text group_member.human_access.downcase is_expected.to have_body_text group_member.invite_token + is_expected.not_to have_body_text 'and has assigned you the following tasks:' end end @@ -1444,6 +1487,24 @@ RSpec.describe Notify do is_expected.to have_body_text group_member.invite_token end end + + context 'with tasks to be done present', :aggregate_failures do + let(:group_member) { invite_to_group(group, inviter: inviter, tasks_to_be_done: [:ci, :code]) } + + it 'contains the assigned tasks to be done' do + is_expected.to have_body_text 'and has assigned you the following tasks:' + is_expected.to have_body_text localized_tasks_to_be_done_choices[:ci] + is_expected.to have_body_text localized_tasks_to_be_done_choices[:code] + end + + context 'when there is no inviter' do + let(:inviter) { nil } + + it 'does not contain the assigned tasks to be done' do + is_expected.not_to have_body_text 'and has assigned you the following tasks:' + end + end + end end describe 'group invitation reminders' do |