Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/finders/ci/group_variables_finder_spec.rb')
-rw-r--r--spec/finders/ci/group_variables_finder_spec.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/spec/finders/ci/group_variables_finder_spec.rb b/spec/finders/ci/group_variables_finder_spec.rb
new file mode 100644
index 00000000000..9c5d83d7262
--- /dev/null
+++ b/spec/finders/ci/group_variables_finder_spec.rb
@@ -0,0 +1,73 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::GroupVariablesFinder, feature_category: :secrets_management do
+ subject(:finder) { described_class.new(project, sort_key).execute }
+
+ let_it_be(:user) { create(:user) }
+ let_it_be(:group) { create(:group) }
+ let_it_be(:subgroup) { create(:group, parent: group) }
+ let_it_be(:project_with_subgroup) { create(:project, group: subgroup) }
+ let_it_be(:project_without_group) { create(:project) }
+ let_it_be(:variable1) { create(:ci_group_variable, group: group, key: 'GROUP_VAR_A', created_at: 1.day.ago) }
+ let_it_be(:variable2) { create(:ci_group_variable, group: subgroup, key: 'SUBGROUP_VAR_B') }
+
+ let_it_be(:inherited_ci_variables) do
+ [variable1, variable2]
+ end
+
+ let(:sort_key) { nil }
+
+ context 'when project does not have a group' do
+ let_it_be(:project) { project_without_group }
+
+ it 'returns an empty array' do
+ expect(finder.to_a).to match_array([])
+ end
+ end
+
+ context 'when project belongs to a group' do
+ let_it_be(:project) { project_with_subgroup }
+
+ it 'returns variable from parent group and ancestors' do
+ expect(finder.to_a).to match_array([variable1, variable2])
+ end
+ end
+
+ describe 'sorting behaviour' do
+ let_it_be(:project) { project_with_subgroup }
+
+ context 'with sort by created_at descending' do
+ let(:sort_key) { :created_desc }
+
+ it 'returns variables ordered by created_at in descending order' do
+ expect(finder.to_a).to eq([variable2, variable1])
+ end
+ end
+
+ context 'with sort by created_at ascending' do
+ let(:sort_key) { :created_asc }
+
+ it 'returns variables ordered by created_at in ascending order' do
+ expect(finder.to_a).to eq([variable1, variable2])
+ end
+ end
+
+ context 'with sort by key descending' do
+ let(:sort_key) { :key_desc }
+
+ it 'returns variables ordered by key in descending order' do
+ expect(finder.to_a).to eq([variable2, variable1])
+ end
+ end
+
+ context 'with sort by key ascending' do
+ let(:sort_key) { :key_asc }
+
+ it 'returns variables ordered by key in ascending order' do
+ expect(finder.to_a).to eq([variable1, variable2])
+ end
+ end
+ end
+end