Skip to content

Commit

Permalink
fix: Only send out one document if author == maintainer
Browse files Browse the repository at this point in the history
  • Loading branch information
dploeger committed Jun 10, 2022
1 parent 0dfc1a9 commit 839a913
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/api/Notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions test/NotificationTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
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<Mail>).sendMail.calledOnce).to.be.true
chai.expect(
(transportStub as unknown as SinonStubbedInstance<Mail>).sendMail.calledWith({
from: 'Notification <[email protected]>',
to: '[email protected]',
subject: Handlebars.compile(MockServer.NOTIFICATION_SUBJECT)({
author: '[email protected]',
documentsCount: 1,
documents: [documentInfo],
multipleDocuments: false,
}),
html: Handlebars.compile(MockServer.NOTIFICATION_BODY)({
author: '[email protected]',
documentsCount: 1,
documents: [documentInfo],
multipleDocuments: false,
}),
})
).to.be.true
})
})

0 comments on commit 839a913

Please sign in to comment.