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 } from '@shared/server-commands'
21 import { MockSmtpServer } from './mock-servers'
23 type CheckerBaseParams = {
24 server: PeerTubeServer
26 socketNotifications: UserNotification[]
28 check?: { web: boolean, mail: boolean }
31 type CheckerType = 'presence' | 'absence'
33 function getAllNotificationsSettings (): UserNotificationSetting {
35 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
36 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
37 abuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
38 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
39 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
40 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
41 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
42 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
43 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
44 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
45 newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
46 abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
47 abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
48 autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
49 newPeerTubeVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
50 myVideoStudioEditionFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
51 newPluginVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
55 async function checkNewVideoFromSubscription (options: CheckerBaseParams & {
58 checkType: CheckerType
60 const { videoName, shortUUID } = options
61 const notificationType = UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION
63 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
64 if (checkType === 'presence') {
65 expect(notification).to.not.be.undefined
66 expect(notification.type).to.equal(notificationType)
68 checkVideo(notification.video, videoName, shortUUID)
69 checkActor(notification.video.channel)
71 expect(notification).to.satisfy((n: UserNotification) => {
72 return n === undefined || n.type !== UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION || n.video.name !== videoName
77 function emailNotificationFinder (email: object) {
78 const text = email['text']
79 return text.indexOf(shortUUID) !== -1 && text.indexOf('Your subscription') !== -1
82 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
85 async function checkVideoIsPublished (options: CheckerBaseParams & {
88 checkType: CheckerType
90 const { videoName, shortUUID } = options
91 const notificationType = UserNotificationType.MY_VIDEO_PUBLISHED
93 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
94 if (checkType === 'presence') {
95 expect(notification).to.not.be.undefined
96 expect(notification.type).to.equal(notificationType)
98 checkVideo(notification.video, videoName, shortUUID)
99 checkActor(notification.video.channel)
101 expect(notification.video).to.satisfy(v => v === undefined || v.name !== videoName)
105 function emailNotificationFinder (email: object) {
106 const text: string = email['text']
107 return text.includes(shortUUID) && text.includes('Your video')
110 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
113 async function checkVideoStudioEditionIsFinished (options: CheckerBaseParams & {
116 checkType: CheckerType
118 const { videoName, shortUUID } = options
119 const notificationType = UserNotificationType.MY_VIDEO_STUDIO_EDITION_FINISHED
121 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
122 if (checkType === 'presence') {
123 expect(notification).to.not.be.undefined
124 expect(notification.type).to.equal(notificationType)
126 checkVideo(notification.video, videoName, shortUUID)
127 checkActor(notification.video.channel)
129 expect(notification.video).to.satisfy(v => v === undefined || v.name !== videoName)
133 function emailNotificationFinder (email: object) {
134 const text: string = email['text']
135 return text.includes(shortUUID) && text.includes('Edition of your video')
138 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
141 async function checkMyVideoImportIsFinished (options: CheckerBaseParams & {
146 checkType: CheckerType
148 const { videoName, shortUUID, url, success } = options
150 const notificationType = success ? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS : UserNotificationType.MY_VIDEO_IMPORT_ERROR
152 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
153 if (checkType === 'presence') {
154 expect(notification).to.not.be.undefined
155 expect(notification.type).to.equal(notificationType)
157 expect(notification.videoImport.targetUrl).to.equal(url)
159 if (success) checkVideo(notification.videoImport.video, videoName, shortUUID)
161 expect(notification.videoImport).to.satisfy(i => i === undefined || i.targetUrl !== url)
165 function emailNotificationFinder (email: object) {
166 const text: string = email['text']
167 const toFind = success ? ' finished' : ' error'
169 return text.includes(url) && text.includes(toFind)
172 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
175 async function checkUserRegistered (options: CheckerBaseParams & {
177 checkType: CheckerType
179 const { username } = options
180 const notificationType = UserNotificationType.NEW_USER_REGISTRATION
182 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
183 if (checkType === 'presence') {
184 expect(notification).to.not.be.undefined
185 expect(notification.type).to.equal(notificationType)
187 checkActor(notification.account)
188 expect(notification.account.name).to.equal(username)
190 expect(notification).to.satisfy(n => n.type !== notificationType || n.account.name !== username)
194 function emailNotificationFinder (email: object) {
195 const text: string = email['text']
197 return text.includes(' registered.') && text.includes(username)
200 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
203 async function checkNewActorFollow (options: CheckerBaseParams & {
204 followType: 'channel' | 'account'
206 followerDisplayName: string
207 followingDisplayName: string
208 checkType: CheckerType
210 const { followType, followerName, followerDisplayName, followingDisplayName } = options
211 const notificationType = UserNotificationType.NEW_FOLLOW
213 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
214 if (checkType === 'presence') {
215 expect(notification).to.not.be.undefined
216 expect(notification.type).to.equal(notificationType)
218 checkActor(notification.actorFollow.follower)
219 expect(notification.actorFollow.follower.displayName).to.equal(followerDisplayName)
220 expect(notification.actorFollow.follower.name).to.equal(followerName)
221 expect(notification.actorFollow.follower.host).to.not.be.undefined
223 const following = notification.actorFollow.following
224 expect(following.displayName).to.equal(followingDisplayName)
225 expect(following.type).to.equal(followType)
227 expect(notification).to.satisfy(n => {
228 return n.type !== notificationType ||
229 (n.actorFollow.follower.name !== followerName && n.actorFollow.following !== followingDisplayName)
234 function emailNotificationFinder (email: object) {
235 const text: string = email['text']
237 return text.includes(followType) && text.includes(followingDisplayName) && text.includes(followerDisplayName)
240 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
243 async function checkNewInstanceFollower (options: CheckerBaseParams & {
245 checkType: CheckerType
247 const { followerHost } = options
248 const notificationType = UserNotificationType.NEW_INSTANCE_FOLLOWER
250 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
251 if (checkType === 'presence') {
252 expect(notification).to.not.be.undefined
253 expect(notification.type).to.equal(notificationType)
255 checkActor(notification.actorFollow.follower)
256 expect(notification.actorFollow.follower.name).to.equal('peertube')
257 expect(notification.actorFollow.follower.host).to.equal(followerHost)
259 expect(notification.actorFollow.following.name).to.equal('peertube')
261 expect(notification).to.satisfy(n => {
262 return n.type !== notificationType || n.actorFollow.follower.host !== followerHost
267 function emailNotificationFinder (email: object) {
268 const text: string = email['text']
270 return text.includes('instance has a new follower') && text.includes(followerHost)
273 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
276 async function checkAutoInstanceFollowing (options: CheckerBaseParams & {
278 followingHost: string
279 checkType: CheckerType
281 const { followerHost, followingHost } = options
282 const notificationType = UserNotificationType.AUTO_INSTANCE_FOLLOWING
284 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
285 if (checkType === 'presence') {
286 expect(notification).to.not.be.undefined
287 expect(notification.type).to.equal(notificationType)
289 const following = notification.actorFollow.following
290 checkActor(following)
291 expect(following.name).to.equal('peertube')
292 expect(following.host).to.equal(followingHost)
294 expect(notification.actorFollow.follower.name).to.equal('peertube')
295 expect(notification.actorFollow.follower.host).to.equal(followerHost)
297 expect(notification).to.satisfy(n => {
298 return n.type !== notificationType || n.actorFollow.following.host !== followingHost
303 function emailNotificationFinder (email: object) {
304 const text: string = email['text']
306 return text.includes(' automatically followed a new instance') && text.includes(followingHost)
309 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
312 async function checkCommentMention (options: CheckerBaseParams & {
316 byAccountDisplayName: string
317 checkType: CheckerType
319 const { shortUUID, commentId, threadId, byAccountDisplayName } = options
320 const notificationType = UserNotificationType.COMMENT_MENTION
322 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
323 if (checkType === 'presence') {
324 expect(notification).to.not.be.undefined
325 expect(notification.type).to.equal(notificationType)
327 checkComment(notification.comment, commentId, threadId)
328 checkActor(notification.comment.account)
329 expect(notification.comment.account.displayName).to.equal(byAccountDisplayName)
331 checkVideo(notification.comment.video, undefined, shortUUID)
333 expect(notification).to.satisfy(n => n.type !== notificationType || n.comment.id !== commentId)
337 function emailNotificationFinder (email: object) {
338 const text: string = email['text']
340 return text.includes(' mentioned ') && text.includes(shortUUID) && text.includes(byAccountDisplayName)
343 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
346 let lastEmailCount = 0
348 async function checkNewCommentOnMyVideo (options: CheckerBaseParams & {
352 checkType: CheckerType
354 const { server, shortUUID, commentId, threadId, checkType, emails } = options
355 const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO
357 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
358 if (checkType === 'presence') {
359 expect(notification).to.not.be.undefined
360 expect(notification.type).to.equal(notificationType)
362 checkComment(notification.comment, commentId, threadId)
363 checkActor(notification.comment.account)
364 checkVideo(notification.comment.video, undefined, shortUUID)
366 expect(notification).to.satisfy((n: UserNotification) => {
367 return n === undefined || n.comment === undefined || n.comment.id !== commentId
372 const commentUrl = `http://localhost:${server.port}/w/${shortUUID};threadId=${threadId}`
374 function emailNotificationFinder (email: object) {
375 return email['text'].indexOf(commentUrl) !== -1
378 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
380 if (checkType === 'presence') {
381 // We cannot detect email duplicates, so check we received another email
382 expect(emails).to.have.length.above(lastEmailCount)
383 lastEmailCount = emails.length
387 async function checkNewVideoAbuseForModerators (options: CheckerBaseParams & {
390 checkType: CheckerType
392 const { shortUUID, videoName } = options
393 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
395 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
396 if (checkType === 'presence') {
397 expect(notification).to.not.be.undefined
398 expect(notification.type).to.equal(notificationType)
400 expect(notification.abuse.id).to.be.a('number')
401 checkVideo(notification.abuse.video, videoName, shortUUID)
403 expect(notification).to.satisfy((n: UserNotification) => {
404 return n === undefined || n.abuse === undefined || n.abuse.video.shortUUID !== shortUUID
409 function emailNotificationFinder (email: object) {
410 const text = email['text']
411 return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1
414 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
417 async function checkNewAbuseMessage (options: CheckerBaseParams & {
421 checkType: CheckerType
423 const { abuseId, message, toEmail } = options
424 const notificationType = UserNotificationType.ABUSE_NEW_MESSAGE
426 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
427 if (checkType === 'presence') {
428 expect(notification).to.not.be.undefined
429 expect(notification.type).to.equal(notificationType)
431 expect(notification.abuse.id).to.equal(abuseId)
433 expect(notification).to.satisfy((n: UserNotification) => {
434 return n === undefined || n.type !== notificationType || n.abuse === undefined || n.abuse.id !== abuseId
439 function emailNotificationFinder (email: object) {
440 const text = email['text']
441 const to = email['to'].filter(t => t.address === toEmail)
443 return text.indexOf(message) !== -1 && to.length !== 0
446 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
449 async function checkAbuseStateChange (options: CheckerBaseParams & {
452 checkType: CheckerType
454 const { abuseId, state } = options
455 const notificationType = UserNotificationType.ABUSE_STATE_CHANGE
457 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
458 if (checkType === 'presence') {
459 expect(notification).to.not.be.undefined
460 expect(notification.type).to.equal(notificationType)
462 expect(notification.abuse.id).to.equal(abuseId)
463 expect(notification.abuse.state).to.equal(state)
465 expect(notification).to.satisfy((n: UserNotification) => {
466 return n === undefined || n.abuse === undefined || n.abuse.id !== abuseId
471 function emailNotificationFinder (email: object) {
472 const text = email['text']
474 const contains = state === AbuseState.ACCEPTED
478 return text.indexOf(contains) !== -1
481 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
484 async function checkNewCommentAbuseForModerators (options: CheckerBaseParams & {
487 checkType: CheckerType
489 const { shortUUID, videoName } = options
490 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
492 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
493 if (checkType === 'presence') {
494 expect(notification).to.not.be.undefined
495 expect(notification.type).to.equal(notificationType)
497 expect(notification.abuse.id).to.be.a('number')
498 checkVideo(notification.abuse.comment.video, videoName, shortUUID)
500 expect(notification).to.satisfy((n: UserNotification) => {
501 return n === undefined || n.abuse === undefined || n.abuse.comment.video.shortUUID !== shortUUID
506 function emailNotificationFinder (email: object) {
507 const text = email['text']
508 return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1
511 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
514 async function checkNewAccountAbuseForModerators (options: CheckerBaseParams & {
516 checkType: CheckerType
518 const { displayName } = options
519 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
521 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
522 if (checkType === 'presence') {
523 expect(notification).to.not.be.undefined
524 expect(notification.type).to.equal(notificationType)
526 expect(notification.abuse.id).to.be.a('number')
527 expect(notification.abuse.account.displayName).to.equal(displayName)
529 expect(notification).to.satisfy((n: UserNotification) => {
530 return n === undefined || n.abuse === undefined || n.abuse.account.displayName !== displayName
535 function emailNotificationFinder (email: object) {
536 const text = email['text']
537 return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1
540 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
543 async function checkVideoAutoBlacklistForModerators (options: CheckerBaseParams & {
546 checkType: CheckerType
548 const { shortUUID, videoName } = options
549 const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS
551 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
552 if (checkType === 'presence') {
553 expect(notification).to.not.be.undefined
554 expect(notification.type).to.equal(notificationType)
556 expect(notification.videoBlacklist.video.id).to.be.a('number')
557 checkVideo(notification.videoBlacklist.video, videoName, shortUUID)
559 expect(notification).to.satisfy((n: UserNotification) => {
560 return n === undefined || n.video === undefined || n.video.shortUUID !== shortUUID
565 function emailNotificationFinder (email: object) {
566 const text = email['text']
567 return text.indexOf(shortUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1
570 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
573 async function checkNewBlacklistOnMyVideo (options: CheckerBaseParams & {
576 blacklistType: 'blacklist' | 'unblacklist'
578 const { videoName, shortUUID, blacklistType } = options
579 const notificationType = blacklistType === 'blacklist'
580 ? UserNotificationType.BLACKLIST_ON_MY_VIDEO
581 : UserNotificationType.UNBLACKLIST_ON_MY_VIDEO
583 function notificationChecker (notification: UserNotification) {
584 expect(notification).to.not.be.undefined
585 expect(notification.type).to.equal(notificationType)
587 const video = blacklistType === 'blacklist' ? notification.videoBlacklist.video : notification.video
589 checkVideo(video, videoName, shortUUID)
592 function emailNotificationFinder (email: object) {
593 const text = email['text']
594 const blacklistText = blacklistType === 'blacklist'
598 return text.includes(shortUUID) && text.includes(blacklistText)
601 await checkNotification({ ...options, notificationChecker, emailNotificationFinder, checkType: 'presence' })
604 async function checkNewPeerTubeVersion (options: CheckerBaseParams & {
605 latestVersion: string
606 checkType: CheckerType
608 const { latestVersion } = options
609 const notificationType = UserNotificationType.NEW_PEERTUBE_VERSION
611 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
612 if (checkType === 'presence') {
613 expect(notification).to.not.be.undefined
614 expect(notification.type).to.equal(notificationType)
616 expect(notification.peertube).to.exist
617 expect(notification.peertube.latestVersion).to.equal(latestVersion)
619 expect(notification).to.satisfy((n: UserNotification) => {
620 return n === undefined || n.peertube === undefined || n.peertube.latestVersion !== latestVersion
625 function emailNotificationFinder (email: object) {
626 const text = email['text']
628 return text.includes(latestVersion)
631 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
634 async function checkNewPluginVersion (options: CheckerBaseParams & {
635 pluginType: PluginType
637 checkType: CheckerType
639 const { pluginName, pluginType } = options
640 const notificationType = UserNotificationType.NEW_PLUGIN_VERSION
642 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
643 if (checkType === 'presence') {
644 expect(notification).to.not.be.undefined
645 expect(notification.type).to.equal(notificationType)
647 expect(notification.plugin.name).to.equal(pluginName)
648 expect(notification.plugin.type).to.equal(pluginType)
650 expect(notification).to.satisfy((n: UserNotification) => {
651 return n === undefined || n.plugin === undefined || n.plugin.name !== pluginName
656 function emailNotificationFinder (email: object) {
657 const text = email['text']
659 return text.includes(pluginName)
662 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
665 async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) {
666 const userNotifications: UserNotification[] = []
667 const adminNotifications: UserNotification[] = []
668 const adminNotificationsServer2: UserNotification[] = []
669 const emails: object[] = []
671 const port = await MockSmtpServer.Instance.collectEmails(emails)
673 const overrideConfig = {
675 hostname: 'localhost',
682 const servers = await createMultipleServers(serversCount, Object.assign(overrideConfig, overrideConfigArg))
684 await setAccessTokensToServers(servers)
685 await setDefaultChannelAvatar(servers)
686 await setDefaultAccountAvatar(servers)
688 if (servers[1]) await servers[1].config.enableStudio()
690 if (serversCount > 1) {
691 await doubleFollow(servers[0], servers[1])
694 const user = { username: 'user_1', password: 'super password' }
695 await servers[0].users.create({ ...user, videoQuota: 10 * 1000 * 1000 })
696 const userAccessToken = await servers[0].login.getAccessToken(user)
698 await servers[0].notifications.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() })
699 await servers[0].notifications.updateMySettings({ settings: getAllNotificationsSettings() })
701 if (serversCount > 1) {
702 await servers[1].notifications.updateMySettings({ settings: getAllNotificationsSettings() })
706 const socket = servers[0].socketIO.getUserNotificationSocket({ token: userAccessToken })
707 socket.on('new-notification', n => userNotifications.push(n))
710 const socket = servers[0].socketIO.getUserNotificationSocket()
711 socket.on('new-notification', n => adminNotifications.push(n))
714 if (serversCount > 1) {
715 const socket = servers[1].socketIO.getUserNotificationSocket()
716 socket.on('new-notification', n => adminNotificationsServer2.push(n))
719 const { videoChannels } = await servers[0].users.getMyInfo()
720 const channelId = videoChannels[0].id
725 adminNotificationsServer2,
733 // ---------------------------------------------------------------------------
736 getAllNotificationsSettings,
740 checkMyVideoImportIsFinished,
742 checkAutoInstanceFollowing,
743 checkVideoIsPublished,
744 checkNewVideoFromSubscription,
746 checkNewCommentOnMyVideo,
747 checkNewBlacklistOnMyVideo,
749 checkNewVideoAbuseForModerators,
750 checkVideoAutoBlacklistForModerators,
751 checkNewAbuseMessage,
752 checkAbuseStateChange,
753 checkNewInstanceFollower,
754 prepareNotificationsTest,
755 checkNewCommentAbuseForModerators,
756 checkNewAccountAbuseForModerators,
757 checkNewPeerTubeVersion,
758 checkNewPluginVersion,
759 checkVideoStudioEditionIsFinished
762 // ---------------------------------------------------------------------------
764 async function checkNotification (options: CheckerBaseParams & {
765 notificationChecker: (notification: UserNotification, checkType: CheckerType) => void
766 emailNotificationFinder: (email: object) => boolean
767 checkType: CheckerType
769 const { server, token, checkType, notificationChecker, emailNotificationFinder, socketNotifications, emails } = options
771 const check = options.check || { web: true, mail: true }
774 const notification = await server.notifications.getLatest({ token: token })
776 if (notification || checkType !== 'absence') {
777 notificationChecker(notification, checkType)
780 const socketNotification = socketNotifications.find(n => {
782 notificationChecker(n, 'presence')
789 if (checkType === 'presence') {
790 const obj = inspect(socketNotifications, { depth: 5 })
791 expect(socketNotification, 'The socket notification is absent when it should be present. ' + obj).to.not.be.undefined
793 const obj = inspect(socketNotification, { depth: 5 })
794 expect(socketNotification, 'The socket notification is present when it should not be present. ' + obj).to.be.undefined
803 .find(e => emailNotificationFinder(e))
805 if (checkType === 'presence') {
806 const texts = emails.map(e => e.text)
807 expect(email, 'The email is absent when is should be present. ' + inspect(texts)).to.not.be.undefined
809 expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined
814 function checkVideo (video: any, videoName?: string, shortUUID?: string) {
816 expect(video.name).to.be.a('string')
817 expect(video.name).to.not.be.empty
818 expect(video.name).to.equal(videoName)
822 expect(video.shortUUID).to.be.a('string')
823 expect(video.shortUUID).to.not.be.empty
824 expect(video.shortUUID).to.equal(shortUUID)
827 expect(video.id).to.be.a('number')
830 function checkActor (actor: any) {
831 expect(actor.displayName).to.be.a('string')
832 expect(actor.displayName).to.not.be.empty
833 expect(actor.host).to.not.be.undefined
836 function checkComment (comment: any, commentId: number, threadId: number) {
837 expect(comment.id).to.equal(commentId)
838 expect(comment.threadId).to.equal(threadId)