@@ -16,6 +16,7 @@ describe('lib/calculate-label-diff', () => {
16
16
describe ( 'calculateLabelDiff(currentLabels, configuredLabels)' , ( ) => {
17
17
let configuredLabels ;
18
18
let currentLabels ;
19
+ let allowAddedLabels ;
19
20
let diff ;
20
21
21
22
it ( 'should return an array' , function ( ) {
@@ -47,7 +48,25 @@ describe('lib/calculate-label-diff', () => {
47
48
}
48
49
} ) ;
49
50
} ) ;
51
+ } ) ;
52
+
53
+ describe ( 'when a configured label set to delete does not exist in the current labels' , ( ) => {
50
54
55
+ beforeEach ( ( ) => {
56
+ currentLabels = [ ] ;
57
+ configuredLabels = [
58
+ {
59
+ name : 'bar' ,
60
+ color : '00ff00' ,
61
+ delete : true
62
+ }
63
+ ] ;
64
+ diff = calculateLabelDiff ( currentLabels , configuredLabels ) ;
65
+ } ) ;
66
+
67
+ it ( 'should not add a "missing" entry to the returned diff' , ( ) => {
68
+ assert . lengthEquals ( diff , 0 ) ;
69
+ } ) ;
51
70
} ) ;
52
71
53
72
describe ( 'when a configured label with description does not exist in the current labels' , ( ) => {
@@ -142,6 +161,39 @@ describe('lib/calculate-label-diff', () => {
142
161
143
162
} ) ;
144
163
164
+ describe ( 'when a configured label exists in the current labels and is marked for deletion' , ( ) => {
165
+
166
+ beforeEach ( ( ) => {
167
+ currentLabels = [
168
+ {
169
+ name : 'foo' ,
170
+ color : 'ff0000' ,
171
+ }
172
+ ] ;
173
+ configuredLabels = [
174
+ {
175
+ name : 'foo' ,
176
+ delete : true
177
+ }
178
+ ] ;
179
+ diff = calculateLabelDiff ( currentLabels , configuredLabels ) ;
180
+ } ) ;
181
+
182
+ it ( 'should add an "added" entry to the returned diff' , ( ) => {
183
+ assert . lengthEquals ( diff , 1 ) ;
184
+ assert . deepEqual ( diff [ 0 ] , {
185
+ name : 'foo' ,
186
+ type : 'added' ,
187
+ actual : {
188
+ name : 'foo' ,
189
+ color : 'ff0000' ,
190
+ } ,
191
+ expected : null
192
+ } ) ;
193
+ } ) ;
194
+
195
+ } ) ;
196
+
145
197
describe ( 'when a configured label with description exists in the current labels without description' , ( ) => {
146
198
147
199
beforeEach ( ( ) => {
@@ -436,62 +488,158 @@ describe('lib/calculate-label-diff', () => {
436
488
437
489
} ) ;
438
490
439
- describe ( 'when a current label does not exist in the configured labels' , ( ) => {
440
-
491
+ describe ( 'when allowAddedLabels is false' , ( ) => {
441
492
beforeEach ( ( ) => {
442
- currentLabels = [
443
- {
444
- name : 'foo' ,
445
- color : 'ff0000'
446
- }
447
- ] ;
448
- configuredLabels = [ ] ;
449
- diff = calculateLabelDiff ( currentLabels , configuredLabels ) ;
493
+ allowAddedLabels = false ;
450
494
} ) ;
451
495
452
- it ( 'should add an "added" entry to the returned diff' , ( ) => {
453
- assert . lengthEquals ( diff , 1 ) ;
454
- assert . deepEqual ( diff [ 0 ] , {
455
- name : 'foo' ,
456
- type : 'added' ,
457
- actual : {
496
+ describe ( 'when a current label does not exist in the configured labels' , ( ) => {
497
+
498
+ beforeEach ( ( ) => {
499
+ currentLabels = [
500
+ {
501
+ name : 'foo' ,
502
+ color : 'ff0000'
503
+ }
504
+ ] ;
505
+ configuredLabels = [ ] ;
506
+ diff = calculateLabelDiff ( currentLabels , configuredLabels , allowAddedLabels ) ;
507
+ } ) ;
508
+
509
+ it ( 'should add an "added" entry to the returned diff' , ( ) => {
510
+ assert . lengthEquals ( diff , 1 ) ;
511
+ assert . deepEqual ( diff [ 0 ] , {
458
512
name : 'foo' ,
459
- color : 'ff0000'
460
- } ,
461
- expected : null
513
+ type : 'added' ,
514
+ actual : {
515
+ name : 'foo' ,
516
+ color : 'ff0000'
517
+ } ,
518
+ expected : null
519
+ } ) ;
462
520
} ) ;
521
+
522
+ } ) ;
523
+
524
+ describe ( 'when a current label with description does not exist in the configured labels' , ( ) => {
525
+
526
+ beforeEach ( ( ) => {
527
+ currentLabels = [
528
+ {
529
+ name : 'foo' ,
530
+ color : 'ff0000' ,
531
+ description : 'bar'
532
+ }
533
+ ] ;
534
+ configuredLabels = [ ] ;
535
+ diff = calculateLabelDiff ( currentLabels , configuredLabels , allowAddedLabels ) ;
536
+ } ) ;
537
+
538
+ it ( 'should add an "added" entry to the returned diff' , ( ) => {
539
+ assert . lengthEquals ( diff , 1 ) ;
540
+ assert . deepEqual ( diff [ 0 ] , {
541
+ name : 'foo' ,
542
+ type : 'added' ,
543
+ actual : {
544
+ name : 'foo' ,
545
+ color : 'ff0000' ,
546
+ description : 'bar'
547
+ } ,
548
+ expected : null
549
+ } ) ;
550
+ } ) ;
551
+
463
552
} ) ;
464
-
465
553
} ) ;
466
554
467
- describe ( 'when a current label with description does not exist in the configured labels' , ( ) => {
468
-
555
+ describe ( 'when allowAddedLabels is true' , ( ) => {
469
556
beforeEach ( ( ) => {
470
- currentLabels = [
471
- {
472
- name : 'foo' ,
473
- color : 'ff0000' ,
474
- description : 'bar'
475
- }
476
- ] ;
477
- configuredLabels = [ ] ;
478
- diff = calculateLabelDiff ( currentLabels , configuredLabels ) ;
557
+ allowAddedLabels = true ;
479
558
} ) ;
480
559
481
- it ( 'should add an "added" entry to the returned diff' , ( ) => {
482
- assert . lengthEquals ( diff , 1 ) ;
483
- assert . deepEqual ( diff [ 0 ] , {
484
- name : 'foo' ,
485
- type : 'added' ,
486
- actual : {
560
+ describe ( 'when a current label does not exist in the configured labels' , ( ) => {
561
+ beforeEach ( ( ) => {
562
+ currentLabels = [
563
+ {
564
+ name : 'foo' ,
565
+ color : 'ff0000'
566
+ }
567
+ ] ;
568
+ configuredLabels = [ ] ;
569
+ diff = calculateLabelDiff ( currentLabels , configuredLabels , allowAddedLabels ) ;
570
+ } ) ;
571
+
572
+ it ( 'should not add an "added" entry to the returned diff' , ( ) => {
573
+ assert . lengthEquals ( diff , 0 ) ;
574
+ } ) ;
575
+ } ) ;
576
+
577
+ describe ( 'when a current label is marked for deletion in the configured labels' , ( ) => {
578
+ beforeEach ( ( ) => {
579
+ currentLabels = [
580
+ {
581
+ name : 'foo' ,
582
+ color : 'ff0000' ,
583
+ }
584
+ ] ;
585
+ configuredLabels = [
586
+ {
587
+ name : 'foo' ,
588
+ delete : true ,
589
+ }
590
+ ] ;
591
+ diff = calculateLabelDiff ( currentLabels , configuredLabels , allowAddedLabels ) ;
592
+ } ) ;
593
+
594
+ it ( 'should add an "added" entry to the returned diff' , ( ) => {
595
+ assert . lengthEquals ( diff , 1 ) ;
596
+ assert . deepEqual ( diff [ 0 ] , {
487
597
name : 'foo' ,
488
- color : 'ff0000' ,
489
- description : 'bar'
490
- } ,
491
- expected : null
598
+ type : 'added' ,
599
+ actual : {
600
+ name : 'foo' ,
601
+ color : 'ff0000'
602
+ } ,
603
+ expected : null
604
+ } ) ;
492
605
} ) ;
493
606
} ) ;
494
607
608
+ describe ( 'when a current label with description is marked for deletion in the configured labels' , ( ) => {
609
+
610
+ beforeEach ( ( ) => {
611
+ currentLabels = [
612
+ {
613
+ name : 'foo' ,
614
+ color : 'ff0000' ,
615
+ description : 'bar' ,
616
+ delete : true
617
+ }
618
+ ] ;
619
+ configuredLabels = [
620
+ {
621
+ name : 'foo' ,
622
+ delete : true ,
623
+ }
624
+ ] ;
625
+ diff = calculateLabelDiff ( currentLabels , configuredLabels , allowAddedLabels ) ;
626
+ } ) ;
627
+
628
+ it ( 'should add an "added" entry to the returned diff' , ( ) => {
629
+ assert . lengthEquals ( diff , 1 ) ;
630
+ assert . deepEqual ( diff [ 0 ] , {
631
+ name : 'foo' ,
632
+ type : 'added' ,
633
+ actual : {
634
+ name : 'foo' ,
635
+ color : 'ff0000' ,
636
+ description : 'bar'
637
+ } ,
638
+ expected : null
639
+ } ) ;
640
+ } ) ;
641
+
642
+ } ) ;
495
643
} ) ;
496
644
497
645
describe ( 'when a range of diffs are expected' , ( ) => {
@@ -583,4 +731,4 @@ describe('lib/calculate-label-diff', () => {
583
731
584
732
} ) ;
585
733
586
- } ) ;
734
+ } ) ;
0 commit comments