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
end
def can_extend_trial?
return false unless ::Feature.enabled?(:allow_extend_reactivate_trial, default_enabled: :yaml)
trial_active? && !trial_extended_or_reactivated?
end
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?
end
......
......@@ -228,14 +228,32 @@ RSpec.describe EE::TrialHelper do
end
context 'when feature flag is disabled' do
it { is_expected.to eq({ namespace_id: 1, plan_name: 'Ultimate', action: nil })}
end
context 'when feature flag is enabled' do
before do
stub_feature_flags(allow_extend_reactivate_trial: true)
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 })}
end
context 'when trial can be reactivated' 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)
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
before do
allow(namespace).to receive(:can_extend_trial?).and_return(true)
......
......@@ -1232,54 +1232,82 @@ RSpec.describe Namespace do
describe '#can_extend_trial?' do
subject { namespace.can_extend_trial? }
where(:trial_active, :trial_extended_or_reactivated, :can_extend_trial) do
false | false | false
false | true | false
true | false | true
true | true | false
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
with_them do
before do
allow(namespace).to receive(:trial_active?).and_return(trial_active)
allow(namespace).to receive(:trial_extended_or_reactivated?).and_return(trial_extended_or_reactivated)
context 'when feature flag is enabled' do
where(:trial_active, :trial_extended_or_reactivated, :can_extend_trial) do
false | false | false
false | true | false
true | false | true
true | true | false
end
it { is_expected.to be can_extend_trial }
with_them do
before do
allow(namespace).to receive(:trial_active?).and_return(trial_active)
allow(namespace).to receive(:trial_extended_or_reactivated?).and_return(trial_extended_or_reactivated)
end
it { is_expected.to be can_extend_trial }
end
end
end
describe '#can_reactivate_trial?' do
subject { namespace.can_reactivate_trial? }
where(:trial_active, :never_had_trial, :trial_extended_or_reactivated, :free_plan, :can_reactivate_trial) do
false | false | false | false | false
false | false | false | true | true
false | false | true | false | false
false | false | true | true | false
false | true | false | false | false
false | true | false | true | false
false | true | true | false | false
false | true | true | true | false
true | false | false | false | false
true | false | false | true | false
true | false | true | false | false
true | false | true | true | false
true | true | false | false | false
true | true | false | true | false
true | true | true | false | false
true | true | true | true | false
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
with_them do
before do
allow(namespace).to receive(:trial_active?).and_return(trial_active)
allow(namespace).to receive(:never_had_trial?).and_return(never_had_trial)
allow(namespace).to receive(:trial_extended_or_reactivated?).and_return(trial_extended_or_reactivated)
allow(namespace).to receive(:free_plan?).and_return(free_plan)
context 'when feature flag is enabled' 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 | true | true
false | false | true | false | false
false | false | true | true | false
false | true | false | false | false
false | true | false | true | false
false | true | true | false | false
false | true | true | true | false
true | false | false | false | false
true | false | false | true | false
true | false | true | false | false
true | false | true | true | false
true | true | false | false | false
true | true | false | true | false
true | true | true | false | false
true | true | true | true | false
end
it { is_expected.to be can_reactivate_trial }
with_them do
before do
allow(namespace).to receive(:trial_active?).and_return(trial_active)
allow(namespace).to receive(:never_had_trial?).and_return(never_had_trial)
allow(namespace).to receive(:trial_extended_or_reactivated?).and_return(trial_extended_or_reactivated)
allow(namespace).to receive(:free_plan?).and_return(free_plan)
end
it { is_expected.to be can_reactivate_trial }
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