diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/lib/gitlab/email | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/lib/gitlab/email')
7 files changed, 267 insertions, 0 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 e76a5d3fe32..c0ac40e3249 100644 --- a/spec/lib/gitlab/email/handler/create_note_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb @@ -110,6 +110,60 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do end end + context 'when email contains reply' do + shared_examples 'no content message' do + context 'when email contains quoted text only' do + let(:email_raw) { fixture_file('emails/no_content_with_quote.eml') } + + it 'raises an EmptyEmailError' do + expect { receiver.execute }.to raise_error(Gitlab::Email::EmptyEmailError) + end + end + + context 'when email contains quoted text and quick commands only' do + let(:email_raw) { fixture_file('emails/commands_only_reply.eml') } + + it 'does not create a discussion' do + expect { receiver.execute }.not_to change { noteable.notes.count } + end + end + end + + context 'when noteable is not an issue' do + let_it_be(:note) { create(:note_on_merge_request, project: project) } + + it_behaves_like 'no content message' + + context 'when email contains text, quoted text and quick commands' do + let(:email_raw) { fixture_file('emails/commands_in_reply.eml') } + + it 'creates a discussion without appended reply' do + expect { receiver.execute }.to change { noteable.notes.count }.by(1) + new_note = noteable.notes.last + + expect(new_note.note).not_to include('<details><summary>...</summary>') + end + end + end + + context 'when noteable is an issue' do + let_it_be(:note) { create(:note_on_issue, project: project) } + + it_behaves_like 'no content message' + + context 'when email contains text, quoted text and quick commands' do + let(:email_raw) { fixture_file('emails/commands_in_reply.eml') } + + it 'creates a discussion with appended reply' do + expect { receiver.execute }.to change { noteable.notes.count }.by(1) + new_note = noteable.notes.last + + expect(new_note.note).to include('<details><summary>...</summary>') + end + end + end + end + context 'when note is not a discussion' do let(:note) { create(:note_on_merge_request, project: project) } 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 new file mode 100644 index 00000000000..b5c3415fe12 --- /dev/null +++ b/spec/lib/gitlab/email/message/in_product_marketing/admin_verify_spec.rb @@ -0,0 +1,45 @@ +# 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/team_short_spec.rb b/spec/lib/gitlab/email/message/in_product_marketing/team_short_spec.rb new file mode 100644 index 00000000000..daeacef53f6 --- /dev/null +++ b/spec/lib/gitlab/email/message/in_product_marketing/team_short_spec.rb @@ -0,0 +1,47 @@ +# 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 index f72994fcce1..eca8ba1df00 100644 --- a/spec/lib/gitlab/email/message/in_product_marketing/team_spec.rb +++ b/spec/lib/gitlab/email/message/in_product_marketing/team_spec.rb @@ -23,6 +23,26 @@ RSpec.describe Gitlab::Email::Message::InProductMarketing::Team do 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 @@ -37,6 +57,26 @@ RSpec.describe Gitlab::Email::Message::InProductMarketing::Team do 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 new file mode 100644 index 00000000000..ebad4672eb3 --- /dev/null +++ b/spec/lib/gitlab/email/message/in_product_marketing/trial_short_spec.rb @@ -0,0 +1,45 @@ +# 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 index 5f7639a9ed6..3e18b8e35b6 100644 --- a/spec/lib/gitlab/email/message/in_product_marketing/trial_spec.rb +++ b/spec/lib/gitlab/email/message/in_product_marketing/trial_spec.rb @@ -23,6 +23,26 @@ RSpec.describe Gitlab::Email::Message::InProductMarketing::Trial do 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/reply_parser_spec.rb b/spec/lib/gitlab/email/reply_parser_spec.rb index bc4c6cf007d..3b01b568fb4 100644 --- a/spec/lib/gitlab/email/reply_parser_spec.rb +++ b/spec/lib/gitlab/email/reply_parser_spec.rb @@ -228,5 +228,21 @@ RSpec.describe Gitlab::Email::ReplyParser do BODY ) end + + it "appends trimmed reply when when append_reply option is true" do + body = <<-BODY.strip_heredoc.chomp + The reply by email functionality should be extended to allow creating a new issue by email. + even when the email is forwarded to the project which may include lines that begin with ">" + + there should be a quote below this line: + BODY + + reply = <<-BODY.strip_heredoc.chomp + > this is a quote + BODY + + expect(test_parse_body(fixture_file("emails/valid_new_issue_with_quote.eml"), { append_reply: true })) + .to contain_exactly(body, reply) + end end end |