Commit 7b051af7 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '333551-refactor-billing-plan-specs' into 'master'

Refactor billing plan stubbing for connection errors

See merge request gitlab-org/gitlab!64173
parents 5dea2af8 faad977e
...@@ -296,8 +296,7 @@ RSpec.describe 'Billing plan pages', :feature, :js do ...@@ -296,8 +296,7 @@ RSpec.describe 'Billing plan pages', :feature, :js do
let!(:subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan: plan) } let!(:subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan: plan) }
before do before do
stub_full_request("#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?plan=#{plan.name}&namespace_id=#{namespace.id}") stub_billing_plans(namespace.id, plan.name, raise_error: 'Connection refused')
.to_raise("Connection refused")
end end
it 'renders an error page' do it 'renders an error page' do
......
...@@ -114,9 +114,7 @@ RSpec.describe 'Groups > Billing', :js do ...@@ -114,9 +114,7 @@ RSpec.describe 'Groups > Billing', :js do
context 'when CustomersDot is unavailable' do context 'when CustomersDot is unavailable' do
before do before do
stub_full_request("#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?plan=#{plan}&namespace_id=#{group.id}") stub_billing_plans(group.id, plan, raise_error: 'Connection refused')
.with(headers: { 'Accept' => 'application/json' })
.to_raise("Connection refused")
end end
let(:plan) { 'bronze' } let(:plan) { 'bronze' }
......
...@@ -27,10 +27,14 @@ module SubscriptionPortalHelpers ...@@ -27,10 +27,14 @@ module SubscriptionPortalHelpers
end end
end end
def stub_billing_plans(namespace_id, plan = 'free', plans_data = nil) def stub_billing_plans(namespace_id, plan = 'free', plans_data = nil, raise_error: nil)
stub_full_request("#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?namespace_id=#{namespace_id}&plan=#{plan}") stub = stub_full_request("#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?namespace_id=#{namespace_id}&plan=#{plan}")
.with(headers: { 'Accept' => 'application/json' }) .with(headers: { 'Accept' => 'application/json' })
.to_return(status: 200, body: plans_data || plans_fixture) if raise_error
stub.to_raise(raise_error)
else
stub.to_return(status: 200, body: plans_data || plans_fixture)
end
end end
private private
......
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