blob: 0e43fa024f31f0d33185801d57d28c1621b09b8c (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'PipelineSchedulePlay', feature_category: :continuious_integration do
include GraphqlHelpers
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:pipeline_schedule) do
create(
:ci_pipeline_schedule,
:every_minute,
project: project,
owner: user
)
end
let(:mutation) do
graphql_mutation(
:pipeline_schedule_play,
{ id: pipeline_schedule.to_global_id.to_s },
<<-QL
pipelineSchedule { id, nextRunAt }
errors
QL
)
end
let(:mutation_response) { graphql_mutation_response(:pipeline_schedule_play) }
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_maintainer(user)
pipeline_schedule.update_columns(next_run_at: 2.hours.ago)
end
context 'when mutation succeeds' do
it do
post_graphql_mutation(mutation, current_user: user)
expect(mutation_response['pipelineSchedule']['id']).to include(pipeline_schedule.id.to_s)
new_next_run_at = DateTime.parse(mutation_response['pipelineSchedule']['nextRunAt'])
expect(new_next_run_at).not_to eq(pipeline_schedule.next_run_at)
expect(new_next_run_at).to eq(pipeline_schedule.reset.next_run_at)
expect(mutation_response['errors']).to eq([])
end
end
context 'when mutation fails' do
before do
allow(RunPipelineScheduleWorker).to receive(:perform_async).and_return(nil)
end
it do
expect(RunPipelineScheduleWorker)
.to receive(:perform_async)
.with(pipeline_schedule.id, user.id)
post_graphql_mutation(mutation, current_user: user)
expect(mutation_response['pipelineSchedule']).to be_nil
expect(mutation_response['errors']).to match_array(['Unable to schedule a pipeline to run immediately.'])
end
end
end
end
|