debian-mirror-gitlab/spec/serializers/deployment_cluster_entity_spec.rb

43 lines
1.4 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe DeploymentClusterEntity do
2019-12-04 20:38:33 +05:30
describe '#as_json' do
2020-03-13 15:44:24 +05:30
subject { described_class.new(deployment, request: request).as_json }
2019-12-21 20:55:43 +05:30
2019-12-04 20:38:33 +05:30
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]) }
2020-03-13 15:44:24 +05:30
let(:deployment) { create(:deployment, cluster: cluster) }
let!(:deployment_cluster) { create(:deployment_cluster, cluster: cluster, deployment: deployment) }
2019-12-04 20:38:33 +05:30
before do
project.add_maintainer(maintainer)
project.add_developer(developer)
end
2020-03-13 15:44:24 +05:30
it 'matches deployment_cluster entity schema' do
expect(subject.as_json).to match_schema('deployment_cluster')
2019-12-04 20:38:33 +05:30
end
it 'exposes the cluster details' do
expect(subject[:name]).to eq('the-cluster')
2020-01-01 13:55:28 +05:30
expect(subject[:path]).to eq("/#{project.full_path}/-/clusters/#{cluster.id}")
2020-03-13 15:44:24 +05:30
expect(subject[:kubernetes_namespace]).to eq(deployment_cluster.kubernetes_namespace)
2019-12-04 20:38:33 +05:30
end
context 'when the user does not have permission to view the cluster' do
let(:current_user) { developer }
2020-03-13 15:44:24 +05:30
it 'does not include the path nor the namespace' do
2019-12-04 20:38:33 +05:30
expect(subject[:path]).to be_nil
2020-03-13 15:44:24 +05:30
expect(subject[:kubernetes_namespace]).to be_nil
2019-12-04 20:38:33 +05:30
end
end
end
end