]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/users/notifications.ts
Introduce user command
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / users / notifications.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { expect } from 'chai'
4 import { inspect } from 'util'
5 import { AbuseState, PluginType } from '@shared/models'
6 import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users'
7 import { MockSmtpServer } from '../mock-servers/mock-email'
8 import { doubleFollow } from '../server/follows'
9 import { flushAndRunMultipleServers, ServerInfo } from '../server/servers'
10 import { setAccessTokensToServers } from './login'
11
12 function getAllNotificationsSettings (): UserNotificationSetting {
13 return {
14 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
15 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
16 abuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
17 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
18 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
19 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
20 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
21 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
22 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
23 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
24 newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
25 abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
26 abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
27 autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
28 newPeerTubeVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
29 newPluginVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
30 }
31 }
32
33 type CheckerBaseParams = {
34 server: ServerInfo
35 emails: any[]
36 socketNotifications: UserNotification[]
37 token: string
38 check?: { web: boolean, mail: boolean }
39 }
40
41 type CheckerType = 'presence' | 'absence'
42
43 async function checkNotification (
44 base: CheckerBaseParams,
45 notificationChecker: (notification: UserNotification, type: CheckerType) => void,
46 emailNotificationFinder: (email: object) => boolean,
47 checkType: CheckerType
48 ) {
49 const check = base.check || { web: true, mail: true }
50
51 if (check.web) {
52 const notification = await base.server.notificationsCommand.getLastest({ token: base.token })
53
54 if (notification || checkType !== 'absence') {
55 notificationChecker(notification, checkType)
56 }
57
58 const socketNotification = base.socketNotifications.find(n => {
59 try {
60 notificationChecker(n, 'presence')
61 return true
62 } catch {
63 return false
64 }
65 })
66
67 if (checkType === 'presence') {
68 const obj = inspect(base.socketNotifications, { depth: 5 })
69 expect(socketNotification, 'The socket notification is absent when it should be present. ' + obj).to.not.be.undefined
70 } else {
71 const obj = inspect(socketNotification, { depth: 5 })
72 expect(socketNotification, 'The socket notification is present when it should not be present. ' + obj).to.be.undefined
73 }
74 }
75
76 if (check.mail) {
77 // Last email
78 const email = base.emails
79 .slice()
80 .reverse()
81 .find(e => emailNotificationFinder(e))
82
83 if (checkType === 'presence') {
84 const emails = base.emails.map(e => e.text)
85 expect(email, 'The email is absent when is should be present. ' + inspect(emails)).to.not.be.undefined
86 } else {
87 expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined
88 }
89 }
90 }
91
92 function checkVideo (video: any, videoName?: string, videoUUID?: string) {
93 if (videoName) {
94 expect(video.name).to.be.a('string')
95 expect(video.name).to.not.be.empty
96 expect(video.name).to.equal(videoName)
97 }
98
99 if (videoUUID) {
100 expect(video.uuid).to.be.a('string')
101 expect(video.uuid).to.not.be.empty
102 expect(video.uuid).to.equal(videoUUID)
103 }
104
105 expect(video.id).to.be.a('number')
106 }
107
108 function checkActor (actor: any) {
109 expect(actor.displayName).to.be.a('string')
110 expect(actor.displayName).to.not.be.empty
111 expect(actor.host).to.not.be.undefined
112 }
113
114 function checkComment (comment: any, commentId: number, threadId: number) {
115 expect(comment.id).to.equal(commentId)
116 expect(comment.threadId).to.equal(threadId)
117 }
118
119 async function checkNewVideoFromSubscription (base: CheckerBaseParams, videoName: string, videoUUID: string, type: CheckerType) {
120 const notificationType = UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION
121
122 function notificationChecker (notification: UserNotification, type: CheckerType) {
123 if (type === 'presence') {
124 expect(notification).to.not.be.undefined
125 expect(notification.type).to.equal(notificationType)
126
127 checkVideo(notification.video, videoName, videoUUID)
128 checkActor(notification.video.channel)
129 } else {
130 expect(notification).to.satisfy((n: UserNotification) => {
131 return n === undefined || n.type !== UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION || n.video.name !== videoName
132 })
133 }
134 }
135
136 function emailNotificationFinder (email: object) {
137 const text = email['text']
138 return text.indexOf(videoUUID) !== -1 && text.indexOf('Your subscription') !== -1
139 }
140
141 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
142 }
143
144 async function checkVideoIsPublished (base: CheckerBaseParams, videoName: string, videoUUID: string, type: CheckerType) {
145 const notificationType = UserNotificationType.MY_VIDEO_PUBLISHED
146
147 function notificationChecker (notification: UserNotification, type: CheckerType) {
148 if (type === 'presence') {
149 expect(notification).to.not.be.undefined
150 expect(notification.type).to.equal(notificationType)
151
152 checkVideo(notification.video, videoName, videoUUID)
153 checkActor(notification.video.channel)
154 } else {
155 expect(notification.video).to.satisfy(v => v === undefined || v.name !== videoName)
156 }
157 }
158
159 function emailNotificationFinder (email: object) {
160 const text: string = email['text']
161 return text.includes(videoUUID) && text.includes('Your video')
162 }
163
164 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
165 }
166
167 async function checkMyVideoImportIsFinished (
168 base: CheckerBaseParams,
169 videoName: string,
170 videoUUID: string,
171 url: string,
172 success: boolean,
173 type: CheckerType
174 ) {
175 const notificationType = success ? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS : UserNotificationType.MY_VIDEO_IMPORT_ERROR
176
177 function notificationChecker (notification: UserNotification, type: CheckerType) {
178 if (type === 'presence') {
179 expect(notification).to.not.be.undefined
180 expect(notification.type).to.equal(notificationType)
181
182 expect(notification.videoImport.targetUrl).to.equal(url)
183
184 if (success) checkVideo(notification.videoImport.video, videoName, videoUUID)
185 } else {
186 expect(notification.videoImport).to.satisfy(i => i === undefined || i.targetUrl !== url)
187 }
188 }
189
190 function emailNotificationFinder (email: object) {
191 const text: string = email['text']
192 const toFind = success ? ' finished' : ' error'
193
194 return text.includes(url) && text.includes(toFind)
195 }
196
197 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
198 }
199
200 async function checkUserRegistered (base: CheckerBaseParams, username: string, type: CheckerType) {
201 const notificationType = UserNotificationType.NEW_USER_REGISTRATION
202
203 function notificationChecker (notification: UserNotification, type: CheckerType) {
204 if (type === 'presence') {
205 expect(notification).to.not.be.undefined
206 expect(notification.type).to.equal(notificationType)
207
208 checkActor(notification.account)
209 expect(notification.account.name).to.equal(username)
210 } else {
211 expect(notification).to.satisfy(n => n.type !== notificationType || n.account.name !== username)
212 }
213 }
214
215 function emailNotificationFinder (email: object) {
216 const text: string = email['text']
217
218 return text.includes(' registered.') && text.includes(username)
219 }
220
221 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
222 }
223
224 async function checkNewActorFollow (
225 base: CheckerBaseParams,
226 followType: 'channel' | 'account',
227 followerName: string,
228 followerDisplayName: string,
229 followingDisplayName: string,
230 type: CheckerType
231 ) {
232 const notificationType = UserNotificationType.NEW_FOLLOW
233
234 function notificationChecker (notification: UserNotification, type: CheckerType) {
235 if (type === 'presence') {
236 expect(notification).to.not.be.undefined
237 expect(notification.type).to.equal(notificationType)
238
239 checkActor(notification.actorFollow.follower)
240 expect(notification.actorFollow.follower.displayName).to.equal(followerDisplayName)
241 expect(notification.actorFollow.follower.name).to.equal(followerName)
242 expect(notification.actorFollow.follower.host).to.not.be.undefined
243
244 const following = notification.actorFollow.following
245 expect(following.displayName).to.equal(followingDisplayName)
246 expect(following.type).to.equal(followType)
247 } else {
248 expect(notification).to.satisfy(n => {
249 return n.type !== notificationType ||
250 (n.actorFollow.follower.name !== followerName && n.actorFollow.following !== followingDisplayName)
251 })
252 }
253 }
254
255 function emailNotificationFinder (email: object) {
256 const text: string = email['text']
257
258 return text.includes(followType) && text.includes(followingDisplayName) && text.includes(followerDisplayName)
259 }
260
261 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
262 }
263
264 async function checkNewInstanceFollower (base: CheckerBaseParams, followerHost: string, type: CheckerType) {
265 const notificationType = UserNotificationType.NEW_INSTANCE_FOLLOWER
266
267 function notificationChecker (notification: UserNotification, type: CheckerType) {
268 if (type === 'presence') {
269 expect(notification).to.not.be.undefined
270 expect(notification.type).to.equal(notificationType)
271
272 checkActor(notification.actorFollow.follower)
273 expect(notification.actorFollow.follower.name).to.equal('peertube')
274 expect(notification.actorFollow.follower.host).to.equal(followerHost)
275
276 expect(notification.actorFollow.following.name).to.equal('peertube')
277 } else {
278 expect(notification).to.satisfy(n => {
279 return n.type !== notificationType || n.actorFollow.follower.host !== followerHost
280 })
281 }
282 }
283
284 function emailNotificationFinder (email: object) {
285 const text: string = email['text']
286
287 return text.includes('instance has a new follower') && text.includes(followerHost)
288 }
289
290 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
291 }
292
293 async function checkAutoInstanceFollowing (base: CheckerBaseParams, followerHost: string, followingHost: string, type: CheckerType) {
294 const notificationType = UserNotificationType.AUTO_INSTANCE_FOLLOWING
295
296 function notificationChecker (notification: UserNotification, type: CheckerType) {
297 if (type === 'presence') {
298 expect(notification).to.not.be.undefined
299 expect(notification.type).to.equal(notificationType)
300
301 const following = notification.actorFollow.following
302 checkActor(following)
303 expect(following.name).to.equal('peertube')
304 expect(following.host).to.equal(followingHost)
305
306 expect(notification.actorFollow.follower.name).to.equal('peertube')
307 expect(notification.actorFollow.follower.host).to.equal(followerHost)
308 } else {
309 expect(notification).to.satisfy(n => {
310 return n.type !== notificationType || n.actorFollow.following.host !== followingHost
311 })
312 }
313 }
314
315 function emailNotificationFinder (email: object) {
316 const text: string = email['text']
317
318 return text.includes(' automatically followed a new instance') && text.includes(followingHost)
319 }
320
321 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
322 }
323
324 async function checkCommentMention (
325 base: CheckerBaseParams,
326 uuid: string,
327 commentId: number,
328 threadId: number,
329 byAccountDisplayName: string,
330 type: CheckerType
331 ) {
332 const notificationType = UserNotificationType.COMMENT_MENTION
333
334 function notificationChecker (notification: UserNotification, type: CheckerType) {
335 if (type === 'presence') {
336 expect(notification).to.not.be.undefined
337 expect(notification.type).to.equal(notificationType)
338
339 checkComment(notification.comment, commentId, threadId)
340 checkActor(notification.comment.account)
341 expect(notification.comment.account.displayName).to.equal(byAccountDisplayName)
342
343 checkVideo(notification.comment.video, undefined, uuid)
344 } else {
345 expect(notification).to.satisfy(n => n.type !== notificationType || n.comment.id !== commentId)
346 }
347 }
348
349 function emailNotificationFinder (email: object) {
350 const text: string = email['text']
351
352 return text.includes(' mentioned ') && text.includes(uuid) && text.includes(byAccountDisplayName)
353 }
354
355 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
356 }
357
358 let lastEmailCount = 0
359
360 async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string, commentId: number, threadId: number, type: CheckerType) {
361 const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO
362
363 function notificationChecker (notification: UserNotification, type: CheckerType) {
364 if (type === 'presence') {
365 expect(notification).to.not.be.undefined
366 expect(notification.type).to.equal(notificationType)
367
368 checkComment(notification.comment, commentId, threadId)
369 checkActor(notification.comment.account)
370 checkVideo(notification.comment.video, undefined, uuid)
371 } else {
372 expect(notification).to.satisfy((n: UserNotification) => {
373 return n === undefined || n.comment === undefined || n.comment.id !== commentId
374 })
375 }
376 }
377
378 const commentUrl = `http://localhost:${base.server.port}/w/${uuid};threadId=${threadId}`
379
380 function emailNotificationFinder (email: object) {
381 return email['text'].indexOf(commentUrl) !== -1
382 }
383
384 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
385
386 if (type === 'presence') {
387 // We cannot detect email duplicates, so check we received another email
388 expect(base.emails).to.have.length.above(lastEmailCount)
389 lastEmailCount = base.emails.length
390 }
391 }
392
393 async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
394 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
395
396 function notificationChecker (notification: UserNotification, type: CheckerType) {
397 if (type === 'presence') {
398 expect(notification).to.not.be.undefined
399 expect(notification.type).to.equal(notificationType)
400
401 expect(notification.abuse.id).to.be.a('number')
402 checkVideo(notification.abuse.video, videoName, videoUUID)
403 } else {
404 expect(notification).to.satisfy((n: UserNotification) => {
405 return n === undefined || n.abuse === undefined || n.abuse.video.uuid !== videoUUID
406 })
407 }
408 }
409
410 function emailNotificationFinder (email: object) {
411 const text = email['text']
412 return text.indexOf(videoUUID) !== -1 && text.indexOf('abuse') !== -1
413 }
414
415 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
416 }
417
418 async function checkNewAbuseMessage (base: CheckerBaseParams, abuseId: number, message: string, toEmail: string, type: CheckerType) {
419 const notificationType = UserNotificationType.ABUSE_NEW_MESSAGE
420
421 function notificationChecker (notification: UserNotification, type: CheckerType) {
422 if (type === 'presence') {
423 expect(notification).to.not.be.undefined
424 expect(notification.type).to.equal(notificationType)
425
426 expect(notification.abuse.id).to.equal(abuseId)
427 } else {
428 expect(notification).to.satisfy((n: UserNotification) => {
429 return n === undefined || n.type !== notificationType || n.abuse === undefined || n.abuse.id !== abuseId
430 })
431 }
432 }
433
434 function emailNotificationFinder (email: object) {
435 const text = email['text']
436 const to = email['to'].filter(t => t.address === toEmail)
437
438 return text.indexOf(message) !== -1 && to.length !== 0
439 }
440
441 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
442 }
443
444 async function checkAbuseStateChange (base: CheckerBaseParams, abuseId: number, state: AbuseState, type: CheckerType) {
445 const notificationType = UserNotificationType.ABUSE_STATE_CHANGE
446
447 function notificationChecker (notification: UserNotification, type: CheckerType) {
448 if (type === 'presence') {
449 expect(notification).to.not.be.undefined
450 expect(notification.type).to.equal(notificationType)
451
452 expect(notification.abuse.id).to.equal(abuseId)
453 expect(notification.abuse.state).to.equal(state)
454 } else {
455 expect(notification).to.satisfy((n: UserNotification) => {
456 return n === undefined || n.abuse === undefined || n.abuse.id !== abuseId
457 })
458 }
459 }
460
461 function emailNotificationFinder (email: object) {
462 const text = email['text']
463
464 const contains = state === AbuseState.ACCEPTED
465 ? ' accepted'
466 : ' rejected'
467
468 return text.indexOf(contains) !== -1
469 }
470
471 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
472 }
473
474 async function checkNewCommentAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
475 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
476
477 function notificationChecker (notification: UserNotification, type: CheckerType) {
478 if (type === 'presence') {
479 expect(notification).to.not.be.undefined
480 expect(notification.type).to.equal(notificationType)
481
482 expect(notification.abuse.id).to.be.a('number')
483 checkVideo(notification.abuse.comment.video, videoName, videoUUID)
484 } else {
485 expect(notification).to.satisfy((n: UserNotification) => {
486 return n === undefined || n.abuse === undefined || n.abuse.comment.video.uuid !== videoUUID
487 })
488 }
489 }
490
491 function emailNotificationFinder (email: object) {
492 const text = email['text']
493 return text.indexOf(videoUUID) !== -1 && text.indexOf('abuse') !== -1
494 }
495
496 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
497 }
498
499 async function checkNewAccountAbuseForModerators (base: CheckerBaseParams, displayName: string, type: CheckerType) {
500 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
501
502 function notificationChecker (notification: UserNotification, type: CheckerType) {
503 if (type === 'presence') {
504 expect(notification).to.not.be.undefined
505 expect(notification.type).to.equal(notificationType)
506
507 expect(notification.abuse.id).to.be.a('number')
508 expect(notification.abuse.account.displayName).to.equal(displayName)
509 } else {
510 expect(notification).to.satisfy((n: UserNotification) => {
511 return n === undefined || n.abuse === undefined || n.abuse.account.displayName !== displayName
512 })
513 }
514 }
515
516 function emailNotificationFinder (email: object) {
517 const text = email['text']
518 return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1
519 }
520
521 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
522 }
523
524 async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
525 const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS
526
527 function notificationChecker (notification: UserNotification, type: CheckerType) {
528 if (type === 'presence') {
529 expect(notification).to.not.be.undefined
530 expect(notification.type).to.equal(notificationType)
531
532 expect(notification.videoBlacklist.video.id).to.be.a('number')
533 checkVideo(notification.videoBlacklist.video, videoName, videoUUID)
534 } else {
535 expect(notification).to.satisfy((n: UserNotification) => {
536 return n === undefined || n.video === undefined || n.video.uuid !== videoUUID
537 })
538 }
539 }
540
541 function emailNotificationFinder (email: object) {
542 const text = email['text']
543 return text.indexOf(videoUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1
544 }
545
546 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
547 }
548
549 async function checkNewBlacklistOnMyVideo (
550 base: CheckerBaseParams,
551 videoUUID: string,
552 videoName: string,
553 blacklistType: 'blacklist' | 'unblacklist'
554 ) {
555 const notificationType = blacklistType === 'blacklist'
556 ? UserNotificationType.BLACKLIST_ON_MY_VIDEO
557 : UserNotificationType.UNBLACKLIST_ON_MY_VIDEO
558
559 function notificationChecker (notification: UserNotification) {
560 expect(notification).to.not.be.undefined
561 expect(notification.type).to.equal(notificationType)
562
563 const video = blacklistType === 'blacklist' ? notification.videoBlacklist.video : notification.video
564
565 checkVideo(video, videoName, videoUUID)
566 }
567
568 function emailNotificationFinder (email: object) {
569 const text = email['text']
570 return text.indexOf(videoUUID) !== -1 && text.indexOf(' ' + blacklistType) !== -1
571 }
572
573 await checkNotification(base, notificationChecker, emailNotificationFinder, 'presence')
574 }
575
576 async function checkNewPeerTubeVersion (base: CheckerBaseParams, latestVersion: string, type: CheckerType) {
577 const notificationType = UserNotificationType.NEW_PEERTUBE_VERSION
578
579 function notificationChecker (notification: UserNotification, type: CheckerType) {
580 if (type === 'presence') {
581 expect(notification).to.not.be.undefined
582 expect(notification.type).to.equal(notificationType)
583
584 expect(notification.peertube).to.exist
585 expect(notification.peertube.latestVersion).to.equal(latestVersion)
586 } else {
587 expect(notification).to.satisfy((n: UserNotification) => {
588 return n === undefined || n.peertube === undefined || n.peertube.latestVersion !== latestVersion
589 })
590 }
591 }
592
593 function emailNotificationFinder (email: object) {
594 const text = email['text']
595
596 return text.includes(latestVersion)
597 }
598
599 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
600 }
601
602 async function checkNewPluginVersion (base: CheckerBaseParams, pluginType: PluginType, pluginName: string, type: CheckerType) {
603 const notificationType = UserNotificationType.NEW_PLUGIN_VERSION
604
605 function notificationChecker (notification: UserNotification, type: CheckerType) {
606 if (type === 'presence') {
607 expect(notification).to.not.be.undefined
608 expect(notification.type).to.equal(notificationType)
609
610 expect(notification.plugin.name).to.equal(pluginName)
611 expect(notification.plugin.type).to.equal(pluginType)
612 } else {
613 expect(notification).to.satisfy((n: UserNotification) => {
614 return n === undefined || n.plugin === undefined || n.plugin.name !== pluginName
615 })
616 }
617 }
618
619 function emailNotificationFinder (email: object) {
620 const text = email['text']
621
622 return text.includes(pluginName)
623 }
624
625 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
626 }
627
628 async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) {
629 const userNotifications: UserNotification[] = []
630 const adminNotifications: UserNotification[] = []
631 const adminNotificationsServer2: UserNotification[] = []
632 const emails: object[] = []
633
634 const port = await MockSmtpServer.Instance.collectEmails(emails)
635
636 const overrideConfig = {
637 smtp: {
638 hostname: 'localhost',
639 port
640 },
641 signup: {
642 limit: 20
643 }
644 }
645 const servers = await flushAndRunMultipleServers(serversCount, Object.assign(overrideConfig, overrideConfigArg))
646
647 await setAccessTokensToServers(servers)
648
649 if (serversCount > 1) {
650 await doubleFollow(servers[0], servers[1])
651 }
652
653 const user = { username: 'user_1', password: 'super password' }
654 await servers[0].usersCommand.create({ ...user, videoQuota: 10 * 1000 * 1000 })
655 const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
656
657 await servers[0].notificationsCommand.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() })
658 await servers[0].notificationsCommand.updateMySettings({ settings: getAllNotificationsSettings() })
659
660 if (serversCount > 1) {
661 await servers[1].notificationsCommand.updateMySettings({ settings: getAllNotificationsSettings() })
662 }
663
664 {
665 const socket = servers[0].socketIOCommand.getUserNotificationSocket({ token: userAccessToken })
666 socket.on('new-notification', n => userNotifications.push(n))
667 }
668 {
669 const socket = servers[0].socketIOCommand.getUserNotificationSocket()
670 socket.on('new-notification', n => adminNotifications.push(n))
671 }
672
673 if (serversCount > 1) {
674 const socket = servers[1].socketIOCommand.getUserNotificationSocket()
675 socket.on('new-notification', n => adminNotificationsServer2.push(n))
676 }
677
678 const { videoChannels } = await servers[0].usersCommand.getMyInfo()
679 const channelId = videoChannels[0].id
680
681 return {
682 userNotifications,
683 adminNotifications,
684 adminNotificationsServer2,
685 userAccessToken,
686 emails,
687 servers,
688 channelId
689 }
690 }
691
692 // ---------------------------------------------------------------------------
693
694 export {
695 getAllNotificationsSettings,
696
697 CheckerBaseParams,
698 CheckerType,
699 checkNotification,
700 checkMyVideoImportIsFinished,
701 checkUserRegistered,
702 checkAutoInstanceFollowing,
703 checkVideoIsPublished,
704 checkNewVideoFromSubscription,
705 checkNewActorFollow,
706 checkNewCommentOnMyVideo,
707 checkNewBlacklistOnMyVideo,
708 checkCommentMention,
709 checkNewVideoAbuseForModerators,
710 checkVideoAutoBlacklistForModerators,
711 checkNewAbuseMessage,
712 checkAbuseStateChange,
713 checkNewInstanceFollower,
714 prepareNotificationsTest,
715 checkNewCommentAbuseForModerators,
716 checkNewAccountAbuseForModerators,
717 checkNewPeerTubeVersion,
718 checkNewPluginVersion
719 }