diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-26 00:08:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-26 00:08:43 +0300 |
commit | 3e2ef953d9a22cb3139e7b395a1173604c563007 (patch) | |
tree | 3e22e05affc55017866fca8ff1269b777c52595c /spec/graphql | |
parent | 35487a1e925f7b4ec72a3d0cdde94f92582d2087 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql')
-rw-r--r-- | spec/graphql/resolvers/boards_resolver_spec.rb | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/graphql/resolvers/boards_resolver_spec.rb b/spec/graphql/resolvers/boards_resolver_spec.rb new file mode 100644 index 00000000000..ab77dfa8fc3 --- /dev/null +++ b/spec/graphql/resolvers/boards_resolver_spec.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Resolvers::BoardsResolver do + include GraphqlHelpers + + let_it_be(:user) { create(:user) } + + shared_examples_for 'group and project boards resolver' do + it 'does not create a default board' do + expect(resolve_boards).to eq [] + end + + it 'calls Boards::ListService' do + expect_next_instance_of(Boards::ListService) do |service| + expect(service).to receive(:execute) + end + + resolve_boards + end + + it 'avoids N+1 queries' do + control = ActiveRecord::QueryRecorder.new { resolve_boards(args: {}) } + + create(:milestone, "#{board_parent.class.name.underscore}": board_parent) + create(:board, resource_parent: board_parent) + + expect { resolve_boards(args: {}) }.not_to exceed_query_limit(control) + end + + describe 'multiple_issue_boards_available?' do + let!(:board2) { create(:board, name: 'Two', resource_parent: board_parent) } + let!(:board1) { create(:board, name: 'One', resource_parent: board_parent) } + + it 'returns multiple boards' do + allow(board_parent).to receive(:multiple_issue_boards_available?).and_return(true) + + expect(resolve_boards).to eq [board1, board2] + end + + it 'returns only the first boards' do + allow(board_parent).to receive(:multiple_issue_boards_available?).and_return(false) + + expect(resolve_boards).to eq [board1] + end + end + end + + describe '#resolve' do + context 'when there is no parent' do + let(:board_parent) { nil } + + it 'returns none if parent is nil' do + expect(resolve_boards).to eq(Board.none) + end + end + + context 'when project boards' do + let(:board_parent) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) } + + it_behaves_like 'group and project boards resolver' + end + + context 'when group boards' do + let(:board_parent) { create(:group) } + + it_behaves_like 'group and project boards resolver' + end + end + + def resolve_boards(args: {}) + resolve(described_class, obj: board_parent, args: args, ctx: { current_user: user }) + end +end |