summaryrefslogtreecommitdiff
path: root/spec/mailers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/mailers')
-rw-r--r--spec/mailers/emails/pipelines_spec.rb41
-rw-r--r--spec/mailers/emails/projects_spec.rb21
-rw-r--r--spec/mailers/notify_spec.rb41
3 files changed, 68 insertions, 35 deletions
diff --git a/spec/mailers/emails/pipelines_spec.rb b/spec/mailers/emails/pipelines_spec.rb
index a29835f3439..b9bc53625ac 100644
--- a/spec/mailers/emails/pipelines_spec.rb
+++ b/spec/mailers/emails/pipelines_spec.rb
@@ -9,12 +9,14 @@ RSpec.describe Emails::Pipelines do
let_it_be(:project) { create(:project, :repository) }
shared_examples_for 'correct pipeline information' do
- it 'has a correct information' do
- expect(subject)
- .to have_subject "#{status} pipeline for #{pipeline.source_ref} | " \
- "#{project.name} | " \
- "#{pipeline.short_sha}".to_s
+ let(:expected_email_subject) do
+ "#{project.name} | " \
+ "#{status} pipeline for #{pipeline.source_ref} | " \
+ "#{pipeline.short_sha}"
+ end
+ it 'has a correct information' do
+ expect(subject).to have_subject expected_email_subject
expect(subject).to have_body_text pipeline.source_ref
expect(subject).to have_body_text status_text
end
@@ -28,11 +30,7 @@ RSpec.describe Emails::Pipelines do
end
it 'has correct information that there is no merge request link' do
- expect(subject)
- .to have_subject "#{status} pipeline for #{pipeline.source_ref} | " \
- "#{project.name} | " \
- "#{pipeline.short_sha}".to_s
-
+ expect(subject).to have_subject expected_email_subject
expect(subject).to have_body_text pipeline.source_ref
expect(subject).to have_body_text status_text
end
@@ -48,11 +46,7 @@ RSpec.describe Emails::Pipelines do
end
it 'has correct information that there is a merge request link' do
- expect(subject)
- .to have_subject "#{status} pipeline for #{pipeline.source_ref} | " \
- "#{project.name} | " \
- "#{pipeline.short_sha}".to_s
-
+ expect(subject).to have_subject expected_email_subject
expect(subject).to have_body_text merge_request.to_reference
expect(subject).to have_body_text pipeline.source_ref
expect(subject).not_to have_body_text pipeline.ref
@@ -70,11 +64,7 @@ RSpec.describe Emails::Pipelines do
end
it 'has correct information that there is a merge request link' do
- expect(subject)
- .to have_subject "#{status} pipeline for #{pipeline.source_ref} | " \
- "#{project.name} | " \
- "#{pipeline.short_sha}".to_s
-
+ expect(subject).to have_subject expected_email_subject
expect(subject).to have_body_text merge_request.to_reference
expect(subject).to have_body_text pipeline.source_ref
end
@@ -91,6 +81,17 @@ RSpec.describe Emails::Pipelines do
it_behaves_like 'correct pipeline information' do
let(:status) { 'Successful' }
let(:status_text) { "Pipeline ##{pipeline.id} has passed!" }
+ let(:email_subject_suffix) { 'A Nice Suffix' }
+ let(:expected_email_subject) do
+ "#{project.name} | " \
+ "#{status} pipeline for #{pipeline.source_ref} | " \
+ "#{pipeline.short_sha} | " \
+ "#{email_subject_suffix}"
+ end
+
+ before do
+ stub_config_setting(email_subject_suffix: email_subject_suffix)
+ end
end
end
diff --git a/spec/mailers/emails/projects_spec.rb b/spec/mailers/emails/projects_spec.rb
index a5b89d16bc2..b9c71e35bc6 100644
--- a/spec/mailers/emails/projects_spec.rb
+++ b/spec/mailers/emails/projects_spec.rb
@@ -36,6 +36,27 @@ RSpec.describe Emails::Projects do
Notify.prometheus_alert_fired_email(project, user, alert)
end
+ it_behaves_like 'an email with X-GitLab headers containing project details'
+
+ it 'has expected X-GitLab alert headers', :aggregate_failures do
+ is_expected.to have_header('X-GitLab-Alert-ID', /#{alert.id}/)
+ is_expected.to have_header('X-GitLab-Alert-IID', /#{alert.iid}/)
+ is_expected.to have_header('X-GitLab-NotificationReason', "alert_#{alert.state}")
+
+ is_expected.not_to have_header('X-GitLab-Incident-ID', /.+/)
+ is_expected.not_to have_header('X-GitLab-Incident-IID', /.+/)
+ end
+
+ context 'with incident' do
+ let(:alert) { create(:alert_management_alert, :with_incident, :from_payload, payload: payload, project: project) }
+ let(:incident) { alert.issue }
+
+ it 'has expected X-GitLab incident headers', :aggregate_failures do
+ is_expected.to have_header('X-GitLab-Incident-ID', /#{incident.id}/)
+ is_expected.to have_header('X-GitLab-Incident-IID', /#{incident.iid}/)
+ end
+ end
+
context 'with empty payload' do
let(:payload) { {} }
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index ae956adf563..8272b5d64c1 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -781,7 +781,9 @@ RSpec.describe Notify do
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) }
+ subject(:invite_email) do
+ described_class.member_invited_email('project', project_member.id, project_member.invite_token)
+ end
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
@@ -796,23 +798,13 @@ RSpec.describe Notify do
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
- is_expected.to have_link('Join now', href: invite_url(project_member.invite_token, invite_type: Members::InviteEmailExperiment::INVITE_TYPE))
- end
-
- it 'contains invite link for the group activity' do
- stub_experiments('members/invite_email': :activity)
-
+ is_expected.to have_link('Join now',
+ href: invite_url(project_member.invite_token,
+ invite_type: Emails::Members::INITIAL_INVITE,
+ experiment_name: 'invite_email_preview_text'))
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_content('You are invited!')
- is_expected.not_to have_body_text 'What is a GitLab'
- end
-
- it 'has invite link for the control group' do
- stub_experiments('members/invite_email': :control)
-
- is_expected.to have_content('You are invited!')
end
end
@@ -824,6 +816,25 @@ RSpec.describe Notify do
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
+ is_expected.to have_link('Join now',
+ href: invite_url(project_member.invite_token,
+ invite_type: Emails::Members::INITIAL_INVITE,
+ experiment_name: 'invite_email_preview_text'))
+ is_expected.to have_content('Project details')
+ is_expected.to have_content("What's it about?")
+ end
+ end
+
+ context 'when invite email sent is tracked', :snowplow do
+ it 'tracks the sent invite' do
+ invite_email.deliver_now
+
+ expect_snowplow_event(
+ category: 'Notify',
+ action: 'invite_email_sent',
+ label: 'invite_email',
+ property: project_member.id.to_s
+ )
end
end