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/support/shared_examples/requests/api/graphql/ci/sorted_paginated_variables_shared_examples.rb')
-rw-r--r--spec/support/shared_examples/requests/api/graphql/ci/sorted_paginated_variables_shared_examples.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/support/shared_examples/requests/api/graphql/ci/sorted_paginated_variables_shared_examples.rb b/spec/support/shared_examples/requests/api/graphql/ci/sorted_paginated_variables_shared_examples.rb
new file mode 100644
index 00000000000..306310c9e9c
--- /dev/null
+++ b/spec/support/shared_examples/requests/api/graphql/ci/sorted_paginated_variables_shared_examples.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+# Requires `current_user`, `data_path`, `variables`, and `pagination_query(params)` bindings
+RSpec.shared_examples 'sorted paginated variables' do
+ subject(:expected_ordered_variables) { ordered_variables.map { |var| var.to_global_id.to_s } }
+
+ context 'when sorted by key ascending' do
+ let(:ordered_variables) { variables.sort_by(&:key) }
+
+ it_behaves_like 'sorted paginated query' do
+ let(:sort_param) { :KEY_ASC }
+ let(:first_param) { 2 }
+ let(:all_records) { expected_ordered_variables }
+ end
+ end
+
+ context 'when sorted by key descending' do
+ let(:ordered_variables) { variables.sort_by(&:key).reverse }
+
+ it_behaves_like 'sorted paginated query' do
+ let(:sort_param) { :KEY_DESC }
+ let(:first_param) { 2 }
+ let(:all_records) { expected_ordered_variables }
+ end
+ end
+end