From 839a9130495eec93da40952d67f81904d7e1d34f Mon Sep 17 00:00:00 2001 From: Dennis Ploeger Date: Fri, 10 Jun 2022 09:59:12 +0200 Subject: [PATCH] fix: Only send out one document if author == maintainer --- lib/api/Notification.ts | 4 +++- test/NotificationTest.ts | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/api/Notification.ts b/lib/api/Notification.ts index 8190561..81584ee 100644 --- a/lib/api/Notification.ts +++ b/lib/api/Notification.ts @@ -59,7 +59,9 @@ export class Notification { this._notificationBatch[recipient] = [] } - this._notificationBatch[recipient].push(documentInfo) + if (!this._notificationBatch[recipient].some((docInfo) => docInfo === documentInfo)) { + this._notificationBatch[recipient].push(documentInfo) + } } } diff --git a/test/NotificationTest.ts b/test/NotificationTest.ts index 347ad31..dc843f0 100644 --- a/test/NotificationTest.ts +++ b/test/NotificationTest.ts @@ -134,4 +134,28 @@ describe('The Notification API', (): void => { }) ).to.be.true }) + it('should not send both documents when the maintainer is the author', async (): Promise => { + const notification = new Notification(configuration, '', confluence, transportStub) + const documentInfo = new DocumentInfo(0, 'maintainer', moment(), 'message', 'Test2', ['main', 'Test'], 'http://example.com', 'test') + await notification.notify([documentInfo]) + chai.expect((transportStub as unknown as SinonStubbedInstance).sendMail.calledOnce).to.be.true + chai.expect( + (transportStub as unknown as SinonStubbedInstance).sendMail.calledWith({ + from: 'Notification ', + to: 'maintainer@example.com', + subject: Handlebars.compile(MockServer.NOTIFICATION_SUBJECT)({ + author: 'maintainer@example.com', + documentsCount: 1, + documents: [documentInfo], + multipleDocuments: false, + }), + html: Handlebars.compile(MockServer.NOTIFICATION_BODY)({ + author: 'maintainer@example.com', + documentsCount: 1, + documents: [documentInfo], + multipleDocuments: false, + }), + }) + ).to.be.true + }) })