diff options
Diffstat (limited to 'spec/finders/deploy_keys/deploy_keys_finder_spec.rb')
-rw-r--r-- | spec/finders/deploy_keys/deploy_keys_finder_spec.rb | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/spec/finders/deploy_keys/deploy_keys_finder_spec.rb b/spec/finders/deploy_keys/deploy_keys_finder_spec.rb new file mode 100644 index 00000000000..f0d3935cc95 --- /dev/null +++ b/spec/finders/deploy_keys/deploy_keys_finder_spec.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe DeployKeys::DeployKeysFinder, feature_category: :continuous_delivery do + describe '#execute' do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository) } + + let_it_be(:accessible_project) { create(:project, :internal).tap { |p| p.add_developer(user) } } + let_it_be(:inaccessible_project) { create(:project, :internal) } + let_it_be(:project_private) { create(:project, :private) } + + let_it_be(:deploy_key_for_target_project) do + create(:deploy_keys_project, project: project, deploy_key: create(:deploy_key)) + end + + let_it_be(:deploy_key_for_accessible_project) do + create(:deploy_keys_project, project: accessible_project, deploy_key: create(:deploy_key)) + end + + let_it_be(:deploy_key_for_inaccessible_project) do + create(:deploy_keys_project, project: inaccessible_project, deploy_key: create(:deploy_key)) + end + + let_it_be(:deploy_keys_project_private) do + create(:deploy_keys_project, project: project_private, deploy_key: create(:another_deploy_key)) + end + + let_it_be(:deploy_key_public) { create(:deploy_key, public: true) } + + let(:params) { {} } + + subject(:result) { described_class.new(project, user, params).execute } + + context 'with access' do + before_all do + project.add_maintainer(user) + end + + context 'when filtering for enabled_keys' do + let(:params) { { filter: :enabled_keys } } + + it 'returns the correct result' do + expect(result.map(&:id)).to match_array([deploy_key_for_target_project.deploy_key_id]) + end + end + + context 'when filtering for available project keys' do + let(:params) { { filter: :available_project_keys } } + + it 'returns the correct result' do + expect(result.map(&:id)).to match_array([deploy_key_for_accessible_project.deploy_key_id]) + end + end + + context 'when filtering for available public keys' do + let(:params) { { filter: :available_public_keys } } + + it 'returns the correct result' do + expect(result.map(&:id)).to match_array([deploy_key_public.id]) + end + end + + context 'when there are no set filters' do + it 'returns an empty collection' do + expect(result).to eq DeployKey.none + end + end + end + + context 'without access' do + it 'returns an empty collection' do + expect(result).to eq DeployKey.none + end + end + end +end |