blob: b197d223463a483280f5ec3e13833582e80d8042 (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'PipelineScheduleDelete' do
include GraphqlHelpers
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: user) }
let(:mutation) do
graphql_mutation(
:pipeline_schedule_delete,
{ id: pipeline_schedule_id },
<<-QL
errors
QL
)
end
let(:pipeline_schedule_id) { pipeline_schedule.to_global_id.to_s }
let(:mutation_response) { graphql_mutation_response(:pipeline_schedule_delete) }
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)
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['errors']).to eq([])
end
end
context 'when failure' do
context 'when destroy fails' do
before do
allow_next_found_instance_of(Ci::PipelineSchedule) do |pipeline_schedule|
allow(pipeline_schedule).to receive(:destroy).and_return(false)
end
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(['Failed to remove the pipeline schedule'])
end
end
context 'when pipeline schedule not found' do
let(:pipeline_schedule_id) { 'gid://gitlab/Ci::PipelineSchedule/0' }
it do
post_graphql_mutation(mutation, current_user: user)
expect(graphql_errors).not_to be_empty
expect(graphql_errors[0]['message'])
.to eq("Internal server error: Couldn't find Ci::PipelineSchedule with 'id'=0")
end
end
end
end
end
|