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

create_spec.rb « lists « boards « mutations « graphql « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b1fe9911c7b2f22cab6964e45d8d08ccfb2749db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Mutations::Boards::Lists::Create do
  include GraphqlHelpers

  let_it_be(:group) { create(:group, :private) }
  let_it_be(:board) { create(:board, group: group) }
  let_it_be(:user)  { create(:user) }
  let_it_be(:guest) { create(:user) }

  let(:current_user) { user }
  let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) }
  let(:list_create_params) { {} }

  before_all do
    group.add_reporter(user)
    group.add_guest(guest)
  end

  subject { mutation.resolve(board_id: board.to_global_id.to_s, **list_create_params) }

  describe '#ready?' do
    it 'raises an error if required arguments are missing' do
      expect { mutation.ready?({ board_id: 'some id' }) }
        .to raise_error(Gitlab::Graphql::Errors::ArgumentError, /one and only one of/)
    end

    it 'raises an error if too many required arguments are specified' do
      expect { mutation.ready?({ board_id: 'some id', backlog: true, label_id: 'some label' }) }
        .to raise_error(Gitlab::Graphql::Errors::ArgumentError, /one and only one of/)
    end
  end

  describe '#resolve' do
    context 'with proper permissions' do
      describe 'backlog list' do
        let(:list_create_params) { { backlog: true } }

        it 'creates one and only one backlog' do
          expect { subject }.to change { board.lists.backlog.count }.from(0).to(1)
          expect(board.lists.backlog.first.list_type).to eq 'backlog'

          backlog_id = board.lists.backlog.first.id

          expect { subject }.not_to change { board.lists.backlog.count }
          expect(board.lists.backlog.last.id).to eq backlog_id
        end
      end

      describe 'label list' do
        let_it_be(:dev_label) do
          create(:group_label, title: 'Development', color: '#FFAABB', group: group)
        end

        let(:list_create_params) { { label_id: dev_label.to_global_id.to_s } }

        it 'creates a new issue board list for labels' do
          expect { subject }.to change { board.lists.count }.from(1).to(2)

          new_list = subject[:list]

          expect(new_list.title).to eq dev_label.title
          expect(new_list.position).to eq 0
        end

        context 'when label not found' do
          let(:list_create_params) { { label_id: "gid://gitlab/Label/#{non_existing_record_id}" } }

          it 'raises an error' do
            expect { subject }
              .to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'Label not found!')
          end
        end
      end
    end

    context 'without proper permissions' do
      let(:current_user) { guest }

      it 'raises an error' do
        expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
      end
    end
  end
end