summaryrefslogtreecommitdiff
path: root/spec/mailers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 01:45:44 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 01:45:44 +0000
commit85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch)
tree9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/mailers
parent15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff)
downloadgitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/mailers')
-rw-r--r--spec/mailers/devise_mailer_spec.rb29
-rw-r--r--spec/mailers/emails/profile_spec.rb22
-rw-r--r--spec/mailers/notify_spec.rb216
3 files changed, 238 insertions, 29 deletions
diff --git a/spec/mailers/devise_mailer_spec.rb b/spec/mailers/devise_mailer_spec.rb
index 4637df9c8a3..2ee15308400 100644
--- a/spec/mailers/devise_mailer_spec.rb
+++ b/spec/mailers/devise_mailer_spec.rb
@@ -4,6 +4,9 @@ require 'spec_helper'
require 'email_spec'
RSpec.describe DeviseMailer do
+ include EmailSpec::Matchers
+ include_context 'gitlab email notification'
+
describe "#confirmation_instructions" do
subject { described_class.confirmation_instructions(user, 'faketoken', {}) }
@@ -35,4 +38,30 @@ RSpec.describe DeviseMailer do
end
end
end
+
+ describe '#password_change_by_admin' do
+ subject { described_class.password_change_by_admin(user) }
+
+ let_it_be(:user) { create(:user) }
+
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like 'a user cannot unsubscribe through footer link'
+
+ it 'is sent to the user' do
+ is_expected.to deliver_to user.email
+ end
+
+ it 'has the correct subject' do
+ is_expected.to have_subject /^Password changed by administrator$/i
+ end
+
+ it 'includes the correct content' do
+ is_expected.to have_body_text /An administrator changed the password for your GitLab account/
+ end
+
+ it 'includes a link to GitLab' do
+ is_expected.to have_body_text /#{Gitlab.config.gitlab.url}/
+ end
+ end
end
diff --git a/spec/mailers/emails/profile_spec.rb b/spec/mailers/emails/profile_spec.rb
index fbbdef5feee..fdff2d837f8 100644
--- a/spec/mailers/emails/profile_spec.rb
+++ b/spec/mailers/emails/profile_spec.rb
@@ -256,4 +256,26 @@ RSpec.describe Emails::Profile do
end
end
end
+
+ describe 'disabled two-factor authentication email' do
+ let_it_be(:user) { create(:user) }
+
+ subject { Notify.disabled_two_factor_email(user) }
+
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like 'a user cannot unsubscribe through footer link'
+
+ it 'is sent to the user' do
+ is_expected.to deliver_to user.email
+ end
+
+ it 'has the correct subject' do
+ is_expected.to have_subject /^Two-factor authentication disabled$/i
+ end
+
+ it 'includes a link to two-factor authentication settings page' do
+ is_expected.to have_body_text /#{profile_two_factor_auth_path}/
+ end
+ end
end
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index 7bd1fae8f91..b9f95a9eb00 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -868,36 +868,116 @@ RSpec.describe Notify do
end
end
- def invite_to_project(project, inviter:)
+ def invite_to_project(project, inviter:, user: nil)
create(
:project_member,
:developer,
project: project,
invite_token: '1234',
invite_email: 'toto@example.com',
- user: nil,
+ user: user,
created_by: inviter
)
end
describe 'project invitation' do
let(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } }
- let(:project_member) { invite_to_project(project, inviter: maintainer) }
+ let(:project_member) { invite_to_project(project, inviter: inviter) }
+ let(:inviter) { maintainer }
subject { described_class.member_invited_email('project', project_member.id, project_member.invite_token) }
- it_behaves_like 'an email sent from GitLab'
- it_behaves_like 'it should not have Gmail Actions links'
- it_behaves_like "a user cannot unsubscribe through footer link"
- it_behaves_like 'appearance header and footer enabled'
- it_behaves_like 'appearance header and footer not enabled'
+ context 'when invite_email_experiment is disabled' do
+ before do
+ stub_feature_flags(invite_email_experiment: false)
+ end
- it 'contains all the useful information' do
- is_expected.to have_subject "Invitation to join the #{project.full_name} project"
- is_expected.to have_body_text project.full_name
- is_expected.to have_body_text project.full_name
- is_expected.to have_body_text project_member.human_access
- is_expected.to have_body_text project_member.invite_token
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like "a user cannot unsubscribe through footer link"
+ it_behaves_like 'appearance header and footer enabled'
+ it_behaves_like 'appearance header and footer not enabled'
+
+ it 'contains all the useful information' do
+ is_expected.to have_subject "Invitation to join the #{project.full_name} project"
+ is_expected.to have_body_text project.full_name
+ is_expected.to have_body_text project_member.human_access
+ is_expected.to have_body_text project_member.invite_token
+ end
+
+ context 'when member is invited via an email address' do
+ it 'does add a param to the invite link' do
+ is_expected.to have_body_text 'new_user_invite=control'
+ end
+
+ it 'tracks an event' do
+ expect(Gitlab::Tracking).to receive(:event).with(
+ 'Growth::Acquisition::Experiment::InviteEmail',
+ 'sent',
+ property: 'control_group'
+ )
+
+ subject.deliver_now
+ end
+ end
+
+ context 'when member is already a user' do
+ let(:project_member) { invite_to_project(project, inviter: maintainer, user: create(:user)) }
+
+ it 'does not add a param to the invite link' do
+ is_expected.not_to have_body_text 'new_user_invite'
+ end
+
+ it 'does not track an event' do
+ expect(Gitlab::Tracking).not_to receive(:event)
+
+ subject.deliver_now
+ end
+ end
+ end
+
+ context 'when invite_email_experiment is enabled' do
+ before do
+ stub_feature_flags(invite_email_experiment: true)
+ end
+
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like "a user cannot unsubscribe through footer link"
+
+ context 'when there is no inviter' do
+ let(:inviter) { nil }
+
+ it 'contains all the useful information' do
+ is_expected.to have_subject "Invitation to join the #{project.full_name} project"
+ is_expected.to have_body_text project.full_name
+ is_expected.to have_body_text project_member.human_access.downcase
+ is_expected.to have_body_text project_member.invite_token
+ end
+ end
+
+ context 'when there is an inviter' do
+ it 'contains all the useful information' do
+ is_expected.to have_subject "#{inviter.name} invited you to join GitLab"
+ is_expected.to have_body_text project.full_name
+ is_expected.to have_body_text project_member.human_access.downcase
+ is_expected.to have_body_text project_member.invite_token
+ end
+ end
+
+ it 'adds a param to the invite link' do
+ is_expected.to have_body_text 'new_user_invite=experiment'
+ end
+
+ it 'tracks an event' do
+ expect(Gitlab::Tracking).to receive(:event).with(
+ 'Growth::Acquisition::Experiment::InviteEmail',
+ 'sent',
+ property: 'experiment_group'
+ )
+
+ subject.deliver_now
+ end
end
end
@@ -1416,37 +1496,115 @@ RSpec.describe Notify do
end
end
- def invite_to_group(group, inviter:)
+ def invite_to_group(group, inviter:, user: nil)
create(
:group_member,
:developer,
group: group,
invite_token: '1234',
invite_email: 'toto@example.com',
- user: nil,
+ user: user,
created_by: inviter
)
end
describe 'group invitation' do
let(:owner) { create(:user).tap { |u| group.add_user(u, Gitlab::Access::OWNER) } }
- let(:group_member) { invite_to_group(group, inviter: owner) }
+ let(:group_member) { invite_to_group(group, inviter: inviter) }
+ let(:inviter) { owner }
subject { described_class.member_invited_email('group', group_member.id, group_member.invite_token) }
- it_behaves_like 'an email sent from GitLab'
- it_behaves_like 'it should not have Gmail Actions links'
- it_behaves_like "a user cannot unsubscribe through footer link"
- it_behaves_like 'appearance header and footer enabled'
- it_behaves_like 'appearance header and footer not enabled'
- it_behaves_like 'it requires a group'
+ context 'when invite_email_experiment is disabled' do
+ before do
+ stub_feature_flags(invite_email_experiment: false)
+ end
- it 'contains all the useful information' do
- is_expected.to have_subject "Invitation to join the #{group.name} group"
- is_expected.to have_body_text group.name
- is_expected.to have_body_text group.web_url
- is_expected.to have_body_text group_member.human_access
- is_expected.to have_body_text group_member.invite_token
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like "a user cannot unsubscribe through footer link"
+ it_behaves_like 'appearance header and footer enabled'
+ it_behaves_like 'appearance header and footer not enabled'
+ it_behaves_like 'it requires a group'
+
+ it 'contains all the useful information' do
+ is_expected.to have_subject "Invitation to join the #{group.name} group"
+ is_expected.to have_body_text group.name
+ is_expected.to have_body_text group.web_url
+ is_expected.to have_body_text group_member.human_access
+ is_expected.to have_body_text group_member.invite_token
+ end
+
+ context 'when member is invited via an email address' do
+ it 'does add a param to the invite link' do
+ is_expected.to have_body_text 'new_user_invite=control'
+ end
+
+ it 'tracks an event' do
+ expect(Gitlab::Tracking).to receive(:event).with(
+ 'Growth::Acquisition::Experiment::InviteEmail',
+ 'sent',
+ property: 'control_group'
+ )
+
+ subject.deliver_now
+ end
+ end
+
+ context 'when member is already a user' do
+ let(:group_member) { invite_to_group(group, inviter: owner, user: create(:user)) }
+
+ it 'does not add a param to the invite link' do
+ is_expected.not_to have_body_text 'new_user_invite'
+ end
+
+ it 'does not track an event' do
+ expect(Gitlab::Tracking).not_to receive(:event)
+
+ subject.deliver_now
+ end
+ end
+ end
+
+ context 'when invite_email_experiment is enabled' do
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like "a user cannot unsubscribe through footer link"
+ it_behaves_like 'it requires a group'
+
+ context 'when there is no inviter' do
+ let(:inviter) { nil }
+
+ it 'contains all the useful information' do
+ is_expected.to have_subject "Invitation to join the #{group.name} group"
+ 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
+ end
+ end
+
+ context 'when there is an inviter' do
+ it 'contains all the useful information' do
+ is_expected.to have_subject "#{group_member.created_by.name} invited you to join GitLab"
+ 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
+ end
+ end
+
+ it 'does add a param to the invite link' do
+ is_expected.to have_body_text 'new_user_invite'
+ end
+
+ it 'tracks an event' do
+ expect(Gitlab::Tracking).to receive(:event).with(
+ 'Growth::Acquisition::Experiment::InviteEmail',
+ 'sent',
+ property: 'experiment_group'
+ )
+
+ subject.deliver_now
+ end
end
end