Commit f407d692 authored by Markus Koller's avatar Markus Koller

Merge branch 'update-billings-controller-specs' into 'master'

Update groups & profiles billings_controller_specs

See merge request gitlab-org/gitlab!38872
parents ed27c18e 4db39c81
---
title: Update {groups,profiles}/billings_controller_spec.rb files
merge_request: 38872
author:
type: changed
...@@ -3,35 +3,48 @@ ...@@ -3,35 +3,48 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Groups::BillingsController do RSpec.describe Groups::BillingsController do
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:group) { create(:group, :private) } let_it_be(:group) { create(:group, :private) }
describe 'GET index' do describe 'GET index' do
before do before do
sign_in(user)
stub_application_setting(check_namespace_plan: true) stub_application_setting(check_namespace_plan: true)
allow(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?) { true } allow(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?) { true }
end end
def get_index
get :index, params: { group_id: group }
end
def add_group_owner
group.add_owner(user)
end
subject { response }
context 'authorized' do context 'authorized' do
before do before do
group.add_owner(user) add_group_owner
sign_in(user) allow_next_instance_of(FetchSubscriptionPlansService) do |instance|
allow(instance).to receive(:execute)
end
end end
it 'renders index with 200 status code' do it 'renders index with 200 status code' do
allow_any_instance_of(FetchSubscriptionPlansService).to receive(:execute) get_index
get :index, params: { group_id: group }
expect(response).to have_gitlab_http_status(:ok) is_expected.to have_gitlab_http_status(:ok)
expect(response).to render_template(:index) is_expected.to render_template(:index)
end end
it 'fetches subscription plans data from customers.gitlab.com' do it 'fetches subscription plans data from customers.gitlab.com' do
data = double data = double
expect_any_instance_of(FetchSubscriptionPlansService).to receive(:execute).and_return(data) expect_next_instance_of(FetchSubscriptionPlansService) do |instance|
expect(instance).to receive(:execute).and_return(data)
end
get :index, params: { group_id: group } get_index
expect(assigns(:plans_data)).to eq(data) expect(assigns(:plans_data)).to eq(data)
end end
...@@ -40,21 +53,19 @@ RSpec.describe Groups::BillingsController do ...@@ -40,21 +53,19 @@ RSpec.describe Groups::BillingsController do
context 'unauthorized' do context 'unauthorized' do
it 'renders 404 when user is not an owner' do it 'renders 404 when user is not an owner' do
group.add_developer(user) group.add_developer(user)
sign_in(user)
get :index, params: { group_id: group.id } get_index
expect(response).to have_gitlab_http_status(:not_found) is_expected.to have_gitlab_http_status(:not_found)
end end
it 'renders 404 when it is not gitlab.com' do it 'renders 404 when it is not gitlab.com' do
add_group_owner
expect(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).at_least(:once) { false } expect(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).at_least(:once) { false }
group.add_owner(user)
sign_in(user)
get :index, params: { group_id: group } get_index
expect(response).to have_gitlab_http_status(:not_found) is_expected.to have_gitlab_http_status(:not_found)
end end
end end
end end
......
...@@ -3,24 +3,29 @@ ...@@ -3,24 +3,29 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Profiles::BillingsController do RSpec.describe Profiles::BillingsController do
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
describe 'GET #index' do describe 'GET #index' do
before do before do
sign_in(user)
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 }
end
it 'renders index with 200 status code' do
allow_next_instance_of(FetchSubscriptionPlansService) do |instance| allow_next_instance_of(FetchSubscriptionPlansService) do |instance|
allow(instance).to receive(:execute) allow(instance).to receive(:execute)
end end
sign_in(user) end
def get_index
get :index get :index
end
subject { response }
it 'renders index with 200 status code' do
get_index
expect(response).to have_gitlab_http_status(:ok) is_expected.to have_gitlab_http_status(:ok)
expect(response).to render_template(:index) is_expected.to render_template(:index)
end end
it 'fetch subscription plans data from customers.gitlab.com' do it 'fetch subscription plans data from customers.gitlab.com' do
...@@ -28,9 +33,8 @@ RSpec.describe Profiles::BillingsController do ...@@ -28,9 +33,8 @@ RSpec.describe Profiles::BillingsController do
expect_next_instance_of(FetchSubscriptionPlansService) do |instance| expect_next_instance_of(FetchSubscriptionPlansService) do |instance|
expect(instance).to receive(:execute).and_return(data) expect(instance).to receive(:execute).and_return(data)
end end
sign_in(user)
get :index get_index
expect(assigns(:plans_data)).to eq(data) expect(assigns(:plans_data)).to eq(data)
end end
......
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