2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-09-13 09:26:31 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-02-14 04:08:43 -05:00
|
|
|
describe DeploymentClusterEntity do
|
2019-09-13 09:26:31 -04:00
|
|
|
describe '#as_json' do
|
2020-02-14 04:08:43 -05:00
|
|
|
subject { described_class.new(deployment, request: request).as_json }
|
2019-10-18 07:11:44 -04:00
|
|
|
|
2019-09-13 09:26:31 -04:00
|
|
|
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-02-14 04:08:43 -05:00
|
|
|
let(:deployment) { create(:deployment, cluster: cluster) }
|
|
|
|
let!(:deployment_cluster) { create(:deployment_cluster, cluster: cluster, deployment: deployment) }
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_maintainer(maintainer)
|
|
|
|
project.add_developer(developer)
|
|
|
|
end
|
|
|
|
|
2020-02-14 04:08:43 -05:00
|
|
|
it 'matches deployment_cluster entity schema' do
|
|
|
|
expect(subject.as_json).to match_schema('deployment_cluster')
|
2019-09-13 09:26:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes the cluster details' do
|
|
|
|
expect(subject[:name]).to eq('the-cluster')
|
2019-12-03 04:09:09 -05:00
|
|
|
expect(subject[:path]).to eq("/#{project.full_path}/-/clusters/#{cluster.id}")
|
2020-02-14 04:08:43 -05:00
|
|
|
expect(subject[:kubernetes_namespace]).to eq(deployment_cluster.kubernetes_namespace)
|
2019-09-13 09:26:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user does not have permission to view the cluster' do
|
|
|
|
let(:current_user) { developer }
|
|
|
|
|
2020-02-14 04:08:43 -05:00
|
|
|
it 'does not include the path nor the namespace' do
|
2019-09-13 09:26:31 -04:00
|
|
|
expect(subject[:path]).to be_nil
|
2020-02-14 04:08:43 -05:00
|
|
|
expect(subject[:kubernetes_namespace]).to be_nil
|
2019-09-13 09:26:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|