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