This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
336 lines (292 loc) · 11.4 KB
/
test.js
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
"use strict"
const _ = require('lodash')
const chai = require('chai')
const expect = chai.expect
const SprintlyToJira = require('././lib/SprintlyToJira')
const url = require('url')
const URL = url.URL
// map Sprint.ly values on left to JIRA values on Right
const userMap = {
"[email protected]" : "employee",
"[email protected]" : null,
};
// Map Sprint.ly project numbers on left to JIRA on the right.
// Used for translating Sprint.ly links to JIRA links, even when then cross queues.
// So this mapping should be complete even if you are only importing one queue at a time.
const projectMap = {
12345 : "DEMO",
11122 : "UFS",
22233 : "ASTRO",
};
// Example constructor to migrate a single queue.
const s2j = new SprintlyToJira({
// To support incremental and partial imports.
firstTicketNum: 1,
lastTicketNum: 1,
sprintlyProjectNum: 11122, // UFS
jiraProjectKey: "UFS", // For testing
jiraBaseUrl: 'https://yourcorp.atlassian.net',
// Special proxy temporarily makes Sprint.ly attachments publicly accessible
// To JIRA during import by authenticating requests during the proxy.
fileProxyBaseUrl: 'http://sprintlyfiles.yourcorp.com/somesecret',
// Map Sprint.ly emails to JIRA user names:
userMap,
// Map Sprint.ly project names to JIRA project keys
projectMap,
maxLabels: 10,
maxComments: 50,
maxAttachments: 20,
// For testing, map child item 2 to parent item 2
ticketParentMap: {
2: 1,
}
});
describe("SprintlyToJira", () => {
xdescribe("jiraBaseUrl (not used)", () => {
it("should be set to our value", () => {
expect(s2j.jiraBaseUrl).to.equal("https://yourcorp.atlassian.net");
});
});
const expectedRowLength = 12+50+10+20
describe("csvHeaderRow", () => {
it("should have expected length", () => {
const row = s2j.csvHeaderRow;
expect(row).to.have.length(expectedRowLength);
})
});
describe("transformAllItemsToCSVArray", () => {
const newArray = s2j.transformAllItemsToCSVArray([
{
number: 123,
created_by: { email: '[email protected]', },
assigned_to: { email: '[email protected]', },
description: "Hello",
status: "completed",
labels: [],
comments: [],
attachments: [],
},
{
number: 456,
created_by: { email: '[email protected]', },
// Un-assigned items are assigned to null,
assigned_to: null,
description: "Hello",
status: "accepted",
labels: [],
comments: [],
attachments: [],
}
]);
it("Should have expected structure", () => {
// These are not valid items, but are sufficient for this test.
expect(newArray).to.have.length(3);
expect(newArray[0][0]).to.equal("Issue Key")
});
it("should have expected data row length", () => {
expect(newArray[1]).to.length(expectedRowLength);
});
it("should reality-check JIRA Issue key value", () => {
expect(newArray[1][0]).to.equal("UFS-123")
});
it("should reality-check Resolution for completed and accepted status", () => {
expect(newArray[1][11]).to.equal(undefined)
expect(newArray[2][11]).to.equal("Done")
});
});
describe("transformItemComments", () => {
it("should transform valid comments", () => {
const validSprintlyComments = [
{
"body": "Here is an [example](https://sprint.ly/product/11122/item/1234)",
"type": "commit",
"id": 400,
"created_by": {
"first_name": "employee", "last_name": "Stosberg",
"id": 1, "email": "[email protected]"
}
},
{
"body": "Hello World.",
"type": "commit",
"id": 445,
"created_by": {
"first_name": "employee", "last_name": "Stosberg",
"id": 1, "email": "[email protected]"
}
}
];
expect(s2j.transformItemComments(validSprintlyComments)).to.eql([
'2018-07-01T00:00:00+00:00; employee; Here is an [example|https://yourcorp.atlassian.net/browse/UFS-1234]',
'2018-07-01T00:00:00+00:00; employee; Hello World.',
]);
});
})
describe("transformItemAttachments", () => {
// Requires your own valid Sprint.ly Attachment URLs to work.
xit("should transform valid attachments", async () => {
const validSprintlyAttachments = [
{ "href": "https://sprint.ly/product/12345/file/220094" },
{ "href": "https://sprint.ly/product/12345/file/137135" }
];
const [ firstUrl, secondUrl ] = await s2j.transformItemAttachments(validSprintlyAttachments)
const firstUrlParsed = new URL(firstUrl);
expect(firstUrlParsed.origin).to.equal("https://item-attachments-production.s3.amazonaws.com")
expect(firstUrlParsed.pathname).to.equal("/69/9501a0c5f511e2a438476dbf08873d/some-file.png")
const secondUrlParsed = new URL(firstUrl);
expect(secondUrlParsed.origin).to.equal("https://item-attachments-production.s3.amazonaws.com")
expect(secondUrlParsed.pathname).to.equal("/69/9501a0c5f511e2a438476dbf08873d/some-file.png")
})
})
describe("transformMarkdown", () => {
it("should return through basic text unchanged", () => {
expect(s2j.transformMarkdown("Hello World")).to.equal("Hello World");
});
it("should convert a markdown link to Unity item to JIRA notation.", () => {
const desc = "Here is an [example](https://sprint.ly/product/11122/item/1234)"
expect(s2j.transformMarkdown(desc))
.to.equal("Here is an [example|https://yourcorp.atlassian.net/browse/UFS-1234]");
});
it("should convert a markdown link to DevOps item to JIRA notation.", () => {
const desc = "Here is an [example](https://sprint.ly/product/12345/item/23)"
expect(s2j.transformMarkdown(desc))
.to.equal("Here is an [example|https://yourcorp.atlassian.net/browse/DEMO-23]");
});
it("should convert a markdown link to Astro item to JIRA notation.", () => {
const desc = "Here is an [example](https://sprint.ly/product/22233/item/45)"
expect(s2j.transformMarkdown(desc))
.to.equal("Here is an [example|https://yourcorp.atlassian.net/browse/ASTRO-45]");
})
it("should link #123 as a Unity issue in JIRA", () => {
const desc = "Fixed thing. Ref: #123 some text after this"
expect(s2j.transformMarkdown(desc))
.to.equal("Fixed thing. Ref: [#123|https://yourcorp.atlassian.net/browse/UFS-123] "
+"some text after this");
})
it("should not double link", () => {
const desc = "before [#123|https://yourcorp.atlassian.net/browse/UFS-123] after"
expect(s2j.transformMarkdown(desc))
.to.equal("before [#123|https://yourcorp.atlassian.net/browse/UFS-123] after");
})
})
describe("transformItem", () => {
// From: https://support.sprint.ly/hc/en-us/articles/213642287-Items
const validSprintlyItem = {
"status": "backlog",
"created_at": "2013-06-14T22:52:07+00:00",
"last_modified": "2013-06-14T21:53:43+00:00",
"product": {
"archived": false,
"id": 1,
"name": "sprint.ly"
},
"progress": {
"accepted_at": "2013-06-14T22:52:07+00:00",
"closed_at": "2013-06-14T21:53:43+00:00",
"started_at": "2013-06-14T21:50:36+00:00"
},
"description": "Require people to estimate the score of an item before they can start working on it.",
"tags": [
"scoring",
"backlog"
],
"number": 188,
"archived": false,
"title": "Don't let un-scored items out of the backlog.",
"created_by": {
"first_name": "Mark Stosberg",
"last_name": "Stosberg",
"id": 1,
"email": "[email protected]"
},
"score": "M",
"sort": 1,
"assigned_to": {
"first_name": "Mark Stosberg",
"last_name": "Stosberg",
"id": 1,
"email": "[email protected]"
},
"type": "task"
};
it("should return JIRA issue structure for known-user case", () => {
const jiraIssue = s2j.transformItem(validSprintlyItem)
expect(jiraIssue).to.eql({
"Date Created": "2013-06-14T22:52:07+00:00",
"Date Modified": "2013-06-14T21:53:43+00:00",
"Issue Id": 188,
"Parent Id": undefined,
"Issue Key": "UFS-188",
"Summary": "Don't let un-scored items out of the backlog.",
"Issue Type": "Task",
"Assignee": 'employee',
"Reporter": 'employee',
"labels": ["scoring","backlog"],
"Description": "Require people to estimate the score of an item before they can start working on it.",
"Status": "backlog",
"attachments": undefined,
"comments": undefined,
})
})
it("should set Issue Type to Sub-Task for if parent issue is found.", () => {
const childItem = _.cloneDeep(validSprintlyItem);
// Set a number to match a child in ticketParentMap
childItem.number = 2;
const jiraIssue = s2j.transformItem(childItem)
expect(jiraIssue).to.eql({
"Date Created": "2013-06-14T22:52:07+00:00",
"Date Modified": "2013-06-14T21:53:43+00:00",
"Issue Id": 2,
"Parent Id": 1,
"Issue Key": "UFS-2",
"Summary": "Don't let un-scored items out of the backlog.",
"Issue Type": "Sub-Task",
"Assignee": 'employee',
"Reporter": 'employee',
"labels": ["scoring","backlog"],
"Description": "Require people to estimate the score of an item before they can start working on it.",
"Status": "backlog",
"attachments": undefined,
"comments": undefined,
})
})
it("should set users to null for known ex-employees.", () => {
const exEmployeeItem = validSprintlyItem;
exEmployeeItem.created_by = {
first_name: "Ex",
last_name: "Employee",
id: 2,
email: "[email protected]",
};
exEmployeeItem.assigned_to = exEmployeeItem.created_by;
const jiraIssue = s2j.transformItem(exEmployeeItem)
expect(jiraIssue).to.eql({
"Assignee": null,
"Reporter": null,
"Date Created": "2013-06-14T22:52:07+00:00",
"Date Modified": "2013-06-14T21:53:43+00:00",
"Issue Id": 188,
"Parent Id": undefined,
"Issue Key": "UFS-188",
"Summary": "Don't let un-scored items out of the backlog.",
"Issue Type": "Task",
"labels": ["scoring","backlog"],
"Description": "Require people to estimate the score of an item before they can start working on it.",
"Status": "backlog",
"attachments": undefined,
"comments": undefined,
})
})
it("should throw if we failed to map a user (rather than silent failure)", () => {
const nonEmployeeItem = validSprintlyItem;
nonEmployeeItem.created_by = {
first_name: "Forgotten",
last_name: "Bob",
id: 2,
email: "[email protected]",
};
nonEmployeeItem.assigned_to = nonEmployeeItem.created_by;
expect(() =>s2j.transformItem(nonEmployeeItem)).to.throw;
})
}) // transformItem
})