Commit 1fed39f6 authored by Thong Kuah's avatar Thong Kuah

Add test for instance clusters

Fixed a bug uncovered where we need to refer to top-level `::Project`
constant.
parent 5b5f40f1
......@@ -44,7 +44,7 @@ module Clusters
end
def management_project_scope(cluster)
return Project.all if cluster.instance_type?
return ::Project.all if cluster.instance_type?
group =
if cluster.group_type?
......
......@@ -92,8 +92,6 @@ describe Clusters::UpdateService do
end
context 'when params includes :management_project_id' do
let(:management_project) { create(:project, namespace: cluster.first_project.namespace) }
context 'management_project is non-existent' do
let(:params) do
{ management_project_id: 0 }
......@@ -109,19 +107,42 @@ describe Clusters::UpdateService do
end
end
context 'user is authorized to adminster manangement_project' do
before do
management_project.add_maintainer(cluster.user)
end
shared_examples 'setting a management project' do
context 'user is authorized to adminster manangement_project' do
before do
management_project.add_maintainer(cluster.user)
end
let(:params) do
{ management_project_id: management_project.id }
let(:params) do
{ management_project_id: management_project.id }
end
it 'updates management_project_id' do
is_expected.to eq(true)
expect(cluster.management_project).to eq(management_project)
end
end
it 'updates management_project_id' do
is_expected.to eq(true)
context 'user is not authorized to adminster manangement_project' do
let(:params) do
{ management_project_id: management_project.id }
end
expect(cluster.management_project).to eq(management_project)
it 'does not update management_project_id' do
is_expected.to eq(false)
expect(cluster.errors[:management_project_id]).to include('Project does not exist or you don\'t have permission to perform this action')
cluster.reload
expect(cluster.management_project_id).to be_nil
end
end
end
context 'project cluster' do
include_examples 'setting a management project' do
let(:management_project) { create(:project, namespace: cluster.first_project.namespace) }
end
context 'manangement_project is outside of the namespace scope' do
......@@ -129,6 +150,10 @@ describe Clusters::UpdateService do
management_project.update(group: create(:group))
end
let(:params) do
{ management_project_id: management_project.id }
end
it 'does not update management_project_id' do
is_expected.to eq(false)
......@@ -140,18 +165,38 @@ describe Clusters::UpdateService do
end
end
context 'user is not authorized to adminster manangement_project' do
let(:params) do
{ management_project_id: management_project.id }
context 'group cluster' do
let(:cluster) { create(:cluster, :group) }
include_examples 'setting a management project' do
let(:management_project) { create(:project, group: cluster.first_group) }
end
it 'does not update management_project_id' do
is_expected.to eq(false)
context 'manangement_project is outside of the namespace scope' do
before do
management_project.update(group: create(:group))
end
expect(cluster.errors[:management_project_id]).to include('Project does not exist or you don\'t have permission to perform this action')
let(:params) do
{ management_project_id: management_project.id }
end
cluster.reload
expect(cluster.management_project_id).to be_nil
it 'does not update management_project_id' do
is_expected.to eq(false)
expect(cluster.errors[:management_project_id]).to include('Project does not exist or you don\'t have permission to perform this action')
cluster.reload
expect(cluster.management_project_id).to be_nil
end
end
end
context 'instance cluster' do
let(:cluster) { create(:cluster, :instance) }
include_examples 'setting a management project' do
let(:management_project) { create(:project) }
end
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