Commit bd5f2983 authored by Matija Čupić's avatar Matija Čupić Committed by Kamil Trzcinski

Add tests for EE logic in Clusters::CreateService

parent 5c1cba17
...@@ -29,7 +29,9 @@ module Clusters ...@@ -29,7 +29,9 @@ module Clusters
end end
def can_create_cluster? def can_create_cluster?
project.clusters.empty? return true if project.clusters.empty?
project.feature_available?(:multiple_clusters)
end end
end end
end end
...@@ -82,12 +82,41 @@ describe Clusters::CreateService do ...@@ -82,12 +82,41 @@ describe Clusters::CreateService do
end end
context 'when project has a cluster' do context 'when project has a cluster' do
include_context 'valid params'
let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) } let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
it 'does not create a cluster' do before do
expect(ClusterProvisionWorker).not_to receive(:perform_async) allow(project).to receive(:feature_available?).and_call_original
expect { subject }.to raise_error(ArgumentError).and change { Clusters::Cluster.count }.by(0) end
context 'when license has multiple clusters feature' do
before do
allow(project).to receive(:feature_available?).with(:multiple_clusters).and_return(true)
end
context 'when correct params' do
include_context 'valid params'
include_examples 'create cluster'
end
context 'when invalid params' do
include_context 'invalid params'
include_examples 'error'
end
end
context 'when license does not have multiple clusters feature' do
include_context 'valid params'
before do
allow(project).to receive(:feature_available?).with(:multiple_clusters).and_return(false)
end
it 'does not create a cluster' do
expect(ClusterProvisionWorker).not_to receive(:perform_async)
expect { subject }.to raise_error(ArgumentError).and change { Clusters::Cluster.count }.by(0)
end
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