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, { withAvatar: false })
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, { withAvatar: false })
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
292 checkActor(following, { withAvatar: false })
293 expect(following.name).to.equal('peertube')
294 expect(following.host).to.equal(followingHost)
296 expect(notification.actorFollow.follower.name).to.equal('peertube')
297 expect(notification.actorFollow.follower.host).to.equal(followerHost)
299 expect(notification).to.satisfy(n => {
300 return n.type !== notificationType || n.actorFollow.following.host !== followingHost
305 function emailNotificationFinder (email: object) {
306 const text: string = email['text']
308 return text.includes(' automatically followed a new instance') && text.includes(followingHost)
311 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
314 async function checkCommentMention (options: CheckerBaseParams & {
318 byAccountDisplayName: string
319 checkType: CheckerType
321 const { shortUUID, commentId, threadId, byAccountDisplayName } = options
322 const notificationType = UserNotificationType.COMMENT_MENTION
324 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
325 if (checkType === 'presence') {
326 expect(notification).to.not.be.undefined
327 expect(notification.type).to.equal(notificationType)
329 checkComment(notification.comment, commentId, threadId)
330 checkActor(notification.comment.account)
331 expect(notification.comment.account.displayName).to.equal(byAccountDisplayName)
333 checkVideo(notification.comment.video, undefined, shortUUID)
335 expect(notification).to.satisfy(n => n.type !== notificationType || n.comment.id !== commentId)
339 function emailNotificationFinder (email: object) {
340 const text: string = email['text']
342 return text.includes(' mentioned ') && text.includes(shortUUID) && text.includes(byAccountDisplayName)
345 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
348 let lastEmailCount = 0
350 async function checkNewCommentOnMyVideo (options: CheckerBaseParams & {
354 checkType: CheckerType
356 const { server, shortUUID, commentId, threadId, checkType, emails } = options
357 const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO
359 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
360 if (checkType === 'presence') {
361 expect(notification).to.not.be.undefined
362 expect(notification.type).to.equal(notificationType)
364 checkComment(notification.comment, commentId, threadId)
365 checkActor(notification.comment.account)
366 checkVideo(notification.comment.video, undefined, shortUUID)
368 expect(notification).to.satisfy((n: UserNotification) => {
369 return n === undefined || n.comment === undefined || n.comment.id !== commentId
374 const commentUrl = `http://localhost:${server.port}/w/${shortUUID};threadId=${threadId}`
376 function emailNotificationFinder (email: object) {
377 return email['text'].indexOf(commentUrl) !== -1
380 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
382 if (checkType === 'presence') {
383 // We cannot detect email duplicates, so check we received another email
384 expect(emails).to.have.length.above(lastEmailCount)
385 lastEmailCount = emails.length
389 async function checkNewVideoAbuseForModerators (options: CheckerBaseParams & {
392 checkType: CheckerType
394 const { shortUUID, videoName } = options
395 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
397 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
398 if (checkType === 'presence') {
399 expect(notification).to.not.be.undefined
400 expect(notification.type).to.equal(notificationType)
402 expect(notification.abuse.id).to.be.a('number')
403 checkVideo(notification.abuse.video, videoName, shortUUID)
405 expect(notification).to.satisfy((n: UserNotification) => {
406 return n === undefined || n.abuse === undefined || n.abuse.video.shortUUID !== shortUUID
411 function emailNotificationFinder (email: object) {
412 const text = email['text']
413 return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1
416 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
419 async function checkNewAbuseMessage (options: CheckerBaseParams & {
423 checkType: CheckerType
425 const { abuseId, message, toEmail } = options
426 const notificationType = UserNotificationType.ABUSE_NEW_MESSAGE
428 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
429 if (checkType === 'presence') {
430 expect(notification).to.not.be.undefined
431 expect(notification.type).to.equal(notificationType)
433 expect(notification.abuse.id).to.equal(abuseId)
435 expect(notification).to.satisfy((n: UserNotification) => {
436 return n === undefined || n.type !== notificationType || n.abuse === undefined || n.abuse.id !== abuseId
441 function emailNotificationFinder (email: object) {
442 const text = email['text']
443 const to = email['to'].filter(t => t.address === toEmail)
445 return text.indexOf(message) !== -1 && to.length !== 0
448 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
451 async function checkAbuseStateChange (options: CheckerBaseParams & {
454 checkType: CheckerType
456 const { abuseId, state } = options
457 const notificationType = UserNotificationType.ABUSE_STATE_CHANGE
459 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
460 if (checkType === 'presence') {
461 expect(notification).to.not.be.undefined
462 expect(notification.type).to.equal(notificationType)
464 expect(notification.abuse.id).to.equal(abuseId)
465 expect(notification.abuse.state).to.equal(state)
467 expect(notification).to.satisfy((n: UserNotification) => {
468 return n === undefined || n.abuse === undefined || n.abuse.id !== abuseId
473 function emailNotificationFinder (email: object) {
474 const text = email['text']
476 const contains = state === AbuseState.ACCEPTED
480 return text.indexOf(contains) !== -1
483 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
486 async function checkNewCommentAbuseForModerators (options: CheckerBaseParams & {
489 checkType: CheckerType
491 const { shortUUID, videoName } = options
492 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
494 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
495 if (checkType === 'presence') {
496 expect(notification).to.not.be.undefined
497 expect(notification.type).to.equal(notificationType)
499 expect(notification.abuse.id).to.be.a('number')
500 checkVideo(notification.abuse.comment.video, videoName, shortUUID)
502 expect(notification).to.satisfy((n: UserNotification) => {
503 return n === undefined || n.abuse === undefined || n.abuse.comment.video.shortUUID !== shortUUID
508 function emailNotificationFinder (email: object) {
509 const text = email['text']
510 return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1
513 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
516 async function checkNewAccountAbuseForModerators (options: CheckerBaseParams & {
518 checkType: CheckerType
520 const { displayName } = options
521 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
523 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
524 if (checkType === 'presence') {
525 expect(notification).to.not.be.undefined
526 expect(notification.type).to.equal(notificationType)
528 expect(notification.abuse.id).to.be.a('number')
529 expect(notification.abuse.account.displayName).to.equal(displayName)
531 expect(notification).to.satisfy((n: UserNotification) => {
532 return n === undefined || n.abuse === undefined || n.abuse.account.displayName !== displayName
537 function emailNotificationFinder (email: object) {
538 const text = email['text']
539 return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1
542 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
545 async function checkVideoAutoBlacklistForModerators (options: CheckerBaseParams & {
548 checkType: CheckerType
550 const { shortUUID, videoName } = options
551 const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS
553 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
554 if (checkType === 'presence') {
555 expect(notification).to.not.be.undefined
556 expect(notification.type).to.equal(notificationType)
558 expect(notification.videoBlacklist.video.id).to.be.a('number')
559 checkVideo(notification.videoBlacklist.video, videoName, shortUUID)
561 expect(notification).to.satisfy((n: UserNotification) => {
562 return n === undefined || n.video === undefined || n.video.shortUUID !== shortUUID
567 function emailNotificationFinder (email: object) {
568 const text = email['text']
569 return text.indexOf(shortUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1
572 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
575 async function checkNewBlacklistOnMyVideo (options: CheckerBaseParams & {
578 blacklistType: 'blacklist' | 'unblacklist'
580 const { videoName, shortUUID, blacklistType } = options
581 const notificationType = blacklistType === 'blacklist'
582 ? UserNotificationType.BLACKLIST_ON_MY_VIDEO
583 : UserNotificationType.UNBLACKLIST_ON_MY_VIDEO
585 function notificationChecker (notification: UserNotification) {
586 expect(notification).to.not.be.undefined
587 expect(notification.type).to.equal(notificationType)
589 const video = blacklistType === 'blacklist' ? notification.videoBlacklist.video : notification.video
591 checkVideo(video, videoName, shortUUID)
594 function emailNotificationFinder (email: object) {
595 const text = email['text']
596 const blacklistText = blacklistType === 'blacklist'
600 return text.includes(shortUUID) && text.includes(blacklistText)
603 await checkNotification({ ...options, notificationChecker, emailNotificationFinder, checkType: 'presence' })
606 async function checkNewPeerTubeVersion (options: CheckerBaseParams & {
607 latestVersion: string
608 checkType: CheckerType
610 const { latestVersion } = options
611 const notificationType = UserNotificationType.NEW_PEERTUBE_VERSION
613 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
614 if (checkType === 'presence') {
615 expect(notification).to.not.be.undefined
616 expect(notification.type).to.equal(notificationType)
618 expect(notification.peertube).to.exist
619 expect(notification.peertube.latestVersion).to.equal(latestVersion)
621 expect(notification).to.satisfy((n: UserNotification) => {
622 return n === undefined || n.peertube === undefined || n.peertube.latestVersion !== latestVersion
627 function emailNotificationFinder (email: object) {
628 const text = email['text']
630 return text.includes(latestVersion)
633 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
636 async function checkNewPluginVersion (options: CheckerBaseParams & {
637 pluginType: PluginType
639 checkType: CheckerType
641 const { pluginName, pluginType } = options
642 const notificationType = UserNotificationType.NEW_PLUGIN_VERSION
644 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
645 if (checkType === 'presence') {
646 expect(notification).to.not.be.undefined
647 expect(notification.type).to.equal(notificationType)
649 expect(notification.plugin.name).to.equal(pluginName)
650 expect(notification.plugin.type).to.equal(pluginType)
652 expect(notification).to.satisfy((n: UserNotification) => {
653 return n === undefined || n.plugin === undefined || n.plugin.name !== pluginName
658 function emailNotificationFinder (email: object) {
659 const text = email['text']
661 return text.includes(pluginName)
664 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
667 async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) {
668 const userNotifications: UserNotification[] = []
669 const adminNotifications: UserNotification[] = []
670 const adminNotificationsServer2: UserNotification[] = []
671 const emails: object[] = []
673 const port = await MockSmtpServer.Instance.collectEmails(emails)
675 const overrideConfig = {
677 hostname: 'localhost',
684 const servers = await createMultipleServers(serversCount, Object.assign(overrideConfig, overrideConfigArg))
686 await setAccessTokensToServers(servers)
687 await setDefaultVideoChannel(servers)
688 await setDefaultChannelAvatar(servers)
689 await setDefaultAccountAvatar(servers)
692 await servers[1].config.enableStudio()
693 await servers[1].config.enableLive({ allowReplay: true, transcoding: false })
696 if (serversCount > 1) {
697 await doubleFollow(servers[0], servers[1])
700 const user = { username: 'user_1', password: 'super password' }
701 await servers[0].users.create({ ...user, videoQuota: 10 * 1000 * 1000 })
702 const userAccessToken = await servers[0].login.getAccessToken(user)
704 await servers[0].notifications.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() })
705 await servers[0].users.updateMyAvatar({ token: userAccessToken, fixture: 'avatar.png' })
706 await servers[0].channels.updateImage({ channelName: 'user_1_channel', token: userAccessToken, fixture: 'avatar.png', type: 'avatar' })
708 await servers[0].notifications.updateMySettings({ settings: getAllNotificationsSettings() })
710 if (serversCount > 1) {
711 await servers[1].notifications.updateMySettings({ settings: getAllNotificationsSettings() })
715 const socket = servers[0].socketIO.getUserNotificationSocket({ token: userAccessToken })
716 socket.on('new-notification', n => userNotifications.push(n))
719 const socket = servers[0].socketIO.getUserNotificationSocket()
720 socket.on('new-notification', n => adminNotifications.push(n))
723 if (serversCount > 1) {
724 const socket = servers[1].socketIO.getUserNotificationSocket()
725 socket.on('new-notification', n => adminNotificationsServer2.push(n))
728 const { videoChannels } = await servers[0].users.getMyInfo()
729 const channelId = videoChannels[0].id
734 adminNotificationsServer2,
742 // ---------------------------------------------------------------------------
745 getAllNotificationsSettings,
749 checkMyVideoImportIsFinished,
751 checkAutoInstanceFollowing,
752 checkVideoIsPublished,
753 checkNewVideoFromSubscription,
755 checkNewCommentOnMyVideo,
756 checkNewBlacklistOnMyVideo,
758 checkNewVideoAbuseForModerators,
759 checkVideoAutoBlacklistForModerators,
760 checkNewAbuseMessage,
761 checkAbuseStateChange,
762 checkNewInstanceFollower,
763 prepareNotificationsTest,
764 checkNewCommentAbuseForModerators,
765 checkNewAccountAbuseForModerators,
766 checkNewPeerTubeVersion,
767 checkNewPluginVersion,
768 checkVideoStudioEditionIsFinished
771 // ---------------------------------------------------------------------------
773 async function checkNotification (options: CheckerBaseParams & {
774 notificationChecker: (notification: UserNotification, checkType: CheckerType) => void
775 emailNotificationFinder: (email: object) => boolean
776 checkType: CheckerType
778 const { server, token, checkType, notificationChecker, emailNotificationFinder, socketNotifications, emails } = options
780 const check = options.check || { web: true, mail: true }
783 const notification = await server.notifications.getLatest({ token: token })
785 if (notification || checkType !== 'absence') {
786 notificationChecker(notification, checkType)
789 const socketNotification = socketNotifications.find(n => {
791 notificationChecker(n, 'presence')
798 if (checkType === 'presence') {
799 const obj = inspect(socketNotifications, { depth: 5 })
800 expect(socketNotification, 'The socket notification is absent when it should be present. ' + obj).to.not.be.undefined
802 const obj = inspect(socketNotification, { depth: 5 })
803 expect(socketNotification, 'The socket notification is present when it should not be present. ' + obj).to.be.undefined
812 .find(e => emailNotificationFinder(e))
814 if (checkType === 'presence') {
815 const texts = emails.map(e => e.text)
816 expect(email, 'The email is absent when is should be present. ' + inspect(texts)).to.not.be.undefined
818 expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined
823 function checkVideo (video: any, videoName?: string, shortUUID?: string) {
825 expect(video.name).to.be.a('string')
826 expect(video.name).to.not.be.empty
827 expect(video.name).to.equal(videoName)
831 expect(video.shortUUID).to.be.a('string')
832 expect(video.shortUUID).to.not.be.empty
833 expect(video.shortUUID).to.equal(shortUUID)
836 expect(video.id).to.be.a('number')
839 function checkActor (actor: any, options: { withAvatar?: boolean } = {}) {
840 const { withAvatar = true } = options
842 expect(actor.displayName).to.be.a('string')
843 expect(actor.displayName).to.not.be.empty
844 expect(actor.host).to.not.be.undefined
847 expect(actor.avatars).to.be.an('array')
848 expect(actor.avatars).to.have.lengthOf(2)
849 expect(actor.avatars[0].path).to.exist.and.not.empty
853 function checkComment (comment: any, commentId: number, threadId: number) {
854 expect(comment.id).to.equal(commentId)
855 expect(comment.threadId).to.equal(threadId)