diff options
Diffstat (limited to 'spec/lib/gitlab/email')
5 files changed, 54 insertions, 107 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 6941ebd2e11..e6fff939632 100644 --- a/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb @@ -321,7 +321,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler, feature_category: :se end end - context 'when using custom service desk address' do + context 'when using additional service desk alias address' do let(:receiver) { Gitlab::Email::ServiceDeskReceiver.new(email_raw) } before do @@ -587,6 +587,16 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler, feature_category: :se end end + context 'when there is no to address' do + before do + allow_next_instance_of(described_class) do |instance| + allow(instance).to receive(:to_address).and_return(nil) + end + end + + it_behaves_like 'a new issue request' + end + context 'when there is no from address' do before do allow_next_instance_of(described_class) do |instance| diff --git a/spec/lib/gitlab/email/message/build_ios_app_guide_spec.rb b/spec/lib/gitlab/email/message/build_ios_app_guide_spec.rb deleted file mode 100644 index 4b77b2f7192..00000000000 --- a/spec/lib/gitlab/email/message/build_ios_app_guide_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Email::Message::BuildIosAppGuide, :saas do - subject(:message) { described_class.new } - - it 'contains the correct message', :aggregate_failures do - expect(message.subject_line).to eq 'Get set up to build for iOS' - expect(message.title).to eq "Building for iOS? We've got you covered." - expect(message.body_line1).to eq "Want to get your iOS app up and running, including " \ - "publishing all the way to TestFlight? Follow our guide to set up GitLab and fastlane to publish iOS apps to " \ - "the App Store." - expect(message.cta_text).to eq 'Learn how to build for iOS' - expect(message.cta2_text).to eq 'Watch iOS building in action.' - expect(message.logo_path).to eq 'mailers/in_product_marketing/create-0.png' - expect(message.unsubscribe).to include('%tag_unsubscribe_url%') - end -end diff --git a/spec/lib/gitlab/email/message/in_product_marketing/helper_spec.rb b/spec/lib/gitlab/email/message/in_product_marketing/helper_spec.rb deleted file mode 100644 index a3c2d1b428e..00000000000 --- a/spec/lib/gitlab/email/message/in_product_marketing/helper_spec.rb +++ /dev/null @@ -1,75 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Email::Message::InProductMarketing::Helper do - describe 'unsubscribe_message' do - include Gitlab::Routing - - let(:dummy_class_with_helper) do - Class.new do - include Gitlab::Email::Message::InProductMarketing::Helper - include Gitlab::Routing - - def initialize(format = :html) - @format = format - end - - def default_url_options - {} - end - - attr_accessor :format - end - end - - let(:format) { :html } - - subject(:class_with_helper) { dummy_class_with_helper.new(format) } - - context 'for SaaS', :saas do - context 'format is HTML' do - it 'returns the correct HTML' do - message = "If you no longer wish to receive marketing emails from us, " \ - "you may <a href=\"%tag_unsubscribe_url%\">unsubscribe</a> at any time." - expect(class_with_helper.unsubscribe_message).to match message - end - end - - context 'format is text' do - let(:format) { :text } - - it 'returns the correct string' do - message = "If you no longer wish to receive marketing emails from us, " \ - "you may unsubscribe (%tag_unsubscribe_url%) at any time." - expect(class_with_helper.unsubscribe_message.squish).to match message - end - end - end - - context 'self-managed' do - context 'format is HTML' do - it 'returns the correct HTML' do - preferences_link = "http://example.com/preferences" - message = "To opt out of these onboarding emails, " \ - "<a href=\"#{profile_notifications_url}\">unsubscribe</a>. " \ - "If you don't want to receive marketing emails directly from GitLab, #{preferences_link}." - expect(class_with_helper.unsubscribe_message(preferences_link)) - .to match message - end - end - - context 'format is text' do - let(:format) { :text } - - it 'returns the correct string' do - preferences_link = "http://example.com/preferences" - message = "To opt out of these onboarding emails, " \ - "unsubscribe (#{profile_notifications_url}). " \ - "If you don't want to receive marketing emails directly from GitLab, #{preferences_link}." - expect(class_with_helper.unsubscribe_message(preferences_link).squish).to match message - end - end - end - end -end diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index ee836fc2129..f8084d24850 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -33,7 +33,7 @@ RSpec.describe Gitlab::Email::Receiver do metadata = receiver.mail_metadata - expect(metadata.keys).to match_array(%i(mail_uid from_address to_address mail_key references delivered_to envelope_to x_envelope_to meta received_recipients)) + expect(metadata.keys).to match_array(%i(mail_uid from_address to_address mail_key references delivered_to envelope_to x_envelope_to meta received_recipients cc_address)) expect(metadata[:meta]).to include(client_id: client_id, project: project.full_path) expect(metadata[meta_key]).to eq(meta_value) end @@ -112,6 +112,24 @@ RSpec.describe Gitlab::Email::Receiver do it_behaves_like 'successful receive' end end + + context 'when in a Cc header' do + let(:email_raw) do + <<~EMAIL + From: jake@example.com + To: to@example.com + Cc: incoming+gitlabhq/gitlabhq+auth_token@appmail.example.com + Subject: Issue titile + + Issue description + EMAIL + end + + let(:meta_key) { :cc_address } + let(:meta_value) { ["incoming+gitlabhq/gitlabhq+auth_token@appmail.example.com"] } + + it_behaves_like 'successful receive' + end end context 'when we cannot find a capable handler' do diff --git a/spec/lib/gitlab/email/service_desk_receiver_spec.rb b/spec/lib/gitlab/email/service_desk_receiver_spec.rb index c249a5422ff..4b67020471a 100644 --- a/spec/lib/gitlab/email/service_desk_receiver_spec.rb +++ b/spec/lib/gitlab/email/service_desk_receiver_spec.rb @@ -7,6 +7,12 @@ RSpec.describe Gitlab::Email::ServiceDeskReceiver do let(:receiver) { described_class.new(email) } context 'when the email contains a valid email address' do + shared_examples 'received successfully' do + it 'finds the service desk key' do + expect { receiver.execute }.not_to raise_error + end + end + before do stub_service_desk_email_setting(enabled: true, address: 'support+%{key}@example.com') @@ -21,34 +27,41 @@ RSpec.describe Gitlab::Email::ServiceDeskReceiver do end context 'when in a To header' do - it 'finds the service desk key' do - receiver.execute - end + it_behaves_like 'received successfully' end context 'when the email contains a valid email address in a header' do context 'when in a Delivered-To header' do let(:email) { fixture_file('emails/service_desk_custom_address_reply.eml') } - it 'finds the service desk key' do - receiver.execute - end + it_behaves_like 'received successfully' end context 'when in a Envelope-To header' do let(:email) { fixture_file('emails/service_desk_custom_address_envelope_to.eml') } - it 'finds the service desk key' do - receiver.execute - end + it_behaves_like 'received successfully' end context 'when in a X-Envelope-To header' do let(:email) { fixture_file('emails/service_desk_custom_address_x_envelope_to.eml') } - it 'finds the service desk key' do - receiver.execute + it_behaves_like 'received successfully' + end + + context 'when in a Cc header' do + let(:email) do + <<~EMAIL + From: from@example.com + To: to@example.com + Cc: support+project_slug-project_key@example.com + Subject: Issue titile + + Issue description + EMAIL end + + it_behaves_like 'received successfully' end end end |