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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::BlameResolver, feature_category: :source_code_management do
include GraphqlHelpers
describe '#resolve' do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let(:path) { 'files/ruby/popen.rb' }
let(:commit) { project.commit('master') }
let(:blob) { project.repository.blob_at(commit.id, path) }
let(:args) { { from_line: 1, to_line: 100 } }
subject(:resolve_blame) { resolve(described_class, obj: blob, 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_blame
end
end
end
context 'when authorized' do
before_all do
project.add_developer(user)
end
context 'when feature is disabled' do
before do
stub_feature_flags(graphql_git_blame: false)
end
it 'returns nothing' do
expect(subject).to be_nil
end
end
shared_examples 'argument error' do |error_message|
it 'raises an ArgumentError' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError,
error_message) do
resolve_blame
end
end
end
context 'when feature is enabled' do
context 'when from_line is below 1' do
let(:args) { { from_line: 0, to_line: 2 } }
it_behaves_like 'argument error', '`from_line` and `to_line` must be greater than or equal to 1'
end
context 'when to_line is below 1' do
let(:args) { { from_line: 1, to_line: 0 } }
it_behaves_like 'argument error', '`from_line` and `to_line` must be greater than or equal to 1'
end
context 'when to_line less than from_line' do
let(:args) { { from_line: 3, to_line: 1 } }
it_behaves_like 'argument error', '`to_line` must be greater than or equal to `from_line`'
end
context 'when difference between to_line and from_line is greater then 99' do
let(:args) { { from_line: 3, to_line: 103 } }
it_behaves_like 'argument error',
'`to_line` must be greater than or equal to `from_line` and smaller than `from_line` + 100'
end
context 'when to_line and from_line are the same' do
let(:args) { { from_line: 1, to_line: 1 } }
it 'returns blame object' do
expect(resolve_blame).to be_an_instance_of(Gitlab::Blame)
end
end
it 'returns blame object' do
expect(resolve_blame).to be_an_instance_of(Gitlab::Blame)
end
end
end
end
end
|