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