1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { inspect } from 'util'
9 UserNotificationSetting,
10 UserNotificationSettingValue,
12 } from '@shared/models'
14 createMultipleServers,
17 setAccessTokensToServers,
18 setDefaultAccountAvatar,
19 setDefaultChannelAvatar,
20 setDefaultVideoChannel
21 } from '@shared/server-commands'
22 import { MockSmtpServer } from './mock-servers'
24 type CheckerBaseParams = {
25 server: PeerTubeServer
27 socketNotifications: UserNotification[]
29 check?: { web: boolean, mail: boolean }
32 type CheckerType = 'presence' | 'absence'
34 function getAllNotificationsSettings (): UserNotificationSetting {
36 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
37 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
38 abuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
39 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
40 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
41 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
42 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
43 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
44 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
45 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
46 newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
47 abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
48 abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
49 autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
50 newPeerTubeVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
51 myVideoStudioEditionFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
52 newPluginVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
56 async function checkNewVideoFromSubscription (options: CheckerBaseParams & {
59 checkType: CheckerType
61 const { videoName, shortUUID } = options
62 const notificationType = UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION
64 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
65 if (checkType === 'presence') {
66 expect(notification).to.not.be.undefined
67 expect(notification.type).to.equal(notificationType)
69 checkVideo(notification.video, videoName, shortUUID)
70 checkActor(notification.video.channel)
72 expect(notification).to.satisfy((n: UserNotification) => {
73 return n === undefined || n.type !== UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION || n.video.name !== videoName
78 function emailNotificationFinder (email: object) {
79 const text = email['text']
80 return text.indexOf(shortUUID) !== -1 && text.indexOf('Your subscription') !== -1
83 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
86 async function checkVideoIsPublished (options: CheckerBaseParams & {
89 checkType: CheckerType
91 const { videoName, shortUUID } = options
92 const notificationType = UserNotificationType.MY_VIDEO_PUBLISHED
94 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
95 if (checkType === 'presence') {
96 expect(notification).to.not.be.undefined
97 expect(notification.type).to.equal(notificationType)
99 checkVideo(notification.video, videoName, shortUUID)
100 checkActor(notification.video.channel)
102 expect(notification.video).to.satisfy(v => v === undefined || v.name !== videoName)
106 function emailNotificationFinder (email: object) {
107 const text: string = email['text']
108 return text.includes(shortUUID) && text.includes('Your video')
111 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
114 async function checkVideoStudioEditionIsFinished (options: CheckerBaseParams & {
117 checkType: CheckerType
119 const { videoName, shortUUID } = options
120 const notificationType = UserNotificationType.MY_VIDEO_STUDIO_EDITION_FINISHED
122 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
123 if (checkType === 'presence') {
124 expect(notification).to.not.be.undefined
125 expect(notification.type).to.equal(notificationType)
127 checkVideo(notification.video, videoName, shortUUID)
128 checkActor(notification.video.channel)
130 expect(notification.video).to.satisfy(v => v === undefined || v.name !== videoName)
134 function emailNotificationFinder (email: object) {
135 const text: string = email['text']
136 return text.includes(shortUUID) && text.includes('Edition of your video')
139 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
142 async function checkMyVideoImportIsFinished (options: CheckerBaseParams & {
147 checkType: CheckerType
149 const { videoName, shortUUID, url, success } = options
151 const notificationType = success ? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS : UserNotificationType.MY_VIDEO_IMPORT_ERROR
153 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
154 if (checkType === 'presence') {
155 expect(notification).to.not.be.undefined
156 expect(notification.type).to.equal(notificationType)
158 expect(notification.videoImport.targetUrl).to.equal(url)
160 if (success) checkVideo(notification.videoImport.video, videoName, shortUUID)
162 expect(notification.videoImport).to.satisfy(i => i === undefined || i.targetUrl !== url)
166 function emailNotificationFinder (email: object) {
167 const text: string = email['text']
168 const toFind = success ? ' finished' : ' error'
170 return text.includes(url) && text.includes(toFind)
173 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
176 async function checkUserRegistered (options: CheckerBaseParams & {
178 checkType: CheckerType
180 const { username } = options
181 const notificationType = UserNotificationType.NEW_USER_REGISTRATION
183 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
184 if (checkType === 'presence') {
185 expect(notification).to.not.be.undefined
186 expect(notification.type).to.equal(notificationType)
188 checkActor(notification.account)
189 expect(notification.account.name).to.equal(username)
191 expect(notification).to.satisfy(n => n.type !== notificationType || n.account.name !== username)
195 function emailNotificationFinder (email: object) {
196 const text: string = email['text']
198 return text.includes(' registered.') && text.includes(username)
201 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
204 async function checkNewActorFollow (options: CheckerBaseParams & {
205 followType: 'channel' | 'account'
207 followerDisplayName: string
208 followingDisplayName: string
209 checkType: CheckerType
211 const { followType, followerName, followerDisplayName, followingDisplayName } = options
212 const notificationType = UserNotificationType.NEW_FOLLOW
214 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
215 if (checkType === 'presence') {
216 expect(notification).to.not.be.undefined
217 expect(notification.type).to.equal(notificationType)
219 checkActor(notification.actorFollow.follower)
220 expect(notification.actorFollow.follower.displayName).to.equal(followerDisplayName)
221 expect(notification.actorFollow.follower.name).to.equal(followerName)
222 expect(notification.actorFollow.follower.host).to.not.be.undefined
224 const following = notification.actorFollow.following
225 expect(following.displayName).to.equal(followingDisplayName)
226 expect(following.type).to.equal(followType)
228 expect(notification).to.satisfy(n => {
229 return n.type !== notificationType ||
230 (n.actorFollow.follower.name !== followerName && n.actorFollow.following !== followingDisplayName)
235 function emailNotificationFinder (email: object) {
236 const text: string = email['text']
238 return text.includes(followType) && text.includes(followingDisplayName) && text.includes(followerDisplayName)
241 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
244 async function checkNewInstanceFollower (options: CheckerBaseParams & {
246 checkType: CheckerType
248 const { followerHost } = options
249 const notificationType = UserNotificationType.NEW_INSTANCE_FOLLOWER
251 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
252 if (checkType === 'presence') {
253 expect(notification).to.not.be.undefined
254 expect(notification.type).to.equal(notificationType)
256 checkActor(notification.actorFollow.follower)
257 expect(notification.actorFollow.follower.name).to.equal('peertube')
258 expect(notification.actorFollow.follower.host).to.equal(followerHost)
260 expect(notification.actorFollow.following.name).to.equal('peertube')
262 expect(notification).to.satisfy(n => {
263 return n.type !== notificationType || n.actorFollow.follower.host !== followerHost
268 function emailNotificationFinder (email: object) {
269 const text: string = email['text']
271 return text.includes('instance has a new follower') && text.includes(followerHost)
274 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
277 async function checkAutoInstanceFollowing (options: CheckerBaseParams & {
279 followingHost: string
280 checkType: CheckerType
282 const { followerHost, followingHost } = options
283 const notificationType = UserNotificationType.AUTO_INSTANCE_FOLLOWING
285 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
286 if (checkType === 'presence') {
287 expect(notification).to.not.be.undefined
288 expect(notification.type).to.equal(notificationType)
290 const following = notification.actorFollow.following
291 checkActor(following)
292 expect(following.name).to.equal('peertube')
293 expect(following.host).to.equal(followingHost)
295 expect(notification.actorFollow.follower.name).to.equal('peertube')
296 expect(notification.actorFollow.follower.host).to.equal(followerHost)
298 expect(notification).to.satisfy(n => {
299 return n.type !== notificationType || n.actorFollow.following.host !== followingHost
304 function emailNotificationFinder (email: object) {
305 const text: string = email['text']
307 return text.includes(' automatically followed a new instance') && text.includes(followingHost)
310 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
313 async function checkCommentMention (options: CheckerBaseParams & {
317 byAccountDisplayName: string
318 checkType: CheckerType
320 const { shortUUID, commentId, threadId, byAccountDisplayName } = options
321 const notificationType = UserNotificationType.COMMENT_MENTION
323 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
324 if (checkType === 'presence') {
325 expect(notification).to.not.be.undefined
326 expect(notification.type).to.equal(notificationType)
328 checkComment(notification.comment, commentId, threadId)
329 checkActor(notification.comment.account)
330 expect(notification.comment.account.displayName).to.equal(byAccountDisplayName)
332 checkVideo(notification.comment.video, undefined, shortUUID)
334 expect(notification).to.satisfy(n => n.type !== notificationType || n.comment.id !== commentId)
338 function emailNotificationFinder (email: object) {
339 const text: string = email['text']
341 return text.includes(' mentioned ') && text.includes(shortUUID) && text.includes(byAccountDisplayName)
344 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
347 let lastEmailCount = 0
349 async function checkNewCommentOnMyVideo (options: CheckerBaseParams & {
353 checkType: CheckerType
355 const { server, shortUUID, commentId, threadId, checkType, emails } = options
356 const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO
358 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
359 if (checkType === 'presence') {
360 expect(notification).to.not.be.undefined
361 expect(notification.type).to.equal(notificationType)
363 checkComment(notification.comment, commentId, threadId)
364 checkActor(notification.comment.account)
365 checkVideo(notification.comment.video, undefined, shortUUID)
367 expect(notification).to.satisfy((n: UserNotification) => {
368 return n === undefined || n.comment === undefined || n.comment.id !== commentId
373 const commentUrl = `http://localhost:${server.port}/w/${shortUUID};threadId=${threadId}`
375 function emailNotificationFinder (email: object) {
376 return email['text'].indexOf(commentUrl) !== -1
379 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
381 if (checkType === 'presence') {
382 // We cannot detect email duplicates, so check we received another email
383 expect(emails).to.have.length.above(lastEmailCount)
384 lastEmailCount = emails.length
388 async function checkNewVideoAbuseForModerators (options: CheckerBaseParams & {
391 checkType: CheckerType
393 const { shortUUID, videoName } = options
394 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
396 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
397 if (checkType === 'presence') {
398 expect(notification).to.not.be.undefined
399 expect(notification.type).to.equal(notificationType)
401 expect(notification.abuse.id).to.be.a('number')
402 checkVideo(notification.abuse.video, videoName, shortUUID)
404 expect(notification).to.satisfy((n: UserNotification) => {
405 return n === undefined || n.abuse === undefined || n.abuse.video.shortUUID !== shortUUID
410 function emailNotificationFinder (email: object) {
411 const text = email['text']
412 return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1
415 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
418 async function checkNewAbuseMessage (options: CheckerBaseParams & {
422 checkType: CheckerType
424 const { abuseId, message, toEmail } = options
425 const notificationType = UserNotificationType.ABUSE_NEW_MESSAGE
427 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
428 if (checkType === 'presence') {
429 expect(notification).to.not.be.undefined
430 expect(notification.type).to.equal(notificationType)
432 expect(notification.abuse.id).to.equal(abuseId)
434 expect(notification).to.satisfy((n: UserNotification) => {
435 return n === undefined || n.type !== notificationType || n.abuse === undefined || n.abuse.id !== abuseId
440 function emailNotificationFinder (email: object) {
441 const text = email['text']
442 const to = email['to'].filter(t => t.address === toEmail)
444 return text.indexOf(message) !== -1 && to.length !== 0
447 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
450 async function checkAbuseStateChange (options: CheckerBaseParams & {
453 checkType: CheckerType
455 const { abuseId, state } = options
456 const notificationType = UserNotificationType.ABUSE_STATE_CHANGE
458 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
459 if (checkType === 'presence') {
460 expect(notification).to.not.be.undefined
461 expect(notification.type).to.equal(notificationType)
463 expect(notification.abuse.id).to.equal(abuseId)
464 expect(notification.abuse.state).to.equal(state)
466 expect(notification).to.satisfy((n: UserNotification) => {
467 return n === undefined || n.abuse === undefined || n.abuse.id !== abuseId
472 function emailNotificationFinder (email: object) {
473 const text = email['text']
475 const contains = state === AbuseState.ACCEPTED
479 return text.indexOf(contains) !== -1
482 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
485 async function checkNewCommentAbuseForModerators (options: CheckerBaseParams & {
488 checkType: CheckerType
490 const { shortUUID, videoName } = options
491 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
493 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
494 if (checkType === 'presence') {
495 expect(notification).to.not.be.undefined
496 expect(notification.type).to.equal(notificationType)
498 expect(notification.abuse.id).to.be.a('number')
499 checkVideo(notification.abuse.comment.video, videoName, shortUUID)
501 expect(notification).to.satisfy((n: UserNotification) => {
502 return n === undefined || n.abuse === undefined || n.abuse.comment.video.shortUUID !== shortUUID
507 function emailNotificationFinder (email: object) {
508 const text = email['text']
509 return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1
512 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
515 async function checkNewAccountAbuseForModerators (options: CheckerBaseParams & {
517 checkType: CheckerType
519 const { displayName } = options
520 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
522 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
523 if (checkType === 'presence') {
524 expect(notification).to.not.be.undefined
525 expect(notification.type).to.equal(notificationType)
527 expect(notification.abuse.id).to.be.a('number')
528 expect(notification.abuse.account.displayName).to.equal(displayName)
530 expect(notification).to.satisfy((n: UserNotification) => {
531 return n === undefined || n.abuse === undefined || n.abuse.account.displayName !== displayName
536 function emailNotificationFinder (email: object) {
537 const text = email['text']
538 return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1
541 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
544 async function checkVideoAutoBlacklistForModerators (options: CheckerBaseParams & {
547 checkType: CheckerType
549 const { shortUUID, videoName } = options
550 const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS
552 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
553 if (checkType === 'presence') {
554 expect(notification).to.not.be.undefined
555 expect(notification.type).to.equal(notificationType)
557 expect(notification.videoBlacklist.video.id).to.be.a('number')
558 checkVideo(notification.videoBlacklist.video, videoName, shortUUID)
560 expect(notification).to.satisfy((n: UserNotification) => {
561 return n === undefined || n.video === undefined || n.video.shortUUID !== shortUUID
566 function emailNotificationFinder (email: object) {
567 const text = email['text']
568 return text.indexOf(shortUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1
571 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
574 async function checkNewBlacklistOnMyVideo (options: CheckerBaseParams & {
577 blacklistType: 'blacklist' | 'unblacklist'
579 const { videoName, shortUUID, blacklistType } = options
580 const notificationType = blacklistType === 'blacklist'
581 ? UserNotificationType.BLACKLIST_ON_MY_VIDEO
582 : UserNotificationType.UNBLACKLIST_ON_MY_VIDEO
584 function notificationChecker (notification: UserNotification) {
585 expect(notification).to.not.be.undefined
586 expect(notification.type).to.equal(notificationType)
588 const video = blacklistType === 'blacklist' ? notification.videoBlacklist.video : notification.video
590 checkVideo(video, videoName, shortUUID)
593 function emailNotificationFinder (email: object) {
594 const text = email['text']
595 const blacklistText = blacklistType === 'blacklist'
599 return text.includes(shortUUID) && text.includes(blacklistText)
602 await checkNotification({ ...options, notificationChecker, emailNotificationFinder, checkType: 'presence' })
605 async function checkNewPeerTubeVersion (options: CheckerBaseParams & {
606 latestVersion: string
607 checkType: CheckerType
609 const { latestVersion } = options
610 const notificationType = UserNotificationType.NEW_PEERTUBE_VERSION
612 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
613 if (checkType === 'presence') {
614 expect(notification).to.not.be.undefined
615 expect(notification.type).to.equal(notificationType)
617 expect(notification.peertube).to.exist
618 expect(notification.peertube.latestVersion).to.equal(latestVersion)
620 expect(notification).to.satisfy((n: UserNotification) => {
621 return n === undefined || n.peertube === undefined || n.peertube.latestVersion !== latestVersion
626 function emailNotificationFinder (email: object) {
627 const text = email['text']
629 return text.includes(latestVersion)
632 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
635 async function checkNewPluginVersion (options: CheckerBaseParams & {
636 pluginType: PluginType
638 checkType: CheckerType
640 const { pluginName, pluginType } = options
641 const notificationType = UserNotificationType.NEW_PLUGIN_VERSION
643 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
644 if (checkType === 'presence') {
645 expect(notification).to.not.be.undefined
646 expect(notification.type).to.equal(notificationType)
648 expect(notification.plugin.name).to.equal(pluginName)
649 expect(notification.plugin.type).to.equal(pluginType)
651 expect(notification).to.satisfy((n: UserNotification) => {
652 return n === undefined || n.plugin === undefined || n.plugin.name !== pluginName
657 function emailNotificationFinder (email: object) {
658 const text = email['text']
660 return text.includes(pluginName)
663 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
666 async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) {
667 const userNotifications: UserNotification[] = []
668 const adminNotifications: UserNotification[] = []
669 const adminNotificationsServer2: UserNotification[] = []
670 const emails: object[] = []
672 const port = await MockSmtpServer.Instance.collectEmails(emails)
674 const overrideConfig = {
676 hostname: 'localhost',
683 const servers = await createMultipleServers(serversCount, Object.assign(overrideConfig, overrideConfigArg))
685 await setAccessTokensToServers(servers)
686 await setDefaultVideoChannel(servers)
687 await setDefaultChannelAvatar(servers)
688 await setDefaultAccountAvatar(servers)
691 await servers[1].config.enableStudio()
692 await servers[1].config.enableLive({ allowReplay: true, transcoding: false })
695 if (serversCount > 1) {
696 await doubleFollow(servers[0], servers[1])
699 const user = { username: 'user_1', password: 'super password' }
700 await servers[0].users.create({ ...user, videoQuota: 10 * 1000 * 1000 })
701 const userAccessToken = await servers[0].login.getAccessToken(user)
703 await servers[0].notifications.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() })
704 await servers[0].notifications.updateMySettings({ settings: getAllNotificationsSettings() })
706 if (serversCount > 1) {
707 await servers[1].notifications.updateMySettings({ settings: getAllNotificationsSettings() })
711 const socket = servers[0].socketIO.getUserNotificationSocket({ token: userAccessToken })
712 socket.on('new-notification', n => userNotifications.push(n))
715 const socket = servers[0].socketIO.getUserNotificationSocket()
716 socket.on('new-notification', n => adminNotifications.push(n))
719 if (serversCount > 1) {
720 const socket = servers[1].socketIO.getUserNotificationSocket()
721 socket.on('new-notification', n => adminNotificationsServer2.push(n))
724 const { videoChannels } = await servers[0].users.getMyInfo()
725 const channelId = videoChannels[0].id
730 adminNotificationsServer2,
738 // ---------------------------------------------------------------------------
741 getAllNotificationsSettings,
745 checkMyVideoImportIsFinished,
747 checkAutoInstanceFollowing,
748 checkVideoIsPublished,
749 checkNewVideoFromSubscription,
751 checkNewCommentOnMyVideo,
752 checkNewBlacklistOnMyVideo,
754 checkNewVideoAbuseForModerators,
755 checkVideoAutoBlacklistForModerators,
756 checkNewAbuseMessage,
757 checkAbuseStateChange,
758 checkNewInstanceFollower,
759 prepareNotificationsTest,
760 checkNewCommentAbuseForModerators,
761 checkNewAccountAbuseForModerators,
762 checkNewPeerTubeVersion,
763 checkNewPluginVersion,
764 checkVideoStudioEditionIsFinished
767 // ---------------------------------------------------------------------------
769 async function checkNotification (options: CheckerBaseParams & {
770 notificationChecker: (notification: UserNotification, checkType: CheckerType) => void
771 emailNotificationFinder: (email: object) => boolean
772 checkType: CheckerType
774 const { server, token, checkType, notificationChecker, emailNotificationFinder, socketNotifications, emails } = options
776 const check = options.check || { web: true, mail: true }
779 const notification = await server.notifications.getLatest({ token: token })
781 if (notification || checkType !== 'absence') {
782 notificationChecker(notification, checkType)
785 const socketNotification = socketNotifications.find(n => {
787 notificationChecker(n, 'presence')
794 if (checkType === 'presence') {
795 const obj = inspect(socketNotifications, { depth: 5 })
796 expect(socketNotification, 'The socket notification is absent when it should be present. ' + obj).to.not.be.undefined
798 const obj = inspect(socketNotification, { depth: 5 })
799 expect(socketNotification, 'The socket notification is present when it should not be present. ' + obj).to.be.undefined
808 .find(e => emailNotificationFinder(e))
810 if (checkType === 'presence') {
811 const texts = emails.map(e => e.text)
812 expect(email, 'The email is absent when is should be present. ' + inspect(texts)).to.not.be.undefined
814 expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined
819 function checkVideo (video: any, videoName?: string, shortUUID?: string) {
821 expect(video.name).to.be.a('string')
822 expect(video.name).to.not.be.empty
823 expect(video.name).to.equal(videoName)
827 expect(video.shortUUID).to.be.a('string')
828 expect(video.shortUUID).to.not.be.empty
829 expect(video.shortUUID).to.equal(shortUUID)
832 expect(video.id).to.be.a('number')
835 function checkActor (actor: any) {
836 expect(actor.displayName).to.be.a('string')
837 expect(actor.displayName).to.not.be.empty
838 expect(actor.host).to.not.be.undefined
841 function checkComment (comment: any, commentId: number, threadId: number) {
842 expect(comment.id).to.equal(commentId)
843 expect(comment.threadId).to.equal(threadId)