blob: 2caaedda2a12525b786c00da13c006e43745503a (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'getting a list of work item types for a project' do
include GraphqlHelpers
let_it_be(:developer) { create(:user) }
let_it_be(:project) { create(:project) }
before_all do
project.add_developer(developer)
end
let(:current_user) { developer }
let(:fields) do
<<~GRAPHQL
workItemTypes{
nodes { id name iconName }
}
GRAPHQL
end
let(:query) do
graphql_query_for(
'project',
{ 'fullPath' => project.full_path },
fields
)
end
context 'when user has access to the project' do
before do
post_graphql(query, current_user: current_user)
end
it_behaves_like 'a working graphql query'
it 'returns all default work item types' do
expect(graphql_data.dig('project', 'workItemTypes', 'nodes')).to match_array(
WorkItems::Type.default.map do |type|
hash_including('id' => type.to_global_id.to_s, 'name' => type.name, 'iconName' => type.icon_name)
end
)
end
end
context "when user doesn't have access to the project" do
let(:current_user) { create(:user) }
before do
post_graphql(query, current_user: current_user)
end
it 'does not return the project' do
expect(graphql_data).to eq('project' => nil)
end
end
context 'when the work_items feature flag is disabled' do
before do
stub_feature_flags(work_items: false)
post_graphql(query, current_user: current_user)
end
it 'makes the workItemTypes field unavailable' do
expect(graphql_errors).to contain_exactly(hash_including("message" => "Field 'workItemTypes' doesn't exist on type 'Project'"))
end
end
end
|