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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'PipelineScheduleUpdate', feature_category: :continuous_integration do
include GraphqlHelpers
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public, :repository) }
let_it_be(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: user) }
let(:mutation) do
variables = {
id: pipeline_schedule.to_global_id.to_s,
**pipeline_schedule_parameters
}
graphql_mutation(
:pipeline_schedule_update,
variables,
<<-QL
pipelineSchedule {
id
description
cron
refForDisplay
active
cronTimezone
variables {
nodes {
key
value
}
}
}
errors
QL
)
end
let(:pipeline_schedule_parameters) { {} }
let(:mutation_response) { graphql_mutation_response(:pipeline_schedule_update) }
context 'when unauthorized' do
it 'returns an error' do
post_graphql_mutation(mutation, current_user: create(: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
context 'when authorized' do
before do
project.add_developer(user)
end
context 'when success' do
let(:pipeline_schedule_parameters) do
{
description: 'updated_desc',
cron: '0 1 * * *',
cronTimezone: 'UTC',
ref: 'patch-x',
active: true,
variables: [
{ key: 'AAA', value: "AAA123", variableType: 'ENV_VAR' }
]
}
end
it do
post_graphql_mutation(mutation, current_user: user)
expect(response).to have_gitlab_http_status(:success)
expect_graphql_errors_to_be_empty
expect(mutation_response['pipelineSchedule']['id']).to eq(pipeline_schedule.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')
end
end
context 'when failure' do
context 'when params are invalid' do
let(:pipeline_schedule_parameters) do
{
description: '',
cron: 'abc',
cronTimezone: 'cCc',
ref: '',
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",
"Ref can't be blank",
"Description can't be blank"
]
)
end
end
context 'when params have duplicate variables' do
let(:pipeline_schedule_parameters) do
{
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
end
|