diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 12:08:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 12:08:43 +0300 |
commit | 733befe96ad19f5a02e442c4a9cc8059d3aabbda (patch) | |
tree | dcabd344df040e536a242edc4e3121fb3efca142 /spec/serializers/deployment_cluster_entity_spec.rb | |
parent | 10213bf3b26c3c21f7683471d35d1cd052c41e9c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/serializers/deployment_cluster_entity_spec.rb')
-rw-r--r-- | spec/serializers/deployment_cluster_entity_spec.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/serializers/deployment_cluster_entity_spec.rb b/spec/serializers/deployment_cluster_entity_spec.rb new file mode 100644 index 00000000000..b22a93fcec7 --- /dev/null +++ b/spec/serializers/deployment_cluster_entity_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe DeploymentClusterEntity do + describe '#as_json' do + subject { described_class.new(deployment, request: request).as_json } + + let(:maintainer) { create(:user) } + let(:developer) { create(:user) } + let(:current_user) { maintainer } + let(:request) { double(:request, current_user: current_user) } + let(:project) { create(:project) } + let(:cluster) { create(:cluster, name: 'the-cluster', projects: [project]) } + let(:deployment) { create(:deployment, cluster: cluster) } + let!(:deployment_cluster) { create(:deployment_cluster, cluster: cluster, deployment: deployment) } + + before do + project.add_maintainer(maintainer) + project.add_developer(developer) + end + + it 'matches deployment_cluster entity schema' do + expect(subject.as_json).to match_schema('deployment_cluster') + end + + it 'exposes the cluster details' do + expect(subject[:name]).to eq('the-cluster') + expect(subject[:path]).to eq("/#{project.full_path}/-/clusters/#{cluster.id}") + expect(subject[:kubernetes_namespace]).to eq(deployment_cluster.kubernetes_namespace) + end + + context 'when the user does not have permission to view the cluster' do + let(:current_user) { developer } + + it 'does not include the path nor the namespace' do + expect(subject[:path]).to be_nil + expect(subject[:kubernetes_namespace]).to be_nil + end + end + end +end |