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 @@
require 'spec_helper'
RSpec.describe Groups::BillingsController do
let(:user) { create(:user) }
let(:group) { create(:group, :private) }
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group, :private) }
describe 'GET index' do
before do
sign_in(user)
stub_application_setting(check_namespace_plan: true)
allow(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?) { true }
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
before do
group.add_owner(user)
sign_in(user)
add_group_owner
allow_next_instance_of(FetchSubscriptionPlansService) do |instance|
allow(instance).to receive(:execute)
end
end
it 'renders index with 200 status code' do
allow_any_instance_of(FetchSubscriptionPlansService).to receive(:execute)
get :index, params: { group_id: group }
get_index
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index)
is_expected.to have_gitlab_http_status(:ok)
is_expected.to render_template(:index)
end
it 'fetches subscription plans data from customers.gitlab.com' do
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)
end
......@@ -40,21 +53,19 @@ RSpec.describe Groups::BillingsController do
context 'unauthorized' do
it 'renders 404 when user is not an owner' do
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
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 }
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
......
......@@ -3,24 +3,29 @@
require 'spec_helper'
RSpec.describe Profiles::BillingsController do
let(:user) { create(:user) }
let_it_be(:user) { create(:user) }
describe 'GET #index' do
before do
sign_in(user)
stub_application_setting(check_namespace_plan: true)
allow(Gitlab).to receive(:com?) { true }
end
it 'renders index with 200 status code' do
allow_next_instance_of(FetchSubscriptionPlansService) do |instance|
allow(instance).to receive(:execute)
end
sign_in(user)
end
def 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)
expect(response).to render_template(:index)
is_expected.to have_gitlab_http_status(:ok)
is_expected.to render_template(:index)
end
it 'fetch subscription plans data from customers.gitlab.com' do
......@@ -28,9 +33,8 @@ RSpec.describe Profiles::BillingsController do
expect_next_instance_of(FetchSubscriptionPlansService) do |instance|
expect(instance).to receive(:execute).and_return(data)
end
sign_in(user)
get :index
get_index
expect(assigns(:plans_data)).to eq(data)
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