Commit bc54c517 authored by Axel García's avatar Axel García

Fix false positive on OneTrust helper specs

It also moves the logic from the AuthHelper to
its own helper.
parent 2075d6fe
......@@ -169,13 +169,6 @@ module AuthHelper
!current_user
end
def one_trust_enabled?
Feature.enabled?(:ecomm_instrumentation, nil, type: :ops) &&
extra_config.has_key?('one_trust_id') &&
extra_config.one_trust_id.present? &&
!current_user
end
def auth_app_owner_text(owner)
return unless owner
......
# frozen_string_literal: true
module OneTrustHelper
def one_trust_enabled?
Feature.enabled?(:ecomm_instrumentation, type: :ops) &&
Gitlab.config.extra.has_key?('one_trust_id') &&
Gitlab.config.extra.one_trust_id.present? &&
!current_user
end
end
......@@ -314,45 +314,6 @@ RSpec.describe AuthHelper do
end
end
describe '#one_trust_enabled?' do
let(:user) { nil }
before do
stub_config(extra: { one_trust_id: 'key' })
allow(helper).to receive(:current_user).and_return(user)
end
subject(:one_trust_enabled?) { helper.one_trust_enabled? }
context 'with ecomm_instrumentation feature flag enabled' do
before do
stub_feature_flags(ecomm_instrumentation: true)
end
context 'when current user is set' do
let(:user) { instance_double('User') }
it { is_expected.to be_falsey }
end
context 'when no id is set' do
before do
stub_config(extra: {})
end
it { is_expected.to be_falsey }
end
context 'when id is set and no user is set' do
before do
stub_config(extra: { one_trust_id: 'key' })
end
it { is_expected.to be_truthy }
end
end
end
describe '#auth_app_owner_text' do
shared_examples 'generates text with the correct info' do
it 'includes the name of the application owner' do
......
# frozen_string_literal: true
require "spec_helper"
RSpec.describe OneTrustHelper do
describe '#one_trust_enabled?' do
let(:user) { nil }
before do
stub_config(extra: { one_trust_id: 'id' })
allow(helper).to receive(:current_user).and_return(user)
end
subject(:one_trust_enabled?) { helper.one_trust_enabled? }
context 'with ecomm_instrumentation feature flag disabled' do
before do
stub_feature_flags(ecomm_instrumentation: false)
end
context 'when id is set and no user is set' do
let(:user) { instance_double('User') }
it { is_expected.to be_falsey }
end
end
context 'with ecomm_instrumentation feature flag enabled' do
context 'when current user is set' do
let(:user) { instance_double('User') }
it { is_expected.to be_falsey }
end
context 'when no id is set' do
before do
stub_config(extra: {})
end
it { is_expected.to be_falsey }
end
context 'when id is set and no user is set' do
it { is_expected.to be_truthy }
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment