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