diff options
Diffstat (limited to 'shared/extra-utils/users')
-rw-r--r-- | shared/extra-utils/users/user-notifications.ts | 83 |
1 files changed, 71 insertions, 12 deletions
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts index a17a39de9..2061e3353 100644 --- a/shared/extra-utils/users/user-notifications.ts +++ b/shared/extra-utils/users/user-notifications.ts | |||
@@ -139,13 +139,17 @@ async function checkNotification ( | |||
139 | } | 139 | } |
140 | 140 | ||
141 | function checkVideo (video: any, videoName?: string, videoUUID?: string) { | 141 | function checkVideo (video: any, videoName?: string, videoUUID?: string) { |
142 | expect(video.name).to.be.a('string') | 142 | if (videoName) { |
143 | expect(video.name).to.not.be.empty | 143 | expect(video.name).to.be.a('string') |
144 | if (videoName) expect(video.name).to.equal(videoName) | 144 | expect(video.name).to.not.be.empty |
145 | expect(video.name).to.equal(videoName) | ||
146 | } | ||
145 | 147 | ||
146 | expect(video.uuid).to.be.a('string') | 148 | if (videoUUID) { |
147 | expect(video.uuid).to.not.be.empty | 149 | expect(video.uuid).to.be.a('string') |
148 | if (videoUUID) expect(video.uuid).to.equal(videoUUID) | 150 | expect(video.uuid).to.not.be.empty |
151 | expect(video.uuid).to.equal(videoUUID) | ||
152 | } | ||
149 | 153 | ||
150 | expect(video.id).to.be.a('number') | 154 | expect(video.id).to.be.a('number') |
151 | } | 155 | } |
@@ -436,18 +440,43 @@ async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string, | |||
436 | } | 440 | } |
437 | 441 | ||
438 | async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { | 442 | async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { |
439 | const notificationType = UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS | 443 | const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS |
444 | |||
445 | function notificationChecker (notification: UserNotification, type: CheckerType) { | ||
446 | if (type === 'presence') { | ||
447 | expect(notification).to.not.be.undefined | ||
448 | expect(notification.type).to.equal(notificationType) | ||
449 | |||
450 | expect(notification.abuse.id).to.be.a('number') | ||
451 | checkVideo(notification.abuse.video, videoName, videoUUID) | ||
452 | } else { | ||
453 | expect(notification).to.satisfy((n: UserNotification) => { | ||
454 | return n === undefined || n.abuse === undefined || n.abuse.video.uuid !== videoUUID | ||
455 | }) | ||
456 | } | ||
457 | } | ||
458 | |||
459 | function emailNotificationFinder (email: object) { | ||
460 | const text = email['text'] | ||
461 | return text.indexOf(videoUUID) !== -1 && text.indexOf('abuse') !== -1 | ||
462 | } | ||
463 | |||
464 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | ||
465 | } | ||
466 | |||
467 | async function checkNewCommentAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { | ||
468 | const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS | ||
440 | 469 | ||
441 | function notificationChecker (notification: UserNotification, type: CheckerType) { | 470 | function notificationChecker (notification: UserNotification, type: CheckerType) { |
442 | if (type === 'presence') { | 471 | if (type === 'presence') { |
443 | expect(notification).to.not.be.undefined | 472 | expect(notification).to.not.be.undefined |
444 | expect(notification.type).to.equal(notificationType) | 473 | expect(notification.type).to.equal(notificationType) |
445 | 474 | ||
446 | expect(notification.videoAbuse.id).to.be.a('number') | 475 | expect(notification.abuse.id).to.be.a('number') |
447 | checkVideo(notification.videoAbuse.video, videoName, videoUUID) | 476 | checkVideo(notification.abuse.comment.video, videoName, videoUUID) |
448 | } else { | 477 | } else { |
449 | expect(notification).to.satisfy((n: UserNotification) => { | 478 | expect(notification).to.satisfy((n: UserNotification) => { |
450 | return n === undefined || n.videoAbuse === undefined || n.videoAbuse.video.uuid !== videoUUID | 479 | return n === undefined || n.abuse === undefined || n.abuse.comment.video.uuid !== videoUUID |
451 | }) | 480 | }) |
452 | } | 481 | } |
453 | } | 482 | } |
@@ -460,6 +489,31 @@ async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUU | |||
460 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 489 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) |
461 | } | 490 | } |
462 | 491 | ||
492 | async function checkNewAccountAbuseForModerators (base: CheckerBaseParams, displayName: string, type: CheckerType) { | ||
493 | const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS | ||
494 | |||
495 | function notificationChecker (notification: UserNotification, type: CheckerType) { | ||
496 | if (type === 'presence') { | ||
497 | expect(notification).to.not.be.undefined | ||
498 | expect(notification.type).to.equal(notificationType) | ||
499 | |||
500 | expect(notification.abuse.id).to.be.a('number') | ||
501 | expect(notification.abuse.account.displayName).to.equal(displayName) | ||
502 | } else { | ||
503 | expect(notification).to.satisfy((n: UserNotification) => { | ||
504 | return n === undefined || n.abuse === undefined || n.abuse.account.displayName !== displayName | ||
505 | }) | ||
506 | } | ||
507 | } | ||
508 | |||
509 | function emailNotificationFinder (email: object) { | ||
510 | const text = email['text'] | ||
511 | return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1 | ||
512 | } | ||
513 | |||
514 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | ||
515 | } | ||
516 | |||
463 | async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { | 517 | async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { |
464 | const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS | 518 | const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS |
465 | 519 | ||
@@ -516,7 +570,7 @@ function getAllNotificationsSettings () { | |||
516 | return { | 570 | return { |
517 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 571 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
518 | newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 572 | newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
519 | videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 573 | abuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
520 | videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 574 | videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
521 | blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 575 | blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
522 | myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 576 | myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
@@ -541,6 +595,9 @@ async function prepareNotificationsTest (serversCount = 3) { | |||
541 | smtp: { | 595 | smtp: { |
542 | hostname: 'localhost', | 596 | hostname: 'localhost', |
543 | port | 597 | port |
598 | }, | ||
599 | signup: { | ||
600 | limit: 20 | ||
544 | } | 601 | } |
545 | } | 602 | } |
546 | const servers = await flushAndRunMultipleServers(serversCount, overrideConfig) | 603 | const servers = await flushAndRunMultipleServers(serversCount, overrideConfig) |
@@ -623,5 +680,7 @@ export { | |||
623 | markAsReadNotifications, | 680 | markAsReadNotifications, |
624 | getLastNotification, | 681 | getLastNotification, |
625 | checkNewInstanceFollower, | 682 | checkNewInstanceFollower, |
626 | prepareNotificationsTest | 683 | prepareNotificationsTest, |
684 | checkNewCommentAbuseForModerators, | ||
685 | checkNewAccountAbuseForModerators | ||
627 | } | 686 | } |