diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /spec/lib/gitlab/email | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/lib/gitlab/email')
8 files changed, 279 insertions, 5 deletions
diff --git a/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb b/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb index 7436765e8ee..6d26b3e1064 100644 --- a/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb @@ -90,11 +90,6 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do context 'when quick actions are present' do let(:label) { create(:label, project: project, title: 'label1') } let(:milestone) { create(:milestone, project: project) } - let!(:user) { create(:user, username: 'user1') } - - before do - project.add_developer(user) - end it 'applies quick action commands present on templates' do file_content = %(Text from template \n/label ~#{label.title} \n/milestone %"#{milestone.name}"") diff --git a/spec/lib/gitlab/email/message/in_product_marketing/base_spec.rb b/spec/lib/gitlab/email/message/in_product_marketing/base_spec.rb new file mode 100644 index 00000000000..42d84b3e4de --- /dev/null +++ b/spec/lib/gitlab/email/message/in_product_marketing/base_spec.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Email::Message::InProductMarketing::Base do + let_it_be(:group) { build(:group) } + + let(:series) { 0 } + let(:test_class) { Gitlab::Email::Message::InProductMarketing::Create } + + describe 'initialize' do + subject { test_class.new(group: group, series: series) } + + context 'when series does not exist' do + let(:series) { 3 } + + it 'raises error' do + expect { subject }.to raise_error(ArgumentError) + end + end + + context 'when series exists' do + let(:series) { 0 } + + it 'does not raise error' do + expect { subject }.not_to raise_error(ArgumentError) + end + end + end + + describe '#logo_path' do + subject { test_class.new(group: group, series: series).logo_path } + + it { is_expected.to eq('mailers/in_product_marketing/create-0.png') } + end + + describe '#unsubscribe' do + subject { test_class.new(group: group, series: series).unsubscribe } + + before do + allow(Gitlab).to receive(:com?).and_return(is_gitlab_com) + end + + context 'on gitlab.com' do + let(:is_gitlab_com) { true } + + it { is_expected.to include('%tag_unsubscribe_url%') } + end + + context 'not on gitlab.com' do + let(:is_gitlab_com) { false } + + it { is_expected.to include(Gitlab::Routing.url_helpers.profile_notifications_url) } + end + end + + describe '#cta_link' do + subject(:cta_link) { test_class.new(group: group, series: series).cta_link } + + it 'renders link' do + expect(CGI.unescapeHTML(cta_link)).to include(Gitlab::Routing.url_helpers.group_email_campaigns_url(group, track: :create, series: series)) + end + end + + describe '#progress' do + subject { test_class.new(group: group, series: series).progress } + + before do + allow(Gitlab).to receive(:com?).and_return(is_gitlab_com) + end + + context 'on gitlab.com' do + let(:is_gitlab_com) { true } + + it { is_expected.to include('This is email 1 of 3 in the Create series') } + end + + context 'not on gitlab.com' do + let(:is_gitlab_com) { false } + + it { is_expected.to include('This is email 1 of 3 in the Create series', Gitlab::Routing.url_helpers.profile_notifications_url) } + end + end +end diff --git a/spec/lib/gitlab/email/message/in_product_marketing/create_spec.rb b/spec/lib/gitlab/email/message/in_product_marketing/create_spec.rb new file mode 100644 index 00000000000..be8a33b18bd --- /dev/null +++ b/spec/lib/gitlab/email/message/in_product_marketing/create_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Email::Message::InProductMarketing::Create do + using RSpec::Parameterized::TableSyntax + + let_it_be(:group) { build(:group) } + + subject(:message) { described_class.new(group: group, series: series)} + + describe "public methods" do + where(series: [0, 1, 2]) + + with_them do + it 'returns value for series', :aggregate_failures do + expect(message.subject_line).to be_present + expect(message.tagline).to be_present + expect(message.title).to be_present + expect(message.subtitle).to be_present + expect(message.body_line1).to be_present + expect(message.body_line2).to be_present + expect(message.cta_text).to be_present + end + end + end +end diff --git a/spec/lib/gitlab/email/message/in_product_marketing/team_spec.rb b/spec/lib/gitlab/email/message/in_product_marketing/team_spec.rb new file mode 100644 index 00000000000..6251128f560 --- /dev/null +++ b/spec/lib/gitlab/email/message/in_product_marketing/team_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Email::Message::InProductMarketing::Team do + using RSpec::Parameterized::TableSyntax + + let_it_be(:group) { build(:group) } + + subject(:message) { described_class.new(group: group, series: series)} + + describe "public methods" do + where(series: [0, 1]) + + with_them do + it 'returns value for series', :aggregate_failures do + expect(message.subject_line).to be_present + expect(message.tagline).to be_present + expect(message.title).to be_present + expect(message.subtitle).to be_present + expect(message.body_line1).to be_present + expect(message.body_line2).to be_present + expect(message.cta_text).to be_present + end + end + + context 'with series 2' do + let(:series) { 2 } + + it 'returns value for series', :aggregate_failures do + expect(message.subject_line).to be_present + expect(message.tagline).to be_nil + expect(message.title).to be_present + expect(message.subtitle).to be_present + expect(message.body_line1).to be_present + expect(message.body_line2).to be_present + expect(message.cta_text).to be_present + end + end + end +end diff --git a/spec/lib/gitlab/email/message/in_product_marketing/trial_spec.rb b/spec/lib/gitlab/email/message/in_product_marketing/trial_spec.rb new file mode 100644 index 00000000000..2c435490765 --- /dev/null +++ b/spec/lib/gitlab/email/message/in_product_marketing/trial_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Email::Message::InProductMarketing::Trial do + using RSpec::Parameterized::TableSyntax + + let_it_be(:group) { build(:group) } + + subject(:message) { described_class.new(group: group, series: series)} + + describe "public methods" do + where(series: [0, 1, 2]) + + with_them do + it 'returns value for series', :aggregate_failures do + expect(message.subject_line).to be_present + expect(message.tagline).to be_present + expect(message.title).to be_present + expect(message.subtitle).to be_present + expect(message.body_line1).to be_present + expect(message.body_line2).to be_present + expect(message.cta_text).to be_present + end + end + end +end diff --git a/spec/lib/gitlab/email/message/in_product_marketing/verify_spec.rb b/spec/lib/gitlab/email/message/in_product_marketing/verify_spec.rb new file mode 100644 index 00000000000..73252c0dbdf --- /dev/null +++ b/spec/lib/gitlab/email/message/in_product_marketing/verify_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Email::Message::InProductMarketing::Verify do + let_it_be(:group) { build(:group) } + + subject(:message) { described_class.new(group: group, series: series)} + + describe "public methods" do + context 'with series 0' do + let(:series) { 0 } + + it 'returns value for series', :aggregate_failures do + expect(message.subject_line).to be_present + expect(message.tagline).to be_present + expect(message.title).to be_present + expect(message.subtitle).to be_present + expect(message.body_line1).to be_present + expect(message.body_line2).to be_nil + expect(message.cta_text).to be_present + end + end + + context 'with series 1' do + let(:series) { 1 } + + it 'returns value for series', :aggregate_failures do + expect(message.subject_line).to be_present + expect(message.tagline).to be_present + expect(message.title).to be_present + expect(message.subtitle).to be_present + expect(message.body_line1).to be_present + expect(message.body_line2).to be_present + expect(message.cta_text).to be_present + end + end + + context 'with series 2' do + let(:series) { 2 } + + it 'returns value for series', :aggregate_failures do + expect(message.subject_line).to be_present + expect(message.tagline).to be_present + expect(message.title).to be_present + expect(message.subtitle).to be_present + expect(message.body_line1).to be_present + expect(message.body_line2).to be_nil + expect(message.cta_text).to be_present + end + end + end +end diff --git a/spec/lib/gitlab/email/message/in_product_marketing_spec.rb b/spec/lib/gitlab/email/message/in_product_marketing_spec.rb new file mode 100644 index 00000000000..9ffc4a340a3 --- /dev/null +++ b/spec/lib/gitlab/email/message/in_product_marketing_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Email::Message::InProductMarketing do + describe '.for' do + using RSpec::Parameterized::TableSyntax + + subject { described_class.for(track) } + + context 'when track exists' do + where(:track, :expected_class) do + :create | described_class::Create + :verify | described_class::Verify + :trial | described_class::Trial + :team | described_class::Team + end + + with_them do + it { is_expected.to eq(expected_class) } + end + end + + context 'when track does not exist' do + let(:track) { :non_existent } + + it 'raises error' do + expect { subject }.to raise_error(described_class::UnknownTrackError) + end + end + end +end diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index ccff902d290..9b05c12ef57 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -15,6 +15,7 @@ RSpec.describe Gitlab::Email::Receiver do context 'when the email contains a valid email address in a header' do let(:handler) { double(:handler) } + let(:metadata) { receiver.mail_metadata } before do allow(handler).to receive(:execute) @@ -22,24 +23,38 @@ RSpec.describe Gitlab::Email::Receiver do allow(handler).to receive(:metrics_event) stub_incoming_email_setting(enabled: true, address: "incoming+%{key}@appmail.example.com") + + expect(receiver.mail_metadata.keys).to match_array(%i(mail_uid from_address to_address mail_key references delivered_to envelope_to x_envelope_to)) end context 'when in a Delivered-To header' do let(:email_raw) { fixture_file('emails/forwarded_new_issue.eml') } it_behaves_like 'correctly finds the mail key' + + it 'parses the metadata' do + expect(metadata[:delivered_to]). to eq(["incoming+gitlabhq/gitlabhq+auth_token@appmail.example.com", "support@example.com"]) + end end context 'when in an Envelope-To header' do let(:email_raw) { fixture_file('emails/envelope_to_header.eml') } it_behaves_like 'correctly finds the mail key' + + it 'parses the metadata' do + expect(metadata[:envelope_to]). to eq(["incoming+gitlabhq/gitlabhq+auth_token@appmail.example.com"]) + end end context 'when in an X-Envelope-To header' do let(:email_raw) { fixture_file('emails/x_envelope_to_header.eml') } it_behaves_like 'correctly finds the mail key' + + it 'parses the metadata' do + expect(metadata[:x_envelope_to]). to eq(["incoming+gitlabhq/gitlabhq+auth_token@appmail.example.com"]) + end end context 'when enclosed with angle brackets in an Envelope-To header' do |