Commit cfdb739b authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'trial-namespace-use-new-purchase-flow' into 'master'

Trial namespace uses new purchase flow

See merge request gitlab-org/gitlab!47880
parents 219f6621 aa66ccd0
......@@ -23,8 +23,7 @@ module BillingPlansHelper
end
def use_new_purchase_flow?(namespace)
namespace.group? &&
namespace.actual_plan_name == Plan::FREE
namespace.group? && (namespace.actual_plan_name == Plan::FREE || namespace.trial_active?)
end
def show_contact_sales_button?(purchase_link_action)
......
......@@ -39,6 +39,22 @@ module EE
scope :include_gitlab_subscription_with_hosted_plan, -> { includes(gitlab_subscription: :hosted_plan) }
scope :join_gitlab_subscription, -> { joins("LEFT OUTER JOIN gitlab_subscriptions ON gitlab_subscriptions.namespace_id=namespaces.id") }
scope :top_most, -> { where(parent_id: nil) }
scope :in_active_trial, -> do
left_joins(gitlab_subscription: :hosted_plan)
.where(gitlab_subscriptions: { trial: true, trial_ends_on: Date.today.. })
end
scope :in_default_plan, -> do
left_joins(gitlab_subscription: :hosted_plan)
.where(plans: { name: [nil, *::Plan.default_plans] })
end
scope :eligible_for_subscription, -> do
top_most.in_active_trial.or(top_most.in_default_plan)
end
scope :eligible_for_trial, -> do
left_joins(gitlab_subscription: :hosted_plan)
.where(
......
......@@ -256,11 +256,7 @@ module EE
end
def manageable_groups_eligible_for_subscription
manageable_groups
.where(parent_id: nil)
.left_joins(:gitlab_subscription)
.merge(GitlabSubscription.left_joins(:hosted_plan).where(plans: { name: [nil, *::Plan.default_plans] }))
.order(:name)
manageable_groups.eligible_for_subscription.order(:name)
end
def manageable_groups_eligible_for_trial
......
---
title: New subscription purchase for trial namespaces follow new flow
merge_request: 47880
author:
type: changed
......@@ -57,7 +57,8 @@ RSpec.describe BillingPlansHelper do
describe '#use_new_purchase_flow?' do
where type: ['Group', nil],
plan: Plan.all_plans
plan: Plan.all_plans,
trial_active: [true, false]
with_them do
let_it_be(:user) { create(:user) }
......@@ -68,12 +69,13 @@ RSpec.describe BillingPlansHelper do
before do
allow(helper).to receive(:current_user).and_return(user)
allow(namespace).to receive(:trial_active?).and_return(trial_active)
end
subject { helper.use_new_purchase_flow?(namespace) }
it do
result = type == 'Group' && plan == Plan::FREE
result = type == 'Group' && (plan == Plan::FREE || trial_active)
is_expected.to be(result)
end
......
......@@ -171,6 +171,130 @@ RSpec.describe Namespace do
end
end
describe '.top_most' do
let_it_be(:namespace) { create(:namespace) }
let_it_be(:sub_namespace) { create(:namespace, parent: namespace) }
subject { described_class.top_most.ids }
it 'only contains root namespace' do
is_expected.to eq([namespace.id])
end
end
describe '.in_active_trial' do
let_it_be(:namespaces) do
[
create(:namespace),
create(:namespace_with_plan),
create(:namespace_with_plan, trial_ends_on: Date.tomorrow)
]
end
it 'is consistent to trial_active? method' do
namespaces.each do |ns|
consistent = described_class.in_active_trial.include?(ns) == !!ns.trial_active?
expect(consistent).to be true
end
end
end
describe '.in_default_plan' do
subject { described_class.in_default_plan.ids }
where(:plan_name, :expect_in_default_plan) do
::Plan::FREE | true
::Plan::DEFAULT | true
::Plan::BRONZE | false
::Plan::SILVER | false
::Plan::GOLD | false
end
with_them do
it 'returns expected result' do
namespace = create(:namespace_with_plan, plan: "#{plan_name}_plan")
is_expected.to eq(expect_in_default_plan ? [namespace.id] : [])
end
end
it 'includes namespace with no subscription' do
namespace = create(:namespace)
is_expected.to eq([namespace.id])
end
end
describe '.eligible_for_subscription' do
let_it_be(:namespace) { create :namespace }
let_it_be(:sub_namespace) { create(:namespace, parent: namespace) }
subject { described_class.eligible_for_subscription.ids }
context 'when there is no subscription' do
it { is_expected.to eq([namespace.id]) }
end
context 'when there is a subscription' do
context 'with a plan that is eligible for a trial' do
where(plan: ::Plan::PLANS_ELIGIBLE_FOR_TRIAL)
with_them do
context 'and has not yet been trialed' do
before do
create :gitlab_subscription, plan, namespace: namespace
create :gitlab_subscription, plan, namespace: sub_namespace
end
it { is_expected.to eq([namespace.id]) }
end
context 'but has already had a trial' do
before do
create :gitlab_subscription, plan, :expired_trial, namespace: namespace
create :gitlab_subscription, plan, :expired_trial, namespace: sub_namespace
end
it { is_expected.to eq([namespace.id]) }
end
context 'but is currently being trialed' do
before do
create :gitlab_subscription, plan, :active_trial, namespace: namespace
create :gitlab_subscription, plan, :active_trial, namespace: sub_namespace
end
it { is_expected.to eq([namespace.id]) }
end
end
end
context 'in active trial gold plan' do
before do
create :gitlab_subscription, ::Plan::GOLD, :active_trial, namespace: namespace
create :gitlab_subscription, ::Plan::GOLD, :active_trial, namespace: sub_namespace
end
it { is_expected.to eq([namespace.id]) }
end
context 'with a paid plan and not in trial' do
where(plan: ::Plan::PAID_HOSTED_PLANS)
with_them do
context 'and has not yet been trialed' do
before do
create :gitlab_subscription, plan, namespace: namespace
end
it { is_expected.to be_empty }
end
end
end
end
end
describe '.eligible_for_trial' do
let_it_be(:namespace) { create :namespace }
......
......@@ -1019,6 +1019,7 @@ RSpec.describe User do
let_it_be(:free_group_z) { create(:group, name: 'AZ', gitlab_subscription: create(:gitlab_subscription, :free)) }
let_it_be(:free_group_a) { create(:group, name: 'AA', gitlab_subscription: create(:gitlab_subscription, :free)) }
let_it_be(:sub_group) { create(:group, name: 'SubGroup', parent: free_group_a) }
let_it_be(:trial_group) { create(:group, name: 'AB', gitlab_subscription: create(:gitlab_subscription, :active_trial, :gold)) }
subject { user.manageable_groups_eligible_for_subscription }
......@@ -1068,6 +1069,30 @@ RSpec.describe User do
it { is_expected.not_to include(sub_group) }
end
context 'developer of a trial group' do
before do
trial_group.add_developer(user)
end
it { is_expected.not_to include(trial_group) }
end
context 'owner of a trial group' do
before do
trial_group.add_owner(user)
end
it { is_expected.to include(trial_group) }
end
context 'maintainer of a trial group' do
before do
trial_group.add_maintainer(user)
end
it { is_expected.to include(trial_group) }
end
end
describe '#manageable_groups_eligible_for_trial' 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