blob: 9c0b398a5c1789d43e3d33971c688a63082345d6 (
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
|
# frozen_string_literal: true
RSpec.shared_examples 'boards create mutation' do
include GraphqlHelpers
let_it_be(:current_user, reload: true) { create(:user) }
let(:name) { 'board name' }
let(:mutation) { graphql_mutation(:create_board, params) }
subject { post_graphql_mutation(mutation, current_user: current_user) }
def mutation_response
graphql_mutation_response(:create_board)
end
context 'when the user does not have permission' do
it_behaves_like 'a mutation that returns a top-level access error'
it 'does not create the board' do
expect { subject }.not_to change { Board.count }
end
end
context 'when the user has permission' do
before do
parent.add_maintainer(current_user)
end
context 'when the parent (project_path or group_path) param is given' do
context 'when everything is ok' do
it 'creates the board' do
expect { subject }.to change { Board.count }.from(0).to(1)
end
it 'returns the created board' do
post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response).to have_key('board')
expect(mutation_response['board']['name']).to eq(name)
end
end
context 'when the Boards::CreateService returns an error response' do
before do
allow_next_instance_of(Boards::CreateService) do |service|
allow(service).to receive(:execute).and_return(ServiceResponse.error(message: 'There was an error.'))
end
end
it 'does not create a board' do
expect { subject }.not_to change { Board.count }
end
it 'returns an error' do
post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response).to have_key('board')
expect(mutation_response['board']).to be_nil
expect(mutation_response['errors'].first).to eq('There was an error.')
end
end
end
context 'when neither project_path nor group_path param is given' do
let(:params) { { name: name } }
it_behaves_like 'a mutation that returns top-level errors',
errors: ['Exactly one of group_path or project_path arguments is required']
it 'does not create the board' do
expect { subject }.not_to change { Board.count }
end
end
end
end
|