Commit 0038d3a2 authored by James Lopez's avatar James Lopez

Merge branch 'astoicescu-feature-specs-2' into 'master'

Add feature specs for Upgrade Offer scenarios

See merge request gitlab-org/gitlab!56017
parents 3edf67c8 18f0120d
...@@ -109,7 +109,7 @@ module BillingPlansHelper ...@@ -109,7 +109,7 @@ module BillingPlansHelper
css_classes = %w[btn btn-success gl-button] css_classes = %w[btn btn-success gl-button]
css_classes << 'disabled' if is_current_plan && !namespace.trial_active? css_classes << 'disabled' if is_current_plan && !namespace.trial_active?
css_classes << 'invisible' if plan.deprecated? css_classes << 'invisible' if ::Feature.enabled?(:hide_deprecated_billing_plans) && plan.deprecated?
css_classes.join(' ') css_classes.join(' ')
end end
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
- faq_link_url = 'https://about.gitlab.com/pricing/faq-new-product-subscription-tiers' - faq_link_url = 'https://about.gitlab.com/pricing/faq-new-product-subscription-tiers'
- faq_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: faq_link_url } - faq_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: faq_link_url }
.card-wrapper{ class: ("card-wrapper-has-badge" if has_upgrade) } .card-wrapper{ class: ("card-wrapper-has-badge" if has_upgrade), data: { testid: "plan-card-#{plan.code}" } }
- if has_upgrade - if has_upgrade
.card-badge .card-badge
%span.card-badge-text %span.card-badge-text
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Billing plan pages', :feature do RSpec.describe 'Billing plan pages', :feature, :js do
include StubRequests
include SubscriptionPortalHelpers include SubscriptionPortalHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
...@@ -12,6 +11,7 @@ RSpec.describe 'Billing plan pages', :feature do ...@@ -12,6 +11,7 @@ RSpec.describe 'Billing plan pages', :feature do
let(:bronze_plan) { create(:bronze_plan) } let(:bronze_plan) { create(:bronze_plan) }
let(:premium_plan) { create(:premium_plan) } let(:premium_plan) { create(:premium_plan) }
let(:ultimate_plan) { create(:ultimate_plan) } let(:ultimate_plan) { create(:ultimate_plan) }
let(:plans_data) do let(:plans_data) do
Gitlab::Json.parse(File.read(Rails.root.join('ee/spec/fixtures/gitlab_com_plans.json'))).map do |data| Gitlab::Json.parse(File.read(Rails.root.join('ee/spec/fixtures/gitlab_com_plans.json'))).map do |data|
data.deep_symbolize_keys data.deep_symbolize_keys
...@@ -27,7 +27,7 @@ RSpec.describe 'Billing plan pages', :feature do ...@@ -27,7 +27,7 @@ RSpec.describe 'Billing plan pages', :feature do
stub_eoa_eligibility_request(namespace.id) stub_eoa_eligibility_request(namespace.id)
stub_application_setting(check_namespace_plan: true) stub_application_setting(check_namespace_plan: true)
allow(Gitlab).to receive(:com?) { true } allow(Gitlab).to receive(:com?) { true }
gitlab_sign_in(user) sign_in(user)
end end
def external_upgrade_url(namespace, plan) def external_upgrade_url(namespace, plan)
...@@ -116,7 +116,7 @@ RSpec.describe 'Billing plan pages', :feature do ...@@ -116,7 +116,7 @@ RSpec.describe 'Billing plan pages', :feature do
visit page_path visit page_path
end end
it 'displays subscription table', :js do it 'displays subscription table' do
expect(page).to have_selector('.js-subscription-table') expect(page).to have_selector('.js-subscription-table')
end end
end end
...@@ -126,23 +126,80 @@ RSpec.describe 'Billing plan pages', :feature do ...@@ -126,23 +126,80 @@ RSpec.describe 'Billing plan pages', :feature do
visit page_path visit page_path
end end
it 'displays the number of seats', :js do it 'displays the number of seats' do
page.within('.js-subscription-table') do page.within('.js-subscription-table') do
expect(page).to have_selector('p.property-value.gl-mt-2.gl-mb-0.number', text: '1') expect(page).to have_selector('p.property-value.gl-mt-2.gl-mb-0.number', text: '1')
end end
end end
end end
shared_examples 'active deprecated plan' do
let(:legacy_plan) { plans_data.find { |plan_data| plan_data[:id] == 'bronze-external-id' } }
let(:expected_card_header) { "#{legacy_plan[:name]} (Legacy)" }
before do
stub_feature_flags(hide_deprecated_billing_plans: true)
visit page_path
end
it 'renders the plan card marked as Legacy' do
page.within('.billing-plans') do
panels = page.all('.card')
expect(panels.length).to eq(plans_data.length)
panel_with_legacy_plan = page.find("[data-testid='plan-card-#{legacy_plan[:code]}']")
expect(panel_with_legacy_plan.find('.card-header')).to have_content(expected_card_header)
expect(panel_with_legacy_plan.find('.card-body')).to have_link('frequently asked questions')
end
end
end
shared_examples 'inactive deprecated plan' do
let(:legacy_plan) { plans_data.find { |plan_data| plan_data[:id] == 'bronze-external-id' } }
before do
stub_feature_flags(hide_deprecated_billing_plans: true)
visit page_path
end
it 'does not render the card for that plan' do
expect(page).not_to have_selector("[data-testid='plan-card-#{legacy_plan[:code]}']")
end
end
shared_examples 'plan with free upgrade' do
before do
visit page_path
end
it 'displays the free upgrade' do
within '.card-badge' do
expect(page).to have_text('Free upgrade!')
end
end
end
shared_examples 'plan with sales-assisted upgrade' do
before do
visit page_path
end
it 'displays the sales assisted offer' do
within '.card-badge' do
expect(page).to have_text('Upgrade offers available!')
end
end
end
context 'users profile billing page' do context 'users profile billing page' do
let(:page_path) { profile_billings_path } let(:page_path) { profile_billings_path }
context 'on free' do context 'on free' do
let(:plan) { free_plan } let(:plan) { free_plan }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
before do before do
visit page_path visit page_path
end end
...@@ -187,9 +244,7 @@ RSpec.describe 'Billing plan pages', :feature do ...@@ -187,9 +244,7 @@ RSpec.describe 'Billing plan pages', :feature do
context 'on bronze plan' do context 'on bronze plan' do
let(:plan) { bronze_plan } let(:plan) { bronze_plan }
let!(:subscription) do let!(:subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15) }
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
it 'shows the EoA bronze banner that can be dismissed permanently', :js do it 'shows the EoA bronze banner that can be dismissed permanently', :js do
travel_to(Date.parse(EE::UserCalloutsHelper::EOA_BRONZE_PLAN_END_DATE) - 1.day) do travel_to(Date.parse(EE::UserCalloutsHelper::EOA_BRONZE_PLAN_END_DATE) - 1.day) do
...@@ -212,14 +267,34 @@ RSpec.describe 'Billing plan pages', :feature do ...@@ -212,14 +267,34 @@ RSpec.describe 'Billing plan pages', :feature do
it_behaves_like 'upgradable plan' it_behaves_like 'upgradable plan'
it_behaves_like 'can contact sales' it_behaves_like 'can contact sales'
it_behaves_like 'plan with subscription table' it_behaves_like 'plan with subscription table'
context 'when hide_deprecated_billing_plans is active' do
let(:premium_plan_data) { plans_data.find { |plan_data| plan_data[:id] == 'premium-external-id' } }
before do
stub_feature_flags(hide_deprecated_billing_plans: true)
stub_eoa_eligibility_request(namespace.id, true, premium_plan_data[:id])
end
it_behaves_like 'plan with free upgrade'
it_behaves_like 'active deprecated plan'
context 'with more than 25 users' do
let!(:subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 30) }
before do
stub_eoa_eligibility_request(namespace.id, false, premium_plan_data[:id])
end
it_behaves_like 'plan with sales-assisted upgrade'
end
end
end end
context 'on premium plan' do context 'on premium plan' do
let(:plan) { premium_plan } let(:plan) { premium_plan }
let!(:subscription) do let!(:subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15) }
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
it_behaves_like 'plan with header' it_behaves_like 'plan with header'
it_behaves_like 'downgradable plan' it_behaves_like 'downgradable plan'
...@@ -232,9 +307,7 @@ RSpec.describe 'Billing plan pages', :feature do ...@@ -232,9 +307,7 @@ RSpec.describe 'Billing plan pages', :feature do
context 'on ultimate plan' do context 'on ultimate plan' do
let(:plan) { ultimate_plan } let(:plan) { ultimate_plan }
let!(:subscription) do let!(:subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15) }
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
it_behaves_like 'plan with header' it_behaves_like 'plan with header'
it_behaves_like 'downgradable plan' it_behaves_like 'downgradable plan'
...@@ -298,9 +371,7 @@ RSpec.describe 'Billing plan pages', :feature do ...@@ -298,9 +371,7 @@ RSpec.describe 'Billing plan pages', :feature do
context 'on bronze plan' do context 'on bronze plan' do
let(:plan) { bronze_plan } let(:plan) { bronze_plan }
let!(:subscription) do let!(:subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15) }
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
it_behaves_like 'plan with header' it_behaves_like 'plan with header'
it_behaves_like 'downgradable plan' it_behaves_like 'downgradable plan'
...@@ -311,9 +382,7 @@ RSpec.describe 'Billing plan pages', :feature do ...@@ -311,9 +382,7 @@ RSpec.describe 'Billing plan pages', :feature do
context 'on ultimate plan' do context 'on ultimate plan' do
let(:plan) { ultimate_plan } let(:plan) { ultimate_plan }
let!(:subscription) do let!(:subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15) }
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
it_behaves_like 'plan with header' it_behaves_like 'plan with header'
it_behaves_like 'downgradable plan' it_behaves_like 'downgradable plan'
...@@ -331,9 +400,7 @@ RSpec.describe 'Billing plan pages', :feature do ...@@ -331,9 +400,7 @@ RSpec.describe 'Billing plan pages', :feature do
context 'on ultimate' do context 'on ultimate' do
let(:plan) { ultimate_plan } let(:plan) { ultimate_plan }
let!(:subscription) do let!(:subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15) }
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
before do before do
visit page_path visit page_path
...@@ -351,17 +418,13 @@ RSpec.describe 'Billing plan pages', :feature do ...@@ -351,17 +418,13 @@ RSpec.describe 'Billing plan pages', :feature do
expect(page).not_to have_css('.billing-plans') expect(page).not_to have_css('.billing-plans')
end end
it 'displays subscription table', :js do it_behaves_like 'plan with subscription table'
expect(page).to have_selector('.js-subscription-table')
end
end end
context 'on bronze' do context 'on bronze' do
let(:plan) { bronze_plan } let(:plan) { bronze_plan }
let!(:subscription) do let!(:subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15) }
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
before do before do
visit page_path visit page_path
...@@ -379,36 +442,18 @@ RSpec.describe 'Billing plan pages', :feature do ...@@ -379,36 +442,18 @@ RSpec.describe 'Billing plan pages', :feature do
expect(page).to have_css('.billing-plans') expect(page).to have_css('.billing-plans')
end end
it 'displays subscription table', :js do
expect(page).to have_selector('.js-subscription-table')
end
it_behaves_like 'can contact sales' it_behaves_like 'can contact sales'
it_behaves_like 'plan with subscription table'
end end
context 'on free' do context 'on free' do
let(:plan) { free_plan } let(:plan) { free_plan }
let!(:subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan: plan) }
it_behaves_like 'used seats rendering for non paid subscriptions' it_behaves_like 'used seats rendering for non paid subscriptions'
end end
end
end
context 'group billing page with a trial' do
let(:namespace) { create(:group) }
let!(:group_member) { create(:group_member, :owner, group: namespace, user: user) }
before do
stub_full_request("#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?plan=free&namespace_id=#{namespace.id}")
.to_return(status: 200, body: plans_data.to_json)
end
context 'top-most group' do context 'on trial' do
let(:page_path) { group_billings_path(namespace) } let(:plan) { premium_plan }
context 'on ultimate' do
let(:plan) { ultimate_plan }
let!(:subscription) do let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, create(:gitlab_subscription, namespace: namespace, hosted_plan: plan,
...@@ -416,61 +461,23 @@ RSpec.describe 'Billing plan pages', :feature do ...@@ -416,61 +461,23 @@ RSpec.describe 'Billing plan pages', :feature do
end end
before do before do
visit page_path stub_full_request("#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?plan=free&namespace_id=#{namespace.id}")
end .to_return(status: 200, body: plans_data.to_json)
it 'displays plan header' do
page.within('.billing-plan-header') do
expect(page).to have_content("#{namespace.name} is currently using the Ultimate Plan")
expect(page).to have_css('.billing-plan-logo .identicon') visit page_path
end
end end
it 'does display the billing plans table' do it 'displays the billing plans table' do
expect(page).to have_css('.billing-plans') expect(page).to have_css('.billing-plans')
end end
it 'displays subscription table', :js do
expect(page).to have_selector('.js-subscription-table')
end
it_behaves_like 'non-upgradable plan' it_behaves_like 'non-upgradable plan'
it_behaves_like 'used seats rendering for non paid subscriptions' it_behaves_like 'used seats rendering for non paid subscriptions'
it_behaves_like 'plan with subscription table'
end end
end end
end end
context 'on sub-group' do
let(:group) { create(:group_with_plan, plan: :bronze_plan) }
let(:plan) { bronze_plan }
let(:namespace) { group }
let!(:group_member) { create(:group_member, :owner, group: group, user: user) }
let(:subgroup1) { create(:group, parent: group) }
let!(:subgroup1_member) { create(:group_member, :owner, group: subgroup1) }
let(:subgroup2) { create(:group, parent: subgroup1) }
let!(:subgroup2_member) { create(:group_member, :owner, group: subgroup2) }
let(:page_path) { group_billings_path(subgroup2) }
before do
visit page_path
end
it 'displays plan header' do
page.within('.billing-plan-header') do
expect(page).to have_content("#{subgroup2.full_name} is currently using the Bronze Plan")
expect(page).to have_css('.billing-plan-logo .identicon')
expect(page.find('.btn-success')).to have_content('Manage plan')
end
expect(page).not_to have_css('.billing-plans')
end
end
context 'with unexpected JSON' do context 'with unexpected JSON' do
let(:plan) { free_plan } let(:plan) { free_plan }
...@@ -509,46 +516,4 @@ RSpec.describe 'Billing plan pages', :feature do ...@@ -509,46 +516,4 @@ RSpec.describe 'Billing plan pages', :feature do
end end
end end
end end
context 'when ff purchase_deprecated_plans is enabled' do
before do
stub_feature_flags(hide_deprecated_billing_plans: true)
end
context 'when deprecated plan is active' do
let(:plan) { bronze_plan }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
let(:expected_card_header) { "#{plans_data[1][:name]} (Legacy)" }
it 'renders the plan card marked as Legacy' do
visit profile_billings_path
page.within('.billing-plans') do
panels = page.all('.card')
expect(panels.length).to eq(plans_data.length)
panel_with_legacy_plan = panels[1] # free [0], bronze [1]
expect(panel_with_legacy_plan.find('.card-header')).to have_content(expected_card_header)
expect(panel_with_legacy_plan.find('.card-body')).to have_link('frequently asked questions')
end
end
end
context 'when deprecated plan is inactive' do
let(:plan) { free_plan }
it 'does not render the card for that plan' do
visit profile_billings_path
page.within('.billing-plans') do
panels = page.all('.card')
expect(panels.length).to eq(plans_data.length - 1)
end
end
end
end
end end
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module SubscriptionPortalHelpers module SubscriptionPortalHelpers
include StubRequests include StubRequests
def stub_eoa_eligibility_request(namespace_id) def stub_eoa_eligibility_request(namespace_id, eligible = false, free_upgrade_plan_id = nil, assisted_upgrade_plan_id = nil)
stub_full_request("#{EE::SUBSCRIPTIONS_URL}/graphql", method: :post) stub_full_request("#{EE::SUBSCRIPTIONS_URL}/graphql", method: :post)
.with( .with(
body: "{\"query\":\"{\\n subscription(namespaceId: \\\"#{namespace_id}\\\") {\\n eoaStarterBronzeEligible\\n assistedUpgradePlanId\\n freeUpgradePlanId\\n }\\n}\\n\"}", body: "{\"query\":\"{\\n subscription(namespaceId: \\\"#{namespace_id}\\\") {\\n eoaStarterBronzeEligible\\n assistedUpgradePlanId\\n freeUpgradePlanId\\n }\\n}\\n\"}",
...@@ -17,7 +17,7 @@ module SubscriptionPortalHelpers ...@@ -17,7 +17,7 @@ module SubscriptionPortalHelpers
.to_return( .to_return(
status: 200, status: 200,
headers: { 'Content-Type' => 'application/json' }, headers: { 'Content-Type' => 'application/json' },
body: stubbed_eoa_eligibility_response_body body: stubbed_eoa_eligibility_response_body(eligible, free_upgrade_plan_id, assisted_upgrade_plan_id)
) )
end end
...@@ -41,13 +41,13 @@ module SubscriptionPortalHelpers ...@@ -41,13 +41,13 @@ module SubscriptionPortalHelpers
private private
def stubbed_eoa_eligibility_response_body def stubbed_eoa_eligibility_response_body(eligible, free_upgrade_plan_id, assisted_upgrade_plan_id)
{ {
"data": { "data": {
"subscription": { "subscription": {
"eoaStarterBronzeEligible": false, "eoaStarterBronzeEligible": eligible,
"assistedUpgradePlanId": nil, "assistedUpgradePlanId": free_upgrade_plan_id,
"freeUpgradePlanId": nil "freeUpgradePlanId": assisted_upgrade_plan_id
} }
} }
}.to_json }.to_json
......
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