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/requests/api/graphql/boards/board_list_query_spec.rb')
-rw-r--r--spec/requests/api/graphql/boards/board_list_query_spec.rb98
1 files changed, 98 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/boards/board_list_query_spec.rb b/spec/requests/api/graphql/boards/board_list_query_spec.rb
new file mode 100644
index 00000000000..dec7ca715f2
--- /dev/null
+++ b/spec/requests/api/graphql/boards/board_list_query_spec.rb
@@ -0,0 +1,98 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'Querying a Board list' do
+ include GraphqlHelpers
+
+ let_it_be(:current_user) { create(:user) }
+ let_it_be(:project) { create(:project) }
+ let_it_be(:board) { create(:board, resource_parent: project) }
+ let_it_be(:label) { create(:label, project: project, name: 'foo') }
+ let_it_be(:list) { create(:list, board: board, label: label) }
+ let_it_be(:issue1) { create(:issue, project: project, labels: [label]) }
+ let_it_be(:issue2) { create(:issue, project: project, labels: [label], assignees: [current_user]) }
+
+ let(:filters) { {} }
+ let(:query) do
+ graphql_query_for(
+ :board_list,
+ { id: list.to_global_id.to_s, issueFilters: filters },
+ %w[title issuesCount]
+ )
+ end
+
+ subject { graphql_data['boardList'] }
+
+ before do
+ post_graphql(query, current_user: current_user)
+ end
+
+ context 'when the user has access to the list' do
+ before_all do
+ project.add_guest(current_user)
+ end
+
+ it_behaves_like 'a working graphql query'
+
+ it { is_expected.to include({ 'issuesCount' => 2, 'title' => list.title }) }
+
+ context 'with matching issue filters' do
+ let(:filters) { { assigneeUsername: current_user.username } }
+
+ it 'filters issues metadata' do
+ is_expected.to include({ 'issuesCount' => 1, 'title' => list.title })
+ end
+ end
+
+ context 'with unmatching issue filters' do
+ let(:filters) { { assigneeUsername: 'foo' } }
+
+ it 'filters issues metadata' do
+ is_expected.to include({ 'issuesCount' => 0, 'title' => list.title })
+ end
+ end
+ end
+
+ context 'when the user does not have access to the list' do
+ it { is_expected.to be_nil }
+ end
+
+ context 'when ID argument is missing' do
+ let(:query) do
+ graphql_query_for('boardList', {}, 'title')
+ end
+
+ it 'raises an exception' do
+ expect(graphql_errors).to include(a_hash_including('message' => "Field 'boardList' is missing required arguments: id"))
+ end
+ end
+
+ context 'when list ID is not found' do
+ let(:query) do
+ graphql_query_for('boardList', { id: "gid://gitlab/List/#{non_existing_record_id}" }, 'title')
+ end
+
+ it { is_expected.to be_nil }
+ end
+
+ it 'does not have an N+1 performance issue' do
+ a, b = create_list(:list, 2, board: board)
+ ctx = { current_user: current_user }
+ project.add_guest(current_user)
+
+ baseline = graphql_query_for(:board_list, { id: global_id_of(a) }, 'title')
+ query = <<~GQL
+ query {
+ a: #{query_graphql_field(:board_list, { id: global_id_of(a) }, 'title')}
+ b: #{query_graphql_field(:board_list, { id: global_id_of(b) }, 'title')}
+ }
+ GQL
+
+ control = ActiveRecord::QueryRecorder.new do
+ run_with_clean_state(baseline, context: ctx)
+ end
+
+ expect { run_with_clean_state(query, context: ctx) }.not_to exceed_query_limit(control)
+ end
+end