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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'PipelineSchedulecreate', feature_category: :continuous_integration do
include GraphqlHelpers
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public, :repository) }
let(:mutation) do
variables = {
project_path: project.full_path,
**pipeline_schedule_parameters
}
graphql_mutation(
:pipeline_schedule_create,
variables,
<<-QL
pipelineSchedule {
id
description
cron
refForDisplay
active
cronTimezone
variables {
nodes {
key
value
}
}
owner {
id
}
}
errors
QL
)
end
let(:pipeline_schedule_parameters) do
{
description: 'created_desc',
cron: '0 1 * * *',
cronTimezone: 'UTC',
ref: 'patch-x',
active: true,
variables: [
{ key: 'AAA', value: "AAA123", variableType: 'ENV_VAR' }
]
}
end
let(:mutation_response) { graphql_mutation_response(:pipeline_schedule_create) }
context 'when unauthorized' do
it 'returns an error' do
post_graphql_mutation(mutation, current_user: user)
expect(graphql_errors).not_to be_empty
expect(graphql_errors[0]['message'])
.to eq(
"The resource that you are attempting to access does not exist " \
"or you don't have permission to perform this action"
)
end
end
# Move this from `shared_context` to `context` when `ci_refactoring_pipeline_schedule_create_service` is removed.
shared_context 'when authorized' do # rubocop:disable RSpec/ContextWording
before_all do
project.add_developer(user)
end
context 'when success' do
it do
post_graphql_mutation(mutation, current_user: user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['pipelineSchedule']['owner']['id']).to eq(user.to_global_id.to_s)
%w[description cron cronTimezone active].each do |key|
expect(mutation_response['pipelineSchedule'][key]).to eq(pipeline_schedule_parameters[key.to_sym])
end
expect(mutation_response['pipelineSchedule']['refForDisplay']).to eq(pipeline_schedule_parameters[:ref])
expect(mutation_response['pipelineSchedule']['variables']['nodes'][0]['key']).to eq('AAA')
expect(mutation_response['pipelineSchedule']['variables']['nodes'][0]['value']).to eq('AAA123')
expect(mutation_response['pipelineSchedule']['owner']['id']).to eq(user.to_global_id.to_s)
expect(mutation_response['errors']).to eq([])
end
end
context 'when failure' do
context 'when params are invalid' do
let(:pipeline_schedule_parameters) do
{
description: 'some description',
cron: 'abc',
cronTimezone: 'cCc',
ref: 'asd',
active: true,
variables: []
}
end
it do
post_graphql_mutation(mutation, current_user: user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['errors'])
.to match_array(
["Cron is invalid syntax", "Cron timezone is invalid syntax"]
)
end
end
context 'when variables have duplicate name' do
before do
pipeline_schedule_parameters.merge!(
{
variables: [
{ key: 'AAA', value: "AAA123", variableType: 'ENV_VAR' },
{ key: 'AAA', value: "AAA123", variableType: 'ENV_VAR' }
]
}
)
end
it 'returns error' do
post_graphql_mutation(mutation, current_user: user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['errors'])
.to match_array(
[
"Variables have duplicate values (AAA)"
]
)
end
end
end
end
it_behaves_like 'when authorized'
context 'when the FF ci_refactoring_pipeline_schedule_create_service is disabled' do
before do
stub_feature_flags(ci_refactoring_pipeline_schedule_create_service: false)
end
it_behaves_like 'when authorized'
end
end
|