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 ...@@ -44,7 +44,7 @@ module Clusters
end end
def management_project_scope(cluster) def management_project_scope(cluster)
return Project.all if cluster.instance_type? return ::Project.all if cluster.instance_type?
group = group =
if cluster.group_type? if cluster.group_type?
......
...@@ -92,8 +92,6 @@ describe Clusters::UpdateService do ...@@ -92,8 +92,6 @@ describe Clusters::UpdateService do
end end
context 'when params includes :management_project_id' do 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 context 'management_project is non-existent' do
let(:params) do let(:params) do
{ management_project_id: 0 } { management_project_id: 0 }
...@@ -109,19 +107,42 @@ describe Clusters::UpdateService do ...@@ -109,19 +107,42 @@ describe Clusters::UpdateService do
end end
end end
context 'user is authorized to adminster manangement_project' do shared_examples 'setting a management project' do
before do context 'user is authorized to adminster manangement_project' do
management_project.add_maintainer(cluster.user) before do
end management_project.add_maintainer(cluster.user)
end
let(:params) do let(:params) do
{ management_project_id: management_project.id } { 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 end
it 'updates management_project_id' do context 'user is not authorized to adminster manangement_project' do
is_expected.to eq(true) 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 end
context 'manangement_project is outside of the namespace scope' do context 'manangement_project is outside of the namespace scope' do
...@@ -129,6 +150,10 @@ describe Clusters::UpdateService do ...@@ -129,6 +150,10 @@ describe Clusters::UpdateService do
management_project.update(group: create(:group)) management_project.update(group: create(:group))
end end
let(:params) do
{ management_project_id: management_project.id }
end
it 'does not update management_project_id' do it 'does not update management_project_id' do
is_expected.to eq(false) is_expected.to eq(false)
...@@ -140,18 +165,38 @@ describe Clusters::UpdateService do ...@@ -140,18 +165,38 @@ describe Clusters::UpdateService do
end end
end end
context 'user is not authorized to adminster manangement_project' do context 'group cluster' do
let(:params) do let(:cluster) { create(:cluster, :group) }
{ management_project_id: management_project.id }
include_examples 'setting a management project' do
let(:management_project) { create(:project, group: cluster.first_group) }
end end
it 'does not update management_project_id' do context 'manangement_project is outside of the namespace scope' do
is_expected.to eq(false) 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 it 'does not update management_project_id' do
expect(cluster.management_project_id).to be_nil 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 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