Skip to content

Commit 839a913

Browse files
committed
fix: Only send out one document if author == maintainer
1 parent 0dfc1a9 commit 839a913

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/api/Notification.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ export class Notification {
5959
this._notificationBatch[recipient] = []
6060
}
6161

62-
this._notificationBatch[recipient].push(documentInfo)
62+
if (!this._notificationBatch[recipient].some((docInfo) => docInfo === documentInfo)) {
63+
this._notificationBatch[recipient].push(documentInfo)
64+
}
6365
}
6466
}
6567

test/NotificationTest.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,28 @@ describe('The Notification API', (): void => {
134134
})
135135
).to.be.true
136136
})
137+
it('should not send both documents when the maintainer is the author', async (): Promise<void> => {
138+
const notification = new Notification(configuration, '', confluence, transportStub)
139+
const documentInfo = new DocumentInfo(0, 'maintainer', moment(), 'message', 'Test2', ['main', 'Test'], 'http://example.com', 'test')
140+
await notification.notify([documentInfo])
141+
chai.expect((transportStub as unknown as SinonStubbedInstance<Mail>).sendMail.calledOnce).to.be.true
142+
chai.expect(
143+
(transportStub as unknown as SinonStubbedInstance<Mail>).sendMail.calledWith({
144+
from: 'Notification <[email protected]>',
145+
146+
subject: Handlebars.compile(MockServer.NOTIFICATION_SUBJECT)({
147+
author: '[email protected]',
148+
documentsCount: 1,
149+
documents: [documentInfo],
150+
multipleDocuments: false,
151+
}),
152+
html: Handlebars.compile(MockServer.NOTIFICATION_BODY)({
153+
author: '[email protected]',
154+
documentsCount: 1,
155+
documents: [documentInfo],
156+
multipleDocuments: false,
157+
}),
158+
})
159+
).to.be.true
160+
})
137161
})

0 commit comments

Comments
 (0)