ticket-replicator 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,7 +42,7 @@ module Ticket
42
42
  it do
43
43
  expect(loader).to receive(:create_ticket)
44
44
 
45
- loader.ticket
45
+ loader.send(:ticket)
46
46
  end
47
47
  end
48
48
 
@@ -52,7 +52,7 @@ module Ticket
52
52
  it do
53
53
  expect(loader).to receive(:fetch_ticket)
54
54
 
55
- loader.ticket
55
+ loader.send(:ticket)
56
56
  end
57
57
  end
58
58
  end
@@ -108,7 +108,7 @@ module Ticket
108
108
  it do
109
109
  expect(jira_project).to receive(:replicated_tickets).and_return(replicated_tickets)
110
110
 
111
- expect(loader.fetch_ticket).to be(:a_ticket)
111
+ expect(loader.send(:fetch_ticket)).to be(:a_ticket)
112
112
  end
113
113
  end
114
114
 
@@ -128,7 +128,7 @@ module Ticket
128
128
  expect(issue_accessor).to receive(:build).and_return(jira_ticket)
129
129
  expect(Ticket).to receive(:new).with(jira_auto_tool, jira_ticket).and_return(:ticket)
130
130
 
131
- expect(loader.create_ticket).to eq(:ticket)
131
+ expect(loader.send(:create_ticket)).to eq(:ticket)
132
132
  end
133
133
  end
134
134
 
@@ -149,26 +149,14 @@ module Ticket
149
149
  ticket: ticket,
150
150
  :ticket_fields_need_to_be_updated? => ticket_fields_need_to_be_updated?
151
151
  )
152
-
153
- allow(jira_project)
154
- .to receive_messages(resolutions: {
155
- "Done" => nil, "Won't Do" => nil, "Duplicate" => nil, "Cannot Reproduce" => nil
156
- })
157
152
  end
158
153
 
159
154
  context "when the previously replicated needs to be updated " do
160
155
  let(:ticket_fields_need_to_be_updated?) { true }
161
156
 
162
157
  it do
163
- expect(jira_ticket).to receive(:save!).with({
164
- fields: {
165
- project: { key: "PROJKEY" },
166
- issuetype: { name: "Bug" },
167
- resolution: { name: "Done" },
168
- priority: { name: "Low" },
169
- summary: "PREFIX | summary"
170
- }
171
- })
158
+ allow(loader).to receive_messages(attributes_for_save: { fields: { a: "b" } })
159
+ expect(jira_ticket).to receive(:save!).with({ fields: { a: "b" } })
172
160
 
173
161
  expect(jira_ticket).to receive(:fetch)
174
162
 
@@ -188,6 +176,71 @@ module Ticket
188
176
  end
189
177
  end
190
178
 
179
+ describe "#attributes_for_save" do
180
+ let(:loader) { described_class.send(:new, jira_project, row) }
181
+
182
+ let(:row) do
183
+ { id: "123", priority: "Low", resolution: "Done", status: "Open", summary: "PREFIX | summary",
184
+ team: "A Team" }
185
+ end
186
+
187
+ before do
188
+ allow(jira_project)
189
+ .to receive_messages(resolutions: {
190
+ "Done" => nil, "Won't Do" => nil, "Duplicate" => nil, "Cannot Reproduce" => nil
191
+ })
192
+
193
+ allow(loader).to receive_messages(exclude_resolution?: exclude_resolution?)
194
+ end
195
+
196
+ context "when the resolution is not excluded" do
197
+ let(:exclude_resolution?) { false }
198
+
199
+ it do
200
+ expect(loader.send(:attributes_for_save)).to eq({
201
+ fields: {
202
+ project: { key: "PROJKEY" },
203
+ issuetype: { name: "Bug" },
204
+ priority: { name: "Low" },
205
+ resolution: { name: "Done" },
206
+ summary: "PREFIX | summary"
207
+ }
208
+ })
209
+ end
210
+ end
211
+
212
+ context "when excluding the resolution" do
213
+ let(:exclude_resolution?) { true }
214
+
215
+ it do
216
+ expect(loader.send(:attributes_for_save)).to eq({
217
+ fields: {
218
+ project: { key: "PROJKEY" },
219
+ issuetype: { name: "Bug" },
220
+ priority: { name: "Low" },
221
+ summary: "PREFIX | summary"
222
+ }
223
+ })
224
+ end
225
+ end
226
+ end
227
+
228
+ describe "#exclude_resolution?" do
229
+ before { allow(ENV).to receive(:[]).with("TICKET_REPLICATOR_DISABLE_RESOLUTION_LOADING").and_return(env_value) }
230
+
231
+ context "when the environment variable is not set to true" do
232
+ let(:env_value) { nil }
233
+
234
+ it { expect(loader.send(:exclude_resolution?)).to be_falsey }
235
+ end
236
+
237
+ context "when the environment variable is set to true" do
238
+ let(:env_value) { "true" }
239
+
240
+ it { expect(loader.send(:exclude_resolution?)).to be_truthy }
241
+ end
242
+ end
243
+
191
244
  describe "#build_ticket_link_attributes" do
