diff options
Diffstat (limited to 'spec/lib/gitlab/email')
12 files changed, 43 insertions, 498 deletions
diff --git a/spec/lib/gitlab/email/handler/create_note_handler_spec.rb b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb index e3b0e90bff9..c7b69f39951 100644 --- a/spec/lib/gitlab/email/handler/create_note_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb @@ -68,7 +68,7 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do end context 'when the issue is a Service Desk issue' do - let(:original_recipient) { User.support_bot } + let(:original_recipient) { Users::Internal.support_bot } it 'does not raise a UserNotFoundError' do expect { receiver.execute }.not_to raise_error @@ -209,7 +209,7 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do context 'when note is authored from external author for service desk' do before do - SentNotification.find_by(reply_key: mail_key).update!(recipient: User.support_bot) + SentNotification.find_by(reply_key: mail_key).update!(recipient: Users::Internal.support_bot) end context 'when email contains text, quoted text and quick commands' do 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 98522c53a47..6941ebd2e11 100644 --- a/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb @@ -38,7 +38,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler, feature_category: :se new_issue = Issue.last - expect(new_issue.author).to eql(User.support_bot) + expect(new_issue.author).to eql(Users::Internal.support_bot) expect(new_issue.confidential?).to be true expect(new_issue.all_references.all).to be_empty expect(new_issue.title).to eq("The message subject! @all") @@ -131,7 +131,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler, feature_category: :se expect(notes.count).to eq(1) expect(new_note.note).to eq("Service desk reply!\n\n`/label ~label2`") - expect(new_note.author).to eql(User.support_bot) + expect(new_note.author).to eql(Users::Internal.support_bot) end it 'does not send thank you email' do @@ -267,7 +267,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler, feature_category: :se issue = Issue.last expect(issue.description).to include('Text from service_desk2 template') expect(issue.label_ids).to include(label.id) - expect(issue.author_id).to eq(User.support_bot.id) + expect(issue.author_id).to eq(Users::Internal.support_bot.id) expect(issue.milestone).to eq(milestone) end end @@ -294,7 +294,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler, feature_category: :se note = Note.last expect(note.note).to include("WARNING: The template file unknown.md used for service desk issues is empty or could not be found.") - expect(note.author).to eq(User.support_bot) + expect(note.author).to eq(Users::Internal.support_bot) end it 'does not send warning note email' do diff --git a/spec/lib/gitlab/email/message/in_product_marketing/admin_verify_spec.rb b/spec/lib/gitlab/email/message/in_product_marketing/admin_verify_spec.rb deleted file mode 100644 index 7a09feb5b64..00000000000 --- a/spec/lib/gitlab/email/message/in_product_marketing/admin_verify_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Email::Message::InProductMarketing::AdminVerify do - let_it_be(:group) { build(:group) } - let_it_be(:user) { build(:user) } - - let(:series) { 0 } - - subject(:message) { described_class.new(group: group, user: user, series: series) } - - describe 'public methods' do - it 'returns value for series', :aggregate_failures do - expect(message.subject_line).to eq 'Create a custom CI runner with just a few clicks' - expect(message.tagline).to be_nil - expect(message.title).to eq 'Spin up an autoscaling runner in GitLab' - expect(message.subtitle).to eq 'Use our AWS cloudformation template to spin up your runners in just a few clicks!' - expect(message.body_line1).to be_empty - expect(message.body_line2).to be_empty - expect(message.cta_text).to eq 'Create a custom runner' - expect(message.logo_path).to eq 'mailers/in_product_marketing/admin_verify-0.png' - end - - describe '#progress' do - subject { message.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 eq('This is email 1 of 1 in the Admin series.') } - end - - context 'not on gitlab.com' do - let(:is_gitlab_com) { false } - - it { is_expected.to include('This is email 1 of 1 in the Admin series', Gitlab::Routing.url_helpers.profile_notifications_url) } - end - end - end -end 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 deleted file mode 100644 index ab6b1cd6171..00000000000 --- a/spec/lib/gitlab/email/message/in_product_marketing/base_spec.rb +++ /dev/null @@ -1,108 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Email::Message::InProductMarketing::Base do - let_it_be(:group) { build(:group) } - let_it_be(:user) { build(:user) } - - let(:series) { 0 } - let(:test_class) { Gitlab::Email::Message::InProductMarketing::Create } - - describe 'initialize' do - subject { test_class.new(group: group, user: user, 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 - end - end - end - - describe '#logo_path' do - subject { test_class.new(group: group, user: user, 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, user: user, 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, user: user, 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, user: user, 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 - - describe '#series?' do - using RSpec::Parameterized::TableSyntax - - subject do - test_class = "Gitlab::Email::Message::InProductMarketing::#{track.to_s.classify}".constantize - test_class.new(group: group, user: user, series: series).series? - end - - where(:track, :result) do - :create | true - :team_short | true - :trial_short | true - :admin_verify | true - :verify | true - :trial | true - :team | true - end - - with_them do - it { is_expected.to eq result } - 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 deleted file mode 100644 index d5aec280ea6..00000000000 --- a/spec/lib/gitlab/email/message/in_product_marketing/create_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -# 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) } - let_it_be(:user) { build(:user) } - - subject(:message) { described_class.new(group: group, user: user, 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_short_spec.rb b/spec/lib/gitlab/email/message/in_product_marketing/team_short_spec.rb deleted file mode 100644 index 3ac2076bf35..00000000000 --- a/spec/lib/gitlab/email/message/in_product_marketing/team_short_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Email::Message::InProductMarketing::TeamShort do - using RSpec::Parameterized::TableSyntax - - let_it_be(:group) { build(:group) } - let_it_be(:user) { build(:user) } - - let(:series) { 0 } - - subject(:message) { described_class.new(group: group, user: user, series: series) } - - describe 'public methods' do - it 'returns value for series', :aggregate_failures do - expect(message.subject_line).to eq 'Team up in GitLab for greater efficiency' - expect(message.tagline).to be_nil - expect(message.title).to eq 'Turn coworkers into collaborators' - expect(message.subtitle).to eq 'Invite your team today to build better code (and processes) together' - expect(message.body_line1).to be_empty - expect(message.body_line2).to be_empty - expect(message.cta_text).to eq 'Invite your colleagues today' - expect(message.logo_path).to eq 'mailers/in_product_marketing/team-0.png' - end - - describe '#progress' do - subject { message.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 4 in the Team series') } - end - - context 'not on gitlab.com' do - let(:is_gitlab_com) { false } - - it { is_expected.to include('This is email 1 of 4 in the Team series', Gitlab::Routing.url_helpers.profile_notifications_url) } - 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 deleted file mode 100644 index 3354b2ed5cf..00000000000 --- a/spec/lib/gitlab/email/message/in_product_marketing/team_spec.rb +++ /dev/null @@ -1,82 +0,0 @@ -# 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) } - let_it_be(:user) { build(:user) } - - subject(:message) { described_class.new(group: group, user: user, 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 - - describe '#progress' do - subject { message.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 #{series + 2} of 4 in the Team series") } - end - - context 'not on gitlab.com' do - let(:is_gitlab_com) { false } - - it { is_expected.to include("This is email #{series + 2} of 4 in the Team series", Gitlab::Routing.url_helpers.profile_notifications_url) } - end - 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 - - describe '#progress' do - subject { message.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 4 of 4 in the Team series') } - end - - context 'not on gitlab.com' do - let(:is_gitlab_com) { false } - - it { is_expected.to include('This is email 4 of 4 in the Team series', Gitlab::Routing.url_helpers.profile_notifications_url) } - end - end - end - end -end diff --git a/spec/lib/gitlab/email/message/in_product_marketing/trial_short_spec.rb b/spec/lib/gitlab/email/message/in_product_marketing/trial_short_spec.rb deleted file mode 100644 index cf0a119ea80..00000000000 --- a/spec/lib/gitlab/email/message/in_product_marketing/trial_short_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Email::Message::InProductMarketing::TrialShort do - let_it_be(:group) { build(:group) } - let_it_be(:user) { build(:user) } - - let(:series) { 0 } - - subject(:message) { described_class.new(group: group, user: user, series: series) } - - describe 'public methods' do - it 'returns value for series', :aggregate_failures do - expect(message.subject_line).to eq 'Be a DevOps hero' - expect(message.tagline).to be_nil - expect(message.title).to eq 'Expand your DevOps journey with a free GitLab trial' - expect(message.subtitle).to eq 'Start your trial today to experience single application success and discover all the features of GitLab Ultimate for free!' - expect(message.body_line1).to be_empty - expect(message.body_line2).to be_empty - expect(message.cta_text).to eq 'Start a trial' - expect(message.logo_path).to eq 'mailers/in_product_marketing/trial-0.png' - end - - describe '#progress' do - subject { message.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 eq('This is email 1 of 4 in the Trial series.') } - end - - context 'not on gitlab.com' do - let(:is_gitlab_com) { false } - - it { is_expected.to include('This is email 1 of 4 in the Trial series', Gitlab::Routing.url_helpers.profile_notifications_url) } - 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 deleted file mode 100644 index 7f86c9a6c6f..00000000000 --- a/spec/lib/gitlab/email/message/in_product_marketing/trial_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -# 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) } - let_it_be(:user) { build(:user) } - - subject(:message) { described_class.new(group: group, user: user, 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 - - describe '#progress' do - subject { message.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 eq("This is email #{series + 2} of 4 in the Trial series.") } - end - - context 'not on gitlab.com' do - let(:is_gitlab_com) { false } - - it { is_expected.to include("This is email #{series + 2} of 4 in the Trial series", Gitlab::Routing.url_helpers.profile_notifications_url) } - end - 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 deleted file mode 100644 index 7e6f62289d2..00000000000 --- a/spec/lib/gitlab/email/message/in_product_marketing/verify_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Email::Message::InProductMarketing::Verify do - let_it_be(:group) { build(:group) } - let_it_be(:user) { build(:user) } - - subject(:message) { described_class.new(group: group, user: user, 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 deleted file mode 100644 index 1c59d9c8208..00000000000 --- a/spec/lib/gitlab/email/message/in_product_marketing_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -# 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 - :team_short | described_class::TeamShort - :trial_short | described_class::TrialShort - :admin_verify | described_class::AdminVerify - :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/service_desk/custom_email_spec.rb b/spec/lib/gitlab/email/service_desk/custom_email_spec.rb new file mode 100644 index 00000000000..bba1ca1c8be --- /dev/null +++ b/spec/lib/gitlab/email/service_desk/custom_email_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Email::ServiceDesk::CustomEmail, feature_category: :service_desk do + let(:reply_key) { 'b7721fc7e8419911a8bea145236a0519' } + let(:custom_email) { 'support@example.com' } + let(:email_with_reply_key) { 'support+b7721fc7e8419911a8bea145236a0519@example.com' } + + describe '.reply_address' do + let_it_be(:project) { create(:project) } + + subject(:reply_address) { described_class.reply_address(nil, nil) } + + it { is_expected.to be nil } + + context 'with reply key' do + subject(:reply_address) { described_class.reply_address(nil, reply_key) } + + it { is_expected.to be nil } + + context 'with issue' do + let_it_be(:issue) { create(:issue, project: project) } + + subject(:reply_address) { described_class.reply_address(issue, reply_key) } + + it { is_expected.to be nil } + + context 'with service_desk_setting and custom email' do + let!(:service_desk_setting) { create(:service_desk_setting, custom_email: custom_email, project: project) } + + it { is_expected.to eq(email_with_reply_key) } + end + end + end + end +end |