@@ -33,41 +33,97 @@ describe('The Notification API', (): void => {
33
33
it ( 'should send notifications' , async ( ) : Promise < void > => {
34
34
const notification = new Notification ( configuration , '' , confluence , transportStub )
35
35
const documentInfo = new DocumentInfo ( 0 , 'author' , moment ( ) , 'message' , 'title' , [ 'main' ] , 'http://example.com' )
36
- await notification . notify ( documentInfo )
36
+ await notification . notify ( [ documentInfo ] )
37
37
chai . expect ( ( transportStub as unknown as SinonStubbedInstance < Mail > ) . sendMail . calledOnce ) . to . be . true
38
38
chai . expect (
39
39
( transportStub as unknown as SinonStubbedInstance < Mail > ) . sendMail . calledWith ( {
40
40
from : 'Notification <noreply@example.com>' ,
41
41
to : 'author@example.com' ,
42
- subject : Handlebars . compile ( MockServer . NOTIFICATION_SUBJECT ) ( documentInfo ) ,
43
- html : Handlebars . compile ( MockServer . NOTIFICATION_BODY ) ( documentInfo ) ,
42
+ subject : Handlebars . compile ( MockServer . NOTIFICATION_SUBJECT ) ( {
43
+ documentsCount : 1 ,
44
+ documents : [ documentInfo ] ,
45
+ multipleDocuments : false ,
46
+ } ) ,
47
+ html : Handlebars . compile ( MockServer . NOTIFICATION_BODY ) ( {
48
+ documentsCount : 1 ,
49
+ documents : [ documentInfo ] ,
50
+ multipleDocuments : false ,
51
+ } ) ,
44
52
} )
45
53
) . to . be . true
46
54
} )
47
55
it ( 'should use a maintainer when configured' , async ( ) : Promise < void > => {
48
56
const notification = new Notification ( configuration , '' , confluence , transportStub )
49
57
const documentInfo = new DocumentInfo ( 0 , 'author2' , moment ( ) , 'message' , 'Test2' , [ 'main' , 'Test' ] , 'http://example.com' )
50
- await notification . notify ( documentInfo )
51
- chai . expect ( ( transportStub as unknown as SinonStubbedInstance < Mail > ) . sendMail . calledOnce ) . to . be . true
58
+ await notification . notify ( [ documentInfo ] )
59
+ chai . expect ( ( transportStub as unknown as SinonStubbedInstance < Mail > ) . sendMail . calledTwice ) . to . be . true
60
+ chai . expect (
61
+ ( transportStub as unknown as SinonStubbedInstance < Mail > ) . sendMail . calledWith ( {
62
+ from : 'Notification <noreply@example.com>' ,
63
+ to : 'maintainer@example.com' ,
64
+ subject : Handlebars . compile ( MockServer . NOTIFICATION_SUBJECT ) ( {
65
+ documentsCount : 1 ,
66
+ documents : [ documentInfo ] ,
67
+ multipleDocuments : false ,
68
+ } ) ,
69
+ html : Handlebars . compile ( MockServer . NOTIFICATION_BODY ) ( {
70
+ documentsCount : 1 ,
71
+ documents : [ documentInfo ] ,
72
+ multipleDocuments : false ,
73
+ } ) ,
74
+ } )
75
+ ) . to . be . true
52
76
chai . expect (
53
77
( transportStub as unknown as SinonStubbedInstance < Mail > ) . sendMail . calledWith ( {
54
78
from : 'Notification <noreply@example.com>' ,
55
- to : 'maintainer@example.com,author2@example.com' ,
56
- subject : Handlebars . compile ( MockServer . NOTIFICATION_SUBJECT ) ( documentInfo ) ,
57
- html : Handlebars . compile ( MockServer . NOTIFICATION_BODY ) ( documentInfo ) ,
79
+ to : 'author2@example.com' ,
80
+ subject : Handlebars . compile ( MockServer . NOTIFICATION_SUBJECT ) ( {
81
+ documentsCount : 1 ,
82
+ documents : [ documentInfo ] ,
83
+ multipleDocuments : false ,
84
+ } ) ,
85
+ html : Handlebars . compile ( MockServer . NOTIFICATION_BODY ) ( {
86
+ documentsCount : 1 ,
87
+ documents : [ documentInfo ] ,
88
+ multipleDocuments : false ,
89
+ } ) ,
58
90
} )
59
91
) . to . be . true
60
92
} )
61
93
it ( 'should not send notifications on a dry run' , async ( ) : Promise < void > => {
62
94
const notification = new Notification ( configuration , '' , confluence , transportStub , true )
63
95
const documentInfo = new DocumentInfo ( 0 , 'author' , moment ( ) , 'message' , 'title' , [ 'main' ] , 'http://example.com' )
64
- await notification . notify ( documentInfo )
96
+ await notification . notify ( [ documentInfo ] )
65
97
chai . expect ( ( transportStub as unknown as SinonStubbedInstance < Mail > ) . sendMail . notCalled ) . to . be . true
66
98
} )
67
99
it ( 'should not send notifications for an excluded document' , async ( ) : Promise < void > => {
68
100
const notification = new Notification ( configuration , '' , confluence , transportStub )
69
101
const documentInfo = new DocumentInfo ( 0 , 'author2' , moment ( ) , 'message' , 'NOT' , [ 'main' , 'Test' ] , 'http://example.com' )
70
- await notification . notify ( documentInfo )
102
+ await notification . notify ( [ documentInfo ] )
71
103
chai . expect ( ( transportStub as unknown as SinonStubbedInstance < Mail > ) . sendMail . calledOnce ) . to . be . false
72
104
} )
105
+
106
+ it ( 'should send notifications in a batch if configured' , async ( ) : Promise < void > => {
107
+ const notification = new Notification ( configuration , '' , confluence , transportStub )
108
+ const documentInfo = new DocumentInfo ( 0 , 'author' , moment ( ) , 'message' , 'title1' , [ 'main' ] , 'http://example.com' )
109
+ const documentInfo2 = new DocumentInfo ( 0 , 'author' , moment ( ) , 'message' , 'title2' , [ 'main' ] , 'http://example.com' )
110
+ await notification . notify ( [ documentInfo , documentInfo2 ] )
111
+ chai . expect ( ( transportStub as unknown as SinonStubbedInstance < Mail > ) . sendMail . calledOnce ) . to . be . true
112
+ chai . expect (
113
+ ( transportStub as unknown as SinonStubbedInstance < Mail > ) . sendMail . calledWith ( {
114
+ from : 'Notification <noreply@example.com>' ,
115
+ to : 'author@example.com' ,
116
+ subject : Handlebars . compile ( MockServer . NOTIFICATION_SUBJECT ) ( {
117
+ documentsCount : 2 ,
118
+ documents : [ documentInfo , documentInfo2 ] ,
119
+ multipleDocuments : true ,
120
+ } ) ,
121
+ html : Handlebars . compile ( MockServer . NOTIFICATION_BODY ) ( {
122
+ documentsCount : 2 ,
123
+ documents : [ documentInfo , documentInfo2 ] ,
124
+ multipleDocuments : true ,
125
+ } ) ,
126
+ } )
127
+ ) . to . be . true
128
+ } )
73
129
} )
0 commit comments