192
245
  it "builds the link attributes with a default application" do
193
246
  expect(described_class.send(:build_ticket_link_attributes,
@@ -222,21 +275,21 @@ module Ticket
222
275
  let(:ticket_previously_replicated?) { false }
223
276
  let(:ticket_fields_changed?) { false }
224
277
 
225
- it { expect(loader.ticket_fields_need_to_be_updated?).to be_truthy }
278
+ it { expect(loader.send(:ticket_fields_need_to_be_updated?)).to be_truthy }
226
279
  end
227
280
 
228
281
  context "when the fields changed since last replication" do
229
282
  let(:ticket_previously_replicated?) { true }
230
283
  let(:ticket_fields_changed?) { true }
231
284
 
232
- it { expect(loader.ticket_fields_need_to_be_updated?).to be_truthy }
285
+ it { expect(loader.send(:ticket_fields_need_to_be_updated?)).to be_truthy }
233
286
  end
234
287
 
235
288
  context "when the fields did not change since last replication" do
236
289
  let(:ticket_previously_replicated?) { true }
237
290
  let(:ticket_fields_changed?) { false }
238
291
 
239
- it { expect(loader.ticket_fields_need_to_be_updated?).to be_falsey }
292
+ it { expect(loader.send(:ticket_fields_need_to_be_updated?)).to be_falsey }
240
293
  end
241
294
  end
242
295
 
@@ -246,57 +299,89 @@ module Ticket
246
299
  end
247
300
 
248
301
  let(:loader) { described_class.send(:new, jira_project, row) }
249
- let(:jira_ticket) { double(JIRA::Resource::Issue, summary: current_summary, priority: current_priority) }
302
+
303
+ let(:jira_ticket) do
304
+ double(JIRA::Resource::Issue,
305
+ summary: current_summary,
306
+ priority: current_priority,
307
+ resolution: current_resolution)
308
+ end
250
309
 
251
310
  before do
252
311
  expect(loader).to receive(:ticket).at_least(:once).and_return(jira_ticket)
253
312
  end
254
313
 
255
- context "when both summary and priority changed" do
314
+ context "when summary, priority and resolution changed" do
256
315
  let(:current_summary) { "PREFIX | different summary" }
257
316
  let(:current_priority) { "High" }
317
+ let(:current_resolution) { "Won't Do" }
258
318
 
259
- it { expect(loader.ticket_fields_changed?).to be_truthy }
319
+ it { expect(loader.send(:ticket_fields_changed?)).to be_truthy }
260
320
  end
261
321
 
262
322
  context "when only summary changed" do
263
323
  let(:current_summary) { "PREFIX | different summary" }
264
324
  let(:current_priority) { "Low" }
325
+ let(:current_resolution) { "" }
265
326
 
266
- it { expect(loader.ticket_fields_changed?).to be_truthy }
327
+ it { expect(loader.send(:ticket_fields_changed?)).to be_truthy }
267
328
  end
268
329
 
269
330
  context "when only priority changed" do
270
331
  let(:current_summary) { "PREFIX | summary" }
271
332
  let(:current_priority) { "High" }
333
+ let(:current_resolution) { "" }
272
334
 
273
- it { expect(loader.ticket_fields_changed?).to be_truthy }
335
+ it { expect(loader.send(:ticket_fields_changed?)).to be_truthy }
336
+ end
337
+
338
+ context "when only resolution changed" do
339
+ let(:current_summary) { "PREFIX | summary" }
340
+ let(:current_priority) { "Low" }
341
+ let(:current_resolution) { "Done" }
342
+
343
+ before do
344
+ allow(loader).to receive_messages(exclude_resolution?: exclude_resolution?)
345
+ end
346
+
347
+ context "when the resolution is not excluded" do
348
+ let(:exclude_resolution?) { false }
349
+
350
+ it { expect(loader.send(:ticket_fields_changed?)).to be_truthy }
351
+ end
352
+
353
+ context "when excluding the resolution" do
354
+ let(:exclude_resolution?) { true }
355
+
356
+ it { expect(loader.send(:ticket_fields_changed?)).to be_falsey }
357
+ end
274
358
  end
275
359
 
276
360
  context "when neither summary nor priority changed" do
277
361
  let(:current_summary) { "PREFIX | summary" }
278
362
  let(:current_priority) { "Low" }
363
+ let(:current_resolution) { "" }
279
364
 
280
- it { expect(loader.ticket_fields_changed?).to be_falsey }
365
+ it { expect(loader.send(:ticket_fields_changed?)).to be_falsey }
281
366
  end
282
367
  end
283
368
 
284
369
  describe "#ticket_previously_replicated?" do
285
370
  let(:loader) { described_class.send(:new, jira_project, row) }
286
- let(:replicated_tickets) { { "123" => "a_ticket" } }
371
+ let(:replicated_tickets) { { "123" => "a_ticket", "880" => "another_ticket" } }
287
372
 
288
373
  before { expect(jira_project).to receive(:replicated_tickets).and_return(replicated_tickets) }
289
374
 
290
375
  context "when previously replicated" do
291
376
  let(:row) { { id: "123" } }
292
377
 
293
- it { expect(loader.ticket_previously_replicated?).to be_truthy }
378
+ it { expect(loader.send(:ticket_previously_replicated?)).to be_truthy }
294
379
  end
295
380
 
296
381
  context "when previously replicated" do
297
382
  let(:row) { { id: "456" } }
298
383
 
299
- it { expect(loader.ticket_previously_replicated?).to be_falsey }
384
+ it { expect(loader.send(:ticket_previously_replicated?)).to be_falsey }
300
385
  end
301
386
  end
302
387
 
@@ -317,7 +402,7 @@ module Ticket
317
402
  let(:expected_link) { build_link("https://url/to/source/ticket/123", "Source Ticket 123") }
318
403
 
319
404
  describe "#source_ticket_link_title" do
320
- it { expect(loader.source_ticket_link_title).to eq("Source Ticket 123") }
405
+ it { expect(loader.send(:source_ticket_link_title)).to eq("Source Ticket 123") }
321
406
  end
322
407
 
323
408
  describe "#update_source_ticket_remote_link" do
@@ -333,7 +418,7 @@ module Ticket
333
418
  it "setups the link" do
334
419
  expect(remotelink).to receive(:save!).with(expected_link)
335
420
 
336
- loader.update_source_ticket_remote_link
421
+ loader.send(:update_source_ticket_remote_link)
337
422
  end
338
423
  end
339
424
 
@@ -347,7 +432,7 @@ module Ticket
347
432
  expect(source_ticket_link).to receive(:delete)
348
433
  expect(remotelink).to receive(:save!).with(expected_link)
349
434
 
350
- loader.update_source_ticket_remote_link
435
+ loader.send(:update_source_ticket_remote_link)
351
436
  end
352
437
  end
353
438
 
@@ -357,7 +442,7 @@ module Ticket
357
442
  it "no link creation happens" do
358
443
  expect(remotelink).not_to receive(:save!)
359
444
 
360
- loader.update_source_ticket_remote_link
445
+ loader.send(:update_source_ticket_remote_link)
361
446
  end
362
447
  end
363
448
  end
@@ -370,7 +455,7 @@ module Ticket
370
455
  context "when link has yet to be created" do
371
456
  let(:remote_link) { nil }
372
457
 
373
- it { expect(loader.source_ticket_link_needs_update?).to be_truthy }
458
+ it { expect(loader.send(:source_ticket_link_needs_update?)).to be_truthy }
374
459
  end
375
460
 
376
461
  context "when link already exists" do
@@ -387,14 +472,14 @@ module Ticket
387
472
  let(:existing_url) { "https://__OLD_URL__/to/source/ticket/1234" }
388
473
  let(:existing_title) { "Source Ticket 123" }
389
474
 
390
- it { expect(loader.source_ticket_link_needs_update?).to be_truthy }
475
+ it { expect(loader.send(:source_ticket_link_needs_update?)).to be_truthy }
391
476
  end
392
477
 
393
478
  context "when title has changed" do
394
479
  let(:existing_url) { "https://url/to/source/ticket/123" }
395
480
  let(:existing_title) { "__OLD TITLE__Source Ticket 1234" }
396
481
 
397
- it { expect(loader.source_ticket_link_needs_update?).to be_truthy }
482
+ it { expect(loader.send(:source_ticket_link_needs_update?)).to be_truthy }
398
483
  end
399
484
  end
400
485
 
@@ -412,7 +497,9 @@ module Ticket
412
497
  { "id" => 10_443, "self" => "https://url/to/source/ticket/123/remotelink/10443" } }
413
498
  end
414
499
 
415
- it("only checks the needed attributes") { expect(loader.source_ticket_link_needs_update?).to be_falsey }
500
+ it("only checks the needed attributes") {
501
+ expect(loader.send(:source_ticket_link_needs_update?)).to be_falsey
502
+ }
416
503
  end
417
504
  end
418
505
  end
@@ -428,7 +515,7 @@ module Ticket
428
515
  expect(loader).to receive(:ticket).at_least(:once).and_return(ticket)
429
516
  expect(ticket).to receive(:transition_to).with("Testing")
430
517
 
431
- loader.transition_ticket_to_the_expected_status
518
+ loader.send(:transition_ticket_to_the_expected_status)
432
519
  end
433
520
  end
434
521
  end