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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

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) }
2022-04-04 11:22:00 +05:30
let(:reporter) { create(:user) }
2019-12-04 20:38:33 +05:30
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)
2022-04-04 11:22:00 +05:30
project.add_reporter(reporter)
2019-12-04 20:38:33 +05:30
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
2022-04-04 11:22:00 +05:30
let(:current_user) { reporter }
2019-12-04 20:38:33 +05:30
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