Commit a930271b authored by Thong Kuah's avatar Thong Kuah

Merge branch 'vslobodin/shared-examples-for-billing-plans-spec' into 'master'

Introduce shared examples for billing plans specs

Closes #31936

See merge request gitlab-org/gitlab!18445
parents 3d7c9f11 b9a10eea
......@@ -9,6 +9,7 @@ describe 'Billing plan pages', :feature do
let(:namespace) { user.namespace }
let(:free_plan) { create(:free_plan) }
let(:bronze_plan) { create(:bronze_plan) }
let(:silver_plan) { create(:silver_plan) }
let(:gold_plan) { create(:gold_plan) }
let(:plans_data) do
JSON.parse(File.read(Rails.root.join('ee/spec/fixtures/gitlab_com_plans.json'))).map do |data|
......@@ -17,7 +18,7 @@ describe 'Billing plan pages', :feature do
end
before do
stub_full_request("#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?plan=#{plan}")
stub_full_request("#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?plan=#{plan.name}")
.to_return(status: 200, body: plans_data.to_json)
stub_application_setting(check_namespace_plan: true)
allow(Gitlab).to receive(:com?) { true }
......@@ -30,13 +31,64 @@ describe 'Billing plan pages', :feature do
end
end
shared_examples 'upgradable plan' do
before do
visit page_path
end
it 'displays the upgrade link' do
page.within('.content') do
expect(page).to have_link('Upgrade', href: external_upgrade_url(namespace, plan))
end
end
end
shared_examples 'non-upgradable plan' do
before do
visit page_path
end
it 'does not display the upgrade link' do
page.within('.content') do
expect(page).not_to have_link('Upgrade', href: external_upgrade_url(namespace, plan))
end
end
end
shared_examples 'downgradable plan' do
before do
visit page_path
end
it 'displays the downgrade link' do
page.within('.content') do
expect(page).to have_content('downgrade your plan')
expect(page).to have_link('Customer Support', href: EE::CUSTOMER_SUPPORT_URL)
end
end
end
shared_examples 'plan with header' do
before do
visit page_path
end
it 'displays header' do
page.within('.billing-plan-header') do
expect(page).to have_content("#{user.username} you are currently using the #{plan.name.titleize} plan.")
expect(page).to have_css('.billing-plan-logo img')
end
end
end
context 'users profile billing page' do
let(:page_path) { profile_billings_path }
it_behaves_like 'billings gold trial callout'
context 'on free' do
let(:plan) { free_plan.name }
let(:plan) { free_plan }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: nil, seats: 15)
......@@ -81,55 +133,40 @@ describe 'Billing plan pages', :feature do
end
end
context 'on bronze' do
let(:plan) { bronze_plan.name }
context 'on bronze plan' do
let(:plan) { bronze_plan }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: bronze_plan, seats: 15)
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
before do
visit page_path
end
it 'displays header and actions' do
page.within('.billing-plan-header') do
expect(page).to have_content("#{user.username} you are currently using the Bronze plan.")
expect(page).to have_css('.billing-plan-logo img')
end
page.within('.content') do
expect(page).to have_link('Upgrade', href: external_upgrade_url(namespace, bronze_plan))
expect(page).to have_content('downgrade your plan')
expect(page).to have_link('Customer Support', href: EE::CUSTOMER_SUPPORT_URL)
end
end
it_behaves_like 'plan with header'
it_behaves_like 'downgradable plan'
it_behaves_like 'upgradable plan'
end
context 'on gold' do
let(:plan) { gold_plan.name }
context 'on silver plan' do
let(:plan) { silver_plan }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: gold_plan, seats: 15)
end
before do
visit page_path
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
it 'displays header and actions' do
page.within('.billing-plan-header') do
expect(page).to have_content("#{user.username} you are currently using the Gold plan.")
it_behaves_like 'plan with header'
it_behaves_like 'downgradable plan'
it_behaves_like 'upgradable plan'
end
expect(page).to have_css('.billing-plan-logo img')
end
context 'on gold plan' do
let(:plan) { gold_plan }
page.within('.content') do
expect(page).to have_content('downgrade your plan')
expect(page).to have_link('Customer Support', href: EE::CUSTOMER_SUPPORT_URL)
end
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
it_behaves_like 'plan with header'
it_behaves_like 'downgradable plan'
it_behaves_like 'non-upgradable plan'
end
end
......@@ -143,10 +180,10 @@ describe 'Billing plan pages', :feature do
it_behaves_like 'billings gold trial callout'
context 'on bronze' do
let(:plan) { bronze_plan.name }
let(:plan) { bronze_plan }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: bronze_plan, seats: 15)
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
before do
......@@ -187,10 +224,10 @@ describe 'Billing plan pages', :feature do
it_behaves_like 'billings gold trial callout'
context 'on bronze' do
let(:plan) { bronze_plan.name }
let(:plan) { bronze_plan }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: bronze_plan, seats: 15)
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
before do
......@@ -210,7 +247,7 @@ describe 'Billing plan pages', :feature do
end
context 'with unexpected JSON' do
let(:plan) { 'free' }
let(:plan) { free_plan }
let(:plans_data) do
[
......
......@@ -60,7 +60,7 @@ end
shared_examples 'billings gold trial callout' do
context 'on a free plan' do
let(:plan) { 'free' }
let(:plan) { free_plan }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: nil, seats: 15)
......@@ -82,7 +82,7 @@ shared_examples 'billings gold trial callout' do
where(case_names: ->(plan_type) {"like #{plan_type}"}, plan_type: [:bronze, :silver])
with_them do
let(:plan) { plan_type }
let(:plan) { plans[plan_type] }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: plans[plan_type], seats: 15)
......@@ -103,10 +103,10 @@ shared_examples 'billings gold trial callout' do
end
context 'on a gold plan' do
let(:plan) { gold_plan.name }
let(:plan) { gold_plan }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: gold_plan, seats: 15)
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
before 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