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
180
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::JiraImport::MetadataCollector do
describe '#execute' do
let(:key) { 'PROJECT-5' }
let(:summary) { 'some title' }
let(:description) { 'basic description' }
let(:created_at) { '2020-01-01 20:00:00' }
let(:updated_at) { '2020-01-10 20:00:00' }
let(:jira_status) { 'new' }
let(:parent_field) do
{ 'key' => 'FOO-2', 'id' => '1050', 'fields' => { 'summary' => 'parent issue FOO' } }
end
let(:issue_type_field) { { 'name' => 'Task' } }
let(:fix_versions_field) { [{ 'name' => '1.0' }, { 'name' => '1.1' }] }
let(:priority_field) { { 'name' => 'Medium' } }
let(:environment_field) { 'staging' }
let(:duedate_field) { '2020-03-01' }
let(:fields) do
{
'parent' => parent_field,
'issuetype' => issue_type_field,
'fixVersions' => fix_versions_field,
'priority' => priority_field,
'environment' => environment_field,
'duedate' => duedate_field
}
end
let(:jira_issue) do
double(
id: '1234',
key: key,
summary: summary,
description: description,
created: created_at,
updated: updated_at,
status: double(statusCategory: { 'key' => jira_status }),
fields: fields
)
end
subject { described_class.new(jira_issue).execute }
context 'when all metadata fields are present' do
it 'writes all fields' do
expected_result = <<~MD
---
**Issue metadata**
- Issue type: Task
- Priority: Medium
- Environment: staging
- Due date: 2020-03-01
- Parent issue: [FOO-2] parent issue FOO
- Fix versions: 1.0, 1.1
MD
expect(subject.strip).to eq(expected_result.strip)
end
end
context 'when some fields are in incorrect format' do
let(:parent_field) { nil }
let(:fix_versions_field) { [] }
let(:priority_field) { nil }
let(:environment_field) { nil }
let(:duedate_field) { nil }
context 'when fixVersions field is not an array' do
let(:fix_versions_field) { { 'title' => '1.0', 'name' => '1.1' } }
it 'skips these fields' do
expected_result = <<~MD
---
**Issue metadata**
- Issue type: Task
MD
expect(subject.strip).to eq(expected_result.strip)
end
end
context 'when a fixVersions element is in incorrect format' do
let(:fix_versions_field) { [{ 'title' => '1.0' }, { 'name' => '1.1' }] }
it 'skips the element' do
expected_result = <<~MD
---
**Issue metadata**
- Issue type: Task
- Fix versions: 1.1
MD
expect(subject.strip).to eq(expected_result.strip)
end
end
context 'when a parent field has incorrectly formatted summary' do
let(:parent_field) do
{ 'key' => 'FOO-2', 'id' => '1050', 'other_field' => { 'summary' => 'parent issue FOO' } }
end
it 'skips the summary' do
expected_result = <<~MD
---
**Issue metadata**
- Issue type: Task
- Parent issue: [FOO-2]
MD
expect(subject.strip).to eq(expected_result.strip)
end
end
context 'when a parent field is missing the key' do
let(:parent_field) do
{ 'not_key' => 'FOO-2', 'id' => '1050', 'other_field' => { 'summary' => 'parent issue FOO' } }
end
it 'skips the field' do
expected_result = <<~MD
---
**Issue metadata**
- Issue type: Task
MD
expect(subject.strip).to eq(expected_result.strip)
end
end
end
context 'when some metadata fields are missing' do
let(:parent_field) { nil }
let(:fix_versions_field) { [] }
let(:environment_field) { nil }
it 'skips the missing fields' do
expected_result = <<~MD
---
**Issue metadata**
- Issue type: Task
- Priority: Medium
- Due date: 2020-03-01
MD
expect(subject.strip).to eq(expected_result.strip)
end
end
context 'when all metadata fields are missing' do
let(:parent_field) { nil }
let(:issue_type_field) { nil }
let(:fix_versions_field) { [] }
let(:priority_field) { nil }
let(:environment_field) { nil }
let(:duedate_field) { nil }
it 'returns nil' do
expect(subject).to be_nil
end
end
end
end
|