diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/initializers/microsoft_graph_mailer_spec.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/initializers/microsoft_graph_mailer_spec.rb')
-rw-r--r-- | spec/initializers/microsoft_graph_mailer_spec.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/initializers/microsoft_graph_mailer_spec.rb b/spec/initializers/microsoft_graph_mailer_spec.rb new file mode 100644 index 00000000000..fbe667e34fe --- /dev/null +++ b/spec/initializers/microsoft_graph_mailer_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'microsoft_graph_mailer initializer for GitLab' do + let(:microsoft_graph_setting) do + { + user_id: SecureRandom.hex, + tenant: SecureRandom.hex, + client_id: SecureRandom.hex, + client_secret: SecureRandom.hex, + azure_ad_endpoint: 'https://test-azure_ad_endpoint', + graph_endpoint: 'https://test-graph_endpoint' + } + end + + def load_microsoft_graph_mailer_initializer + load Rails.root.join('config/initializers/microsoft_graph_mailer.rb') + end + + context 'when microsoft_graph_mailer is enabled' do + before do + stub_microsoft_graph_mailer_setting(microsoft_graph_setting.merge(enabled: true)) + end + + it 'configures ActionMailer' do + previous_delivery_method = ActionMailer::Base.delivery_method + previous_microsoft_graph_settings = ActionMailer::Base.microsoft_graph_settings + + load_microsoft_graph_mailer_initializer + + expect(ActionMailer::Base.delivery_method).to eq(:microsoft_graph) + expect(ActionMailer::Base.microsoft_graph_settings).to eq(microsoft_graph_setting) + ensure + ActionMailer::Base.delivery_method = previous_delivery_method + ActionMailer::Base.microsoft_graph_settings = previous_microsoft_graph_settings + end + end + + context 'when microsoft_graph_mailer is disabled' do + before do + stub_microsoft_graph_mailer_setting(microsoft_graph_setting.merge(enabled: false)) + end + + it 'does not configure ActionMailer' do + previous_delivery_method = ActionMailer::Base.delivery_method + previous_microsoft_graph_settings = ActionMailer::Base.microsoft_graph_settings + + load_microsoft_graph_mailer_initializer + + expect(previous_microsoft_graph_settings).not_to eq(:microsoft_graph) + expect(ActionMailer::Base.delivery_method).to eq(previous_delivery_method) + expect(ActionMailer::Base.microsoft_graph_settings).to eq(previous_microsoft_graph_settings) + end + end +end |