Commit 3afd7062 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Methods can_{extend,reactivate}_trial? must rely on FF value

parent 555ab4f9
...@@ -303,10 +303,14 @@ module EE ...@@ -303,10 +303,14 @@ module EE
end end
def can_extend_trial? def can_extend_trial?
return false unless ::Feature.enabled?(:allow_extend_reactivate_trial, default_enabled: :yaml)
trial_active? && !trial_extended_or_reactivated? trial_active? && !trial_extended_or_reactivated?
end end
def can_reactivate_trial? def can_reactivate_trial?
return false unless ::Feature.enabled?(:allow_extend_reactivate_trial, default_enabled: :yaml)
!trial_active? && !never_had_trial? && !trial_extended_or_reactivated? && free_plan? !trial_active? && !never_had_trial? && !trial_extended_or_reactivated? && free_plan?
end end
......
...@@ -228,14 +228,32 @@ RSpec.describe EE::TrialHelper do ...@@ -228,14 +228,32 @@ RSpec.describe EE::TrialHelper do
end end
context 'when feature flag is disabled' do context 'when feature flag is disabled' do
before do
stub_feature_flags(allow_extend_reactivate_trial: false)
end
context 'when trial can be extended' do
before do
allow(namespace).to receive(:trial_active?).and_return(true)
allow(namespace).to receive(:trial_extended_or_reactivated?).and_return(false)
end
it { is_expected.to eq({ namespace_id: 1, plan_name: 'Ultimate', action: nil })} it { is_expected.to eq({ namespace_id: 1, plan_name: 'Ultimate', action: nil })}
end end
context 'when feature flag is enabled' do context 'when trial can be reactivated' do
before do before do
stub_feature_flags(allow_extend_reactivate_trial: true) allow(namespace).to receive(:trial_active?).and_return(false)
allow(namespace).to receive(:never_had_trial?).and_return(false)
allow(namespace).to receive(:trial_extended_or_reactivated?).and_return(false)
allow(namespace).to receive(:free_plan?).and_return(true)
end end
it { is_expected.to eq({ namespace_id: 1, plan_name: 'Ultimate', action: nil }) }
end
end
context 'when feature flag is enabled' do
context 'when trial can be extended' do context 'when trial can be extended' do
before do before do
allow(namespace).to receive(:can_extend_trial?).and_return(true) allow(namespace).to receive(:can_extend_trial?).and_return(true)
......
...@@ -1232,6 +1232,18 @@ RSpec.describe Namespace do ...@@ -1232,6 +1232,18 @@ RSpec.describe Namespace do
describe '#can_extend_trial?' do describe '#can_extend_trial?' do
subject { namespace.can_extend_trial? } subject { namespace.can_extend_trial? }
context 'feature flag is disabled' do
before do
allow(namespace).to receive(:trial_active?).and_return(true)
allow(namespace).to receive(:trial_extended_or_reactivated?).and_return(false)
stub_feature_flags(allow_extend_reactivate_trial: false)
end
it { is_expected.to be_falsey }
end
context 'when feature flag is enabled' do
where(:trial_active, :trial_extended_or_reactivated, :can_extend_trial) do where(:trial_active, :trial_extended_or_reactivated, :can_extend_trial) do
false | false | false false | false | false
false | true | false false | true | false
...@@ -1248,10 +1260,25 @@ RSpec.describe Namespace do ...@@ -1248,10 +1260,25 @@ RSpec.describe Namespace do
it { is_expected.to be can_extend_trial } it { is_expected.to be can_extend_trial }
end end
end end
end
describe '#can_reactivate_trial?' do describe '#can_reactivate_trial?' do
subject { namespace.can_reactivate_trial? } subject { namespace.can_reactivate_trial? }
context 'when feature flag is disabled' do
before do
allow(namespace).to receive(:trial_active?).and_return(false)
allow(namespace).to receive(:never_had_trial?).and_return(false)
allow(namespace).to receive(:trial_extended_or_reactivated?).and_return(false)
allow(namespace).to receive(:free_plan?).and_return(true)
stub_feature_flags(allow_extend_reactivate_trial: false)
end
it { is_expected.to be_falsey }
end
context 'when feature flag is enabled' do
where(:trial_active, :never_had_trial, :trial_extended_or_reactivated, :free_plan, :can_reactivate_trial) do where(:trial_active, :never_had_trial, :trial_extended_or_reactivated, :free_plan, :can_reactivate_trial) do
false | false | false | false | false false | false | false | false | false
false | false | false | true | true false | false | false | true | true
...@@ -1282,6 +1309,7 @@ RSpec.describe Namespace do ...@@ -1282,6 +1309,7 @@ RSpec.describe Namespace do
it { is_expected.to be can_reactivate_trial } it { is_expected.to be can_reactivate_trial }
end end
end end
end
describe '#file_template_project_id' do describe '#file_template_project_id' do
it 'is cleared before validation' do it 'is cleared before validation' do
......
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