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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::BlobsResolver, feature_category: :source_code_management do
include GraphqlHelpers
include RepoHelpers
describe '.resolver_complexity' do
it 'adds one per path being resolved' do
control = described_class.resolver_complexity({}, child_complexity: 1)
expect(described_class.resolver_complexity({ paths: %w[a b c] }, child_complexity: 1))
.to eq(control + 3)
end
end
describe '#resolve' do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let(:repository) { project.repository }
let(:args) { { paths: paths, ref: ref } }
let(:paths) { [] }
let(:ref) { nil }
subject(:resolve_blobs) { resolve(described_class, obj: repository, args: args, ctx: { current_user: user }) }
context 'when unauthorized' do
it 'generates an error' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
resolve_blobs
end
end
end
context 'when authorized' do
before do
project.add_developer(user)
end
context 'using no filter' do
it 'returns nothing' do
is_expected.to be_empty
end
end
context 'using paths filter' do
let(:paths) { ['README.md'] }
it 'returns the specified blobs for HEAD' do
is_expected.to contain_exactly(have_attributes(path: 'README.md'))
end
context 'specifying a non-existent blob' do
let(:paths) { ['non-existent'] }
it 'returns nothing' do
is_expected.to be_empty
end
end
context 'when specifying a branch ref' do
let(:ref) { 'add-pdf-file' }
let(:args) { { paths: paths, ref: ref, ref_type: ref_type } }
let(:paths) { ['files/pdf/test.pdf', 'README.md'] }
context 'and no ref_type is specified' do
let(:ref_type) { nil }
it 'returns the specified blobs for that ref' do
is_expected.to contain_exactly(
have_attributes(path: 'files/pdf/test.pdf'),
have_attributes(path: 'README.md')
)
end
context 'and a tag with the same name exists' do
let(:ref) { SecureRandom.uuid }
before do
project.repository.create_branch(ref)
create_file_in_repo(project, ref, ref, 'branch_file', 'Test file', commit_message: 'Add new content')
project.repository.add_tag(project.owner, sample_commit.id, ref)
end
it 'returns the specified blobs for the tag' do
is_expected.to contain_exactly(
have_attributes(path: 'README.md')
)
end
end
end
context 'and ref_type is for branches' do
let(:args) { { paths: paths, ref: ref, ref_type: 'heads' } }
it 'returns nothing' do
is_expected.to contain_exactly(
have_attributes(path: 'files/pdf/test.pdf'),
have_attributes(path: 'README.md')
)
end
end
context 'and ref_type is for tags' do
let(:args) { { paths: paths, ref: ref, ref_type: 'tags' } }
it 'returns nothing' do
is_expected.to be_empty
end
end
end
context 'when specifying a tag ref' do
let(:ref) { 'v1.0.0' }
let(:args) { { paths: paths, ref: ref, ref_type: ref_type } }
context 'and no ref_type is specified' do
let(:ref_type) { nil }
it 'returns the specified blobs for that ref' do
is_expected.to contain_exactly(
have_attributes(path: 'README.md')
)
end
end
context 'and ref_type is for tags' do
let(:ref_type) { 'tags' }
it 'returns the specified blobs for that ref' do
is_expected.to contain_exactly(
have_attributes(path: 'README.md')
)
end
end
context 'and ref_type is for branches' do
let(:ref_type) { 'heads' }
it 'returns nothing' do
is_expected.to be_empty
end
end
end
context 'when specifying HEAD ref' do
let(:ref) { 'HEAD' }
it 'returns the specified blobs for HEAD' do
is_expected.to contain_exactly(have_attributes(path: 'README.md'))
end
end
context 'when specifying an invalid ref' do
let(:ref) { 'ma:in' }
it 'raises an ArgumentError' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'Ref is not valid') do
resolve_blobs
end
end
end
context 'when passing an empty ref' do
let(:ref) { '' }
it 'raises an ArgumentError' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'Ref is not valid') do
resolve_blobs
end
end
end
end
end
end
end
|