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
|
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::GithubImport::Importer::LabelLinksImporter do
let(:project) { create(:project) }
let(:client) { double(:client) }
let(:issue) do
double(
:issue,
iid: 4,
label_names: %w[bug],
issuable_type: Issue,
pull_request?: false
)
end
let(:importer) { described_class.new(issue, project, client) }
describe '#execute' do
it 'creates the label links' do
importer = described_class.new(issue, project, client)
expect(importer).to receive(:create_labels)
importer.execute
end
end
describe '#create_labels' do
it 'inserts the label links in bulk' do
expect(importer.label_finder)
.to receive(:id_for)
.with('bug')
.and_return(2)
expect(importer)
.to receive(:find_target_id)
.and_return(1)
Timecop.freeze do
expect(Gitlab::Database)
.to receive(:bulk_insert)
.with(
LabelLink.table_name,
[
{
label_id: 2,
target_id: 1,
target_type: Issue,
created_at: Time.zone.now,
updated_at: Time.zone.now
}
]
)
importer.create_labels
end
end
it 'does not insert label links for non-existing labels' do
expect(importer.label_finder)
.to receive(:id_for)
.with('bug')
.and_return(nil)
expect(Gitlab::Database)
.to receive(:bulk_insert)
.with(LabelLink.table_name, [])
importer.create_labels
end
end
describe '#find_target_id' do
it 'returns the ID of the issuable to create the label link for' do
expect_next_instance_of(Gitlab::GithubImport::IssuableFinder) do |instance|
expect(instance).to receive(:database_id).and_return(10)
end
expect(importer.find_target_id).to eq(10)
end
end
end
|