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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'JobArtifactsDestroy' do
include GraphqlHelpers
let_it_be(:user) { create(:user) }
let_it_be(:job) { create(:ci_build) }
let(:mutation) do
variables = {
id: job.to_global_id.to_s
}
graphql_mutation(:job_artifacts_destroy, variables, <<~FIELDS)
job {
name
}
destroyedArtifactsCount
errors
FIELDS
end
before do
create(:ci_job_artifact, :archive, job: job)
create(:ci_job_artifact, :junit, job: job)
end
context 'when the user is not allowed to destroy the job artifacts' do
it 'returns an error' do
post_graphql_mutation(mutation, current_user: user)
expect(graphql_errors).not_to be_empty
expect(job.reload.job_artifacts.count).to be(2)
end
end
context 'when the user is allowed to destroy the job artifacts' do
before do
job.project.add_maintainer(user)
end
it 'destroys the job artifacts and returns the expected data' do
expected_data = {
'jobArtifactsDestroy' => {
'errors' => [],
'destroyedArtifactsCount' => 2,
'job' => {
'name' => job.name
}
}
}
post_graphql_mutation(mutation, current_user: user)
expect(response).to have_gitlab_http_status(:success)
expect(graphql_data).to eq(expected_data)
expect(job.reload.job_artifacts.count).to be(0)
end
context 'when the the project this job belongs to is undergoing stats refresh' do
it 'destroys no artifacts and returns the correct error' do
allow_next_found_instance_of(Project) do |project|
allow(project).to receive(:refreshing_build_artifacts_size?).and_return(true)
end
expected_data = {
'jobArtifactsDestroy' => {
'errors' => ['Action temporarily disabled. The project this job belongs to is undergoing stats refresh.'],
'destroyedArtifactsCount' => 0,
'job' => {
'name' => job.name
}
}
}
post_graphql_mutation(mutation, current_user: user)
expect(response).to have_gitlab_http_status(:success)
expect(graphql_data).to eq(expected_data)
expect(job.reload.job_artifacts.count).to be(2)
end
end
end
end
|