Commit 76b5b71b authored by Phil Hughes's avatar Phil Hughes

Merge branch 'customers-2417-mlunoe-remove-deprecated-plans-for-eoa' into 'master'

Feat(subscription/new): hide EoA deprecated plans

See merge request gitlab-org/gitlab!50994
parents 486939a0 9e250e48
...@@ -38,7 +38,7 @@ const determineNumberOfUsers = (groupId, groups) => { ...@@ -38,7 +38,7 @@ const determineNumberOfUsers = (groupId, groups) => {
}; };
export default ({ export default ({
planData = '[]', availablePlans: plansData = '[]',
planId, planId,
namespaceId, namespaceId,
setupForCompany, setupForCompany,
...@@ -46,7 +46,7 @@ export default ({ ...@@ -46,7 +46,7 @@ export default ({
newUser, newUser,
groupData = '[]', groupData = '[]',
}) => { }) => {
const availablePlans = parsePlanData(planData); const availablePlans = parsePlanData(plansData);
const isNewUser = parseBoolean(newUser); const isNewUser = parseBoolean(newUser);
const groupId = parseInt(namespaceId, 10) || null; const groupId = parseInt(namespaceId, 10) || null;
const groups = parseGroupData(groupData); const groups = parseGroupData(groupData);
......
...@@ -90,7 +90,7 @@ module BillingPlansHelper ...@@ -90,7 +90,7 @@ module BillingPlansHelper
css_classes.join(' ') css_classes.join(' ')
end end
def 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.filter { |plan_data| !plan_data.deprecated? || plan_data.code == current_plan&.code }
......
...@@ -7,7 +7,7 @@ module SubscriptionsHelper ...@@ -7,7 +7,7 @@ module SubscriptionsHelper
{ {
setup_for_company: (current_user.setup_for_company == true).to_s, setup_for_company: (current_user.setup_for_company == true).to_s,
full_name: current_user.name, full_name: current_user.name,
plan_data: plan_data.to_json, available_plans: subscription_available_plans.to_json,
plan_id: params[:plan_id], plan_id: params[:plan_id],
namespace_id: params[:namespace_id], namespace_id: params[:namespace_id],
new_user: new_user?.to_s, new_user: new_user?.to_s,
...@@ -17,7 +17,7 @@ module SubscriptionsHelper ...@@ -17,7 +17,7 @@ module SubscriptionsHelper
def plan_title def plan_title
strong_memoize(:plan_title) do strong_memoize(:plan_title) do
plan = plan_data.find { |plan| plan[:id] == params[:plan_id] } plan = subscription_available_plans.find { |plan| plan[:id] == params[:plan_id] }
plan[:code].titleize if plan plan[:code].titleize if plan
end end
end end
...@@ -30,11 +30,17 @@ module SubscriptionsHelper ...@@ -30,11 +30,17 @@ module SubscriptionsHelper
URI.parse(request.referer).path == users_sign_up_welcome_path URI.parse(request.referer).path == users_sign_up_welcome_path
end end
def plan_data def plans_data
FetchSubscriptionPlansService.new(plan: :free).execute FetchSubscriptionPlansService.new(plan: :free).execute
.map(&:symbolize_keys) .map(&:symbolize_keys)
.reject { |plan| plan[:free] } .reject { |plan_data| plan_data[:free] }
.map { |plan| plan.slice(:id, :code, :price_per_year) } .map { |plan_data| plan_data.slice(:id, :code, :price_per_year, :deprecated) }
end
def subscription_available_plans
return plans_data unless ::Feature.enabled?(:hide_deprecated_billing_plans)
plans_data.reject { |plan_data| plan_data[:deprecated] }
end end
def group_data def group_data
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
= render 'shared/billings/billing_plan_header', namespace: namespace, plan: current_plan = render 'shared/billings/billing_plan_header', namespace: namespace, plan: current_plan
- if show_plans?(namespace) - if show_plans?(namespace)
- plans = available_plans(plans_data, current_plan) - plans = billing_available_plans(plans_data, current_plan)
.billing-plans.gl-mt-5.row.justify-content-center .billing-plans.gl-mt-5.row.justify-content-center
- plans.each do |plan| - plans.each do |plan|
......
...@@ -10,14 +10,14 @@ describe('Order Summary', () => { ...@@ -10,14 +10,14 @@ describe('Order Summary', () => {
let wrapper; let wrapper;
const planData = [ const availablePlans = [
{ id: 'firstPlanId', code: 'bronze', price_per_year: 48 }, { id: 'firstPlanId', code: 'bronze', price_per_year: 48 },
{ id: 'secondPlanId', code: 'silver', price_per_year: 228 }, { id: 'secondPlanId', code: 'silver', price_per_year: 228 },
{ id: 'thirdPlanId', code: 'gold', price_per_year: 1188 }, { id: 'thirdPlanId', code: 'gold', price_per_year: 1188 },
]; ];
const initialData = { const initialData = {
planData: JSON.stringify(planData), availablePlans: JSON.stringify(availablePlans),
planId: 'thirdPlanId', planId: 'thirdPlanId',
namespaceId: null, namespaceId: null,
fullName: 'Full Name', fullName: 'Full Name',
......
...@@ -13,7 +13,7 @@ describe('Subscription Details', () => { ...@@ -13,7 +13,7 @@ describe('Subscription Details', () => {
let store; let store;
let wrapper; let wrapper;
const planData = [ const availablePlans = [
{ id: 'firstPlanId', code: 'bronze', price_per_year: 48 }, { id: 'firstPlanId', code: 'bronze', price_per_year: 48 },
{ id: 'secondPlanId', code: 'silver', price_per_year: 228 }, { id: 'secondPlanId', code: 'silver', price_per_year: 228 },
]; ];
...@@ -26,7 +26,7 @@ describe('Subscription Details', () => { ...@@ -26,7 +26,7 @@ describe('Subscription Details', () => {
let initialNamespaceId = null; let initialNamespaceId = null;
const initialData = (namespaceId) => { const initialData = (namespaceId) => {
return { return {
planData: JSON.stringify(planData), availablePlans: JSON.stringify(availablePlans),
groupData: JSON.stringify(groupData), groupData: JSON.stringify(groupData),
planId: 'secondPlanId', planId: 'secondPlanId',
namespaceId, namespaceId,
......
...@@ -5,7 +5,7 @@ constants.STEPS = ['firstStep', 'secondStep']; ...@@ -5,7 +5,7 @@ constants.STEPS = ['firstStep', 'secondStep'];
constants.TAX_RATE = 0; constants.TAX_RATE = 0;
describe('projectsSelector default state', () => { describe('projectsSelector default state', () => {
const planData = [ const availablePlans = [
{ id: 'firstPlanId', code: 'bronze', price_per_year: 48 }, { id: 'firstPlanId', code: 'bronze', price_per_year: 48 },
{ id: 'secondPlanId', code: 'silver', price_per_year: 228 }, { id: 'secondPlanId', code: 'silver', price_per_year: 228 },
]; ];
...@@ -16,7 +16,7 @@ describe('projectsSelector default state', () => { ...@@ -16,7 +16,7 @@ describe('projectsSelector default state', () => {
]; ];
const initialData = { const initialData = {
planData: JSON.stringify(planData), availablePlans: JSON.stringify(availablePlans),
groupData: JSON.stringify(groupData), groupData: JSON.stringify(groupData),
planId: 'secondPlanId', planId: 'secondPlanId',
namespaceId: null, namespaceId: null,
...@@ -36,22 +36,22 @@ describe('projectsSelector default state', () => { ...@@ -36,22 +36,22 @@ describe('projectsSelector default state', () => {
}); });
describe('availablePlans', () => { describe('availablePlans', () => {
it('sets the availablePlans to the provided parsed planData', () => { it('sets the availablePlans to the provided parsed availablePlans', () => {
expect(state.availablePlans).toEqual([ expect(state.availablePlans).toEqual([
{ value: 'firstPlanId', text: 'Bronze', pricePerUserPerYear: 48 }, { value: 'firstPlanId', text: 'Bronze', pricePerUserPerYear: 48 },
{ value: 'secondPlanId', text: 'Silver', pricePerUserPerYear: 228 }, { value: 'secondPlanId', text: 'Silver', pricePerUserPerYear: 228 },
]); ]);
}); });
it('sets the availablePlans to an empty array when no planData provided', () => { it('sets the availablePlans to an empty array when no availablePlans provided', () => {
const modifiedState = createState({ ...initialData, ...{ planData: undefined } }); const modifiedState = createState({ ...initialData, ...{ availablePlans: undefined } });
expect(modifiedState.availablePlans).toEqual([]); expect(modifiedState.availablePlans).toEqual([]);
}); });
}); });
describe('selectedPlan', () => { describe('selectedPlan', () => {
it('sets the selectedPlan to the provided planId if it is present in the provided planData', () => { it('sets the selectedPlan to the provided planId if it is present in the provided availablePlans', () => {
expect(state.selectedPlan).toEqual('secondPlanId'); expect(state.selectedPlan).toEqual('secondPlanId');
}); });
...@@ -68,7 +68,7 @@ describe('projectsSelector default state', () => { ...@@ -68,7 +68,7 @@ describe('projectsSelector default state', () => {
}); });
it('sets the selectedPlan to an empty string if availablePlans are not present', () => { it('sets the selectedPlan to an empty string if availablePlans are not present', () => {
const modifiedState = createState({ ...initialData, ...{ planData: '[]' } }); const modifiedState = createState({ ...initialData, ...{ availablePlans: '[]' } });
expect(modifiedState.selectedPlan).toBeUndefined(); expect(modifiedState.selectedPlan).toBeUndefined();
}); });
......
...@@ -228,14 +228,14 @@ RSpec.describe BillingPlansHelper do ...@@ -228,14 +228,14 @@ RSpec.describe BillingPlansHelper do
end end
end end
describe '#available_plans' do describe '#billing_available_plans' do
let(:plan) { double('Plan', deprecated?: false, code: 'silver') } let(:plan) { double('Plan', deprecated?: false, code: 'silver') }
let(:deprecated_plan) { double('Plan', deprecated?: true, code: 'bronze') } let(:deprecated_plan) { double('Plan', deprecated?: true, code: 'bronze') }
let(:plans_data) { [plan, deprecated_plan] } let(:plans_data) { [plan, deprecated_plan] }
context 'when namespace is on an active plan' do context 'when namespace is on an active plan' do
it 'returns plans without deprecated' do it 'returns plans without deprecated' do
expect(helper.available_plans(plans_data, nil)).to eq([plan]) expect(helper.billing_available_plans(plans_data, nil)).to eq([plan])
end end
end end
...@@ -243,7 +243,7 @@ RSpec.describe BillingPlansHelper do ...@@ -243,7 +243,7 @@ RSpec.describe BillingPlansHelper do
let(:current_plan) { Hashie::Mash.new(code: 'bronze') } let(:current_plan) { Hashie::Mash.new(code: 'bronze') }
it 'returns plans with a deprecated plan' do it 'returns plans with a deprecated plan' do
expect(helper.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
end end
......
...@@ -5,12 +5,11 @@ require 'spec_helper' ...@@ -5,12 +5,11 @@ require 'spec_helper'
RSpec.describe SubscriptionsHelper do RSpec.describe SubscriptionsHelper do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
let_it_be(:raw_plan_data) do let_it_be(:free_plan) do
[ { "name" => "Free Plan", "free" => true, "code" => "free" }
{ end
"name" => "Free Plan",
"free" => true let(:bronze_plan) do
},
{ {
"id" => "bronze_id", "id" => "bronze_id",
"name" => "Bronze Plan", "name" => "Bronze Plan",
...@@ -18,10 +17,14 @@ RSpec.describe SubscriptionsHelper do ...@@ -18,10 +17,14 @@ RSpec.describe SubscriptionsHelper do
"code" => "bronze", "code" => "bronze",
"price_per_year" => 48.0 "price_per_year" => 48.0
} }
] end
let(:raw_plan_data) do
[free_plan, bronze_plan]
end end
before do before do
stub_feature_flags(hide_deprecated_billing_plans: false)
allow(helper).to receive(:params).and_return(plan_id: 'bronze_id', namespace_id: nil) allow(helper).to receive(:params).and_return(plan_id: 'bronze_id', namespace_id: nil)
allow_next_instance_of(FetchSubscriptionPlansService) do |instance| allow_next_instance_of(FetchSubscriptionPlansService) do |instance|
allow(instance).to receive(:execute).and_return(raw_plan_data) allow(instance).to receive(:execute).and_return(raw_plan_data)
...@@ -42,7 +45,7 @@ RSpec.describe SubscriptionsHelper do ...@@ -42,7 +45,7 @@ RSpec.describe SubscriptionsHelper do
it { is_expected.to include(setup_for_company: 'false') } it { is_expected.to include(setup_for_company: 'false') }
it { is_expected.to include(full_name: 'First Last') } it { is_expected.to include(full_name: 'First Last') }
it { is_expected.to include(plan_data: '[{"id":"bronze_id","code":"bronze","price_per_year":48.0}]') } it { is_expected.to include(available_plans: '[{"id":"bronze_id","code":"bronze","price_per_year":48.0}]') }
it { is_expected.to include(plan_id: 'bronze_id') } it { is_expected.to include(plan_id: 'bronze_id') }
it { is_expected.to include(namespace_id: group.id.to_s) } it { is_expected.to include(namespace_id: group.id.to_s) }
it { is_expected.to include(group_data: %Q{[{"id":#{group.id},"name":"My Namespace","users":1}]}) } it { is_expected.to include(group_data: %Q{[{"id":#{group.id},"name":"My Namespace","users":1}]}) }
...@@ -62,6 +65,44 @@ RSpec.describe SubscriptionsHelper do ...@@ -62,6 +65,44 @@ RSpec.describe SubscriptionsHelper do
it { is_expected.to include(new_user: expected_result) } it { is_expected.to include(new_user: expected_result) }
end end
end end
context 'when bronze_plan is deprecated' do
let(:bronze_plan) do
{
"id" => "bronze_id",
"name" => "Bronze Plan",
"deprecated" => true,
"free" => false,
"code" => "bronze",
"price_per_year" => 48.0
}
end
it { is_expected.to include(available_plans: '[{"id":"bronze_id","code":"bronze","price_per_year":48.0,"deprecated":true}]') }
end
context 'when ff purchase_deprecated_plans is enabled' do
before do
stub_feature_flags(hide_deprecated_billing_plans: true)
end
it { is_expected.to include(available_plans: '[{"id":"bronze_id","code":"bronze","price_per_year":48.0}]') }
context 'when bronze_plan is deprecated' do
let(:bronze_plan) do
{
"id" => "bronze_id",
"name" => "Bronze Plan",
"deprecated" => true,
"free" => false,
"code" => "bronze",
"price_per_year" => 48.0
}
end
it { is_expected.to include(available_plans: '[]') }
end
end
end end
describe '#plan_title' do describe '#plan_title' 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