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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkImports::SourceUrlBuilder, feature_category: :importers do
let_it_be(:bulk_import) { create(:bulk_import) }
let_it_be(:configuration) { create(:bulk_import_configuration, bulk_import: bulk_import) }
let(:entity) { create(:bulk_import_entity, bulk_import: bulk_import) }
let(:tracker) { create(:bulk_import_tracker, entity: entity) }
let(:context) { BulkImports::Pipeline::Context.new(tracker) }
let(:entry) { Issue.new(iid: 1, title: 'hello world') }
describe '#url' do
subject { described_class.new(context, entry) }
before do
allow(subject).to receive(:relation).and_return('issues')
end
context 'when relation is allowed' do
context 'when entity is a group' do
it 'returns the url specific to groups' do
expected_url = File.join(
configuration.url,
'groups',
entity.source_full_path,
'-',
'issues',
'1'
)
expect(subject.url).to eq(expected_url)
end
end
context 'when entity is a project' do
let(:entity) { create(:bulk_import_entity, :project_entity, bulk_import: bulk_import) }
it 'returns the url' do
expected_url = File.join(
configuration.url,
entity.source_full_path,
'-',
'issues',
'1'
)
expect(subject.url).to eq(expected_url)
end
end
end
context 'when entry is not an ApplicationRecord' do
let(:entry) { 'not an ApplicationRecord' }
it 'returns nil' do
expect(subject.url).to be_nil
end
end
context 'when relation is not allowed' do
it 'returns nil' do
allow(subject).to receive(:relation).and_return('not_allowed')
expect(subject.url).to be_nil
end
end
context 'when entry has no iid' do
let(:entry) { Issue.new }
it 'returns nil' do
expect(subject.url).to be_nil
end
end
end
end
|