Commit c32f7d04 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'add-deprecated-card-plan-override' into 'master'

Allow Hiding Card in Billing Page for Current Deprecated Plans

See merge request gitlab-org/gitlab!52039
parents de38da5e 377b3d92
...@@ -97,7 +97,13 @@ module BillingPlansHelper ...@@ -97,7 +97,13 @@ module BillingPlansHelper
def billing_available_plans(plans_data, current_plan) def billing_available_plans(plans_data, current_plan)
return plans_data unless ::Feature.enabled?(:hide_deprecated_billing_plans) return plans_data unless ::Feature.enabled?(:hide_deprecated_billing_plans)
plans_data.filter { |plan_data| !plan_data.deprecated? || plan_data.code == current_plan&.code } plans_data.reject do |plan_data|
if plan_data.code == current_plan&.code
plan_data.deprecated? && plan_data.hide_deprecated_card?
else
plan_data.deprecated?
end
end
end end
private private
......
...@@ -271,11 +271,19 @@ RSpec.describe BillingPlansHelper do ...@@ -271,11 +271,19 @@ RSpec.describe BillingPlansHelper do
end end
describe '#billing_available_plans' do describe '#billing_available_plans' do
let(:plan) { double('Plan', deprecated?: false, code: 'silver') } let(:plan) { double('Plan', deprecated?: false, code: 'silver', hide_deprecated_card?: false) }
let(:deprecated_plan) { double('Plan', deprecated?: true, code: 'bronze') } let(:deprecated_plan) { double('Plan', deprecated?: true, code: 'bronze', hide_deprecated_card?: false) }
let(:plans_data) { [plan, deprecated_plan] } let(:plans_data) { [plan, deprecated_plan] }
context 'when namespace is not on a plan' do
it 'returns plans without deprecated' do
expect(helper.billing_available_plans(plans_data, nil)).to eq([plan])
end
end
context 'when namespace is on an active plan' do context 'when namespace is on an active plan' do
let(:current_plan) { Hashie::Mash.new(code: 'silver') }
it 'returns plans without deprecated' do it 'returns plans without deprecated' do
expect(helper.billing_available_plans(plans_data, nil)).to eq([plan]) expect(helper.billing_available_plans(plans_data, nil)).to eq([plan])
end end
...@@ -288,5 +296,23 @@ RSpec.describe BillingPlansHelper do ...@@ -288,5 +296,23 @@ RSpec.describe BillingPlansHelper do
expect(helper.billing_available_plans(plans_data, current_plan)).to eq(plans_data) expect(helper.billing_available_plans(plans_data, current_plan)).to eq(plans_data)
end end
end end
context 'when namespace is on a deprecated plan that has hide_deprecated_card set to true' do
let(:current_plan) { Hashie::Mash.new(code: 'bronze') }
let(:deprecated_plan) { double('Plan', deprecated?: true, code: 'bronze', hide_deprecated_card?: true) }
it 'returns plans without the deprecated plan' do
expect(helper.billing_available_plans(plans_data, current_plan)).to eq([plan])
end
end
context 'when namespace is on a plan that has hide_deprecated_card set to true, but deprecated? is false' do
let(:current_plan) { Hashie::Mash.new(code: 'silver') }
let(:plan) { double('Plan', deprecated?: false, code: 'silver', hide_deprecated_card?: true) }
it 'returns plans with the deprecated plan' do
expect(helper.billing_available_plans(plans_data, current_plan)).to eq([plan])
end
end
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