blob: 0cec67ff54157c0e4123205ae60ff99abb5c163f (
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.shared_examples 'board lists destroy request' do
include GraphqlHelpers
subject { post_graphql_mutation(mutation, current_user: current_user) }
shared_examples 'does not destroy the list and returns an error' do
it 'does not destroy the list' do
expect { subject }.not_to change { klass.count }
end
it 'returns an error and not nil list' do
subject
expect(mutation_response['errors']).not_to be_empty
expect(mutation_response['list']).not_to be_nil
end
end
context 'when the user does not have permission' do
it 'does not destroy the list' do
expect { subject }.not_to change { klass.count }
end
it 'returns an error' do
subject
expect(graphql_errors.first['message']).to include("The resource that you are attempting to access does not exist or you don't have permission to perform this action")
end
end
context 'when the user has permission' do
before do
group.add_maintainer(current_user)
end
context 'when given id is not for a list' do
# could be any non-list thing
let_it_be(:list) { group }
it 'returns an error' do
subject
expect(graphql_errors.first['message']).to include('does not represent an instance of')
end
end
context 'when list does not exist' do
let(:variables) do
{
list_id: "gid://gitlab/#{klass}/#{non_existing_record_id}"
}
end
it 'returns a top level error' do
subject
expect(graphql_errors.first['message']).to include('No object found for')
end
end
context 'when everything is ok' do
it 'destroys the list' do
expect { subject }.to change { klass.count }.by(-1)
end
it 'returns an empty list' do
post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response).to have_key('list')
expect(mutation_response['list']).to be_nil
expect(mutation_response['errors']).to be_empty
end
end
context 'when the list is not destroyable' do
before do
list.update!(list_type: :backlog)
end
it_behaves_like 'does not destroy the list and returns an error'
end
end
end
|