diff options
author | Chocobozzz <me@florianbigard.com> | 2019-01-04 08:56:20 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-01-09 11:15:15 +0100 |
commit | f7cc67b455a12ccae9b0ea16876d166720364357 (patch) | |
tree | eac2cdbf2e92a16b3eda5d74371c82bd79ae22cb /server/tests/api/users/user-notifications.ts | |
parent | dc13348070d808d0ba3feb56a435b835c2e7e791 (diff) | |
download | PeerTube-f7cc67b455a12ccae9b0ea16876d166720364357.tar.gz PeerTube-f7cc67b455a12ccae9b0ea16876d166720364357.tar.zst PeerTube-f7cc67b455a12ccae9b0ea16876d166720364357.zip |
Add new follow, mention and user registered notifs
Diffstat (limited to 'server/tests/api/users/user-notifications.ts')
-rw-r--r-- | server/tests/api/users/user-notifications.ts | 229 |
1 files changed, 221 insertions, 8 deletions
diff --git a/server/tests/api/users/user-notifications.ts b/server/tests/api/users/user-notifications.ts index e4966dbf5..ae77b4db2 100644 --- a/server/tests/api/users/user-notifications.ts +++ b/server/tests/api/users/user-notifications.ts | |||
@@ -10,9 +10,12 @@ import { | |||
10 | flushTests, | 10 | flushTests, |
11 | getMyUserInformation, | 11 | getMyUserInformation, |
12 | immutableAssign, | 12 | immutableAssign, |
13 | registerUser, | ||
13 | removeVideoFromBlacklist, | 14 | removeVideoFromBlacklist, |
14 | reportVideoAbuse, | 15 | reportVideoAbuse, |
16 | updateMyUser, | ||
15 | updateVideo, | 17 | updateVideo, |
18 | updateVideoChannel, | ||
16 | userLogin, | 19 | userLogin, |
17 | wait | 20 | wait |
18 | } from '../../../../shared/utils' | 21 | } from '../../../../shared/utils' |
@@ -21,16 +24,20 @@ import { setAccessTokensToServers } from '../../../../shared/utils/users/login' | |||
21 | import { waitJobs } from '../../../../shared/utils/server/jobs' | 24 | import { waitJobs } from '../../../../shared/utils/server/jobs' |
22 | import { getUserNotificationSocket } from '../../../../shared/utils/socket/socket-io' | 25 | import { getUserNotificationSocket } from '../../../../shared/utils/socket/socket-io' |
23 | import { | 26 | import { |
27 | checkCommentMention, | ||
24 | CheckerBaseParams, | 28 | CheckerBaseParams, |
29 | checkMyVideoImportIsFinished, | ||
30 | checkNewActorFollow, | ||
25 | checkNewBlacklistOnMyVideo, | 31 | checkNewBlacklistOnMyVideo, |
26 | checkNewCommentOnMyVideo, | 32 | checkNewCommentOnMyVideo, |
27 | checkNewVideoAbuseForModerators, | 33 | checkNewVideoAbuseForModerators, |
28 | checkNewVideoFromSubscription, | 34 | checkNewVideoFromSubscription, |
35 | checkUserRegistered, | ||
36 | checkVideoIsPublished, | ||
29 | getLastNotification, | 37 | getLastNotification, |
30 | getUserNotifications, | 38 | getUserNotifications, |
31 | markAsReadNotifications, | 39 | markAsReadNotifications, |
32 | updateMyNotificationSettings, | 40 | updateMyNotificationSettings |
33 | checkVideoIsPublished, checkMyVideoImportIsFinished | ||
34 | } from '../../../../shared/utils/users/user-notifications' | 41 | } from '../../../../shared/utils/users/user-notifications' |
35 | import { | 42 | import { |
36 | User, | 43 | User, |
@@ -40,9 +47,9 @@ import { | |||
40 | UserNotificationType | 47 | UserNotificationType |
41 | } from '../../../../shared/models/users' | 48 | } from '../../../../shared/models/users' |
42 | import { MockSmtpServer } from '../../../../shared/utils/miscs/email' | 49 | import { MockSmtpServer } from '../../../../shared/utils/miscs/email' |
43 | import { addUserSubscription } from '../../../../shared/utils/users/user-subscriptions' | 50 | import { addUserSubscription, removeUserSubscription } from '../../../../shared/utils/users/user-subscriptions' |
44 | import { VideoPrivacy } from '../../../../shared/models/videos' | 51 | import { VideoPrivacy } from '../../../../shared/models/videos' |
45 | import { getYoutubeVideoUrl, importVideo, getBadVideoUrl } from '../../../../shared/utils/videos/video-imports' | 52 | import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports' |
46 | import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments' | 53 | import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments' |
47 | import * as uuidv4 from 'uuid/v4' | 54 | import * as uuidv4 from 'uuid/v4' |
48 | import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist' | 55 | import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist' |
@@ -81,12 +88,15 @@ describe('Test users notifications', function () { | |||
81 | let channelId: number | 88 | let channelId: number |
82 | 89 | ||
83 | const allNotificationSettings: UserNotificationSetting = { | 90 | const allNotificationSettings: UserNotificationSetting = { |
84 | myVideoPublished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, | ||
85 | myVideoImportFinished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, | ||
86 | newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, | ||
87 | newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, | 91 | newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, |
92 | newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, | ||
88 | videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, | 93 | videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, |
89 | blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL | 94 | blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, |
95 | myVideoImportFinished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, | ||
96 | myVideoPublished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, | ||
97 | commentMention: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, | ||
98 | newFollow: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, | ||
99 | newUserRegistration: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL | ||
90 | } | 100 | } |
91 | 101 | ||
92 | before(async function () { | 102 | before(async function () { |
@@ -424,6 +434,114 @@ describe('Test users notifications', function () { | |||
424 | }) | 434 | }) |
425 | }) | 435 | }) |
426 | 436 | ||
437 | describe('Mention notifications', function () { | ||
438 | let baseParams: CheckerBaseParams | ||
439 | |||
440 | before(async () => { | ||
441 | baseParams = { | ||
442 | server: servers[0], | ||
443 | emails, | ||
444 | socketNotifications: userNotifications, | ||
445 | token: userAccessToken | ||
446 | } | ||
447 | |||
448 | await updateMyUser({ | ||
449 | url: servers[0].url, | ||
450 | accessToken: servers[0].accessToken, | ||
451 | displayName: 'super root name' | ||
452 | }) | ||
453 | |||
454 | await updateMyUser({ | ||
455 | url: servers[1].url, | ||
456 | accessToken: servers[1].accessToken, | ||
457 | displayName: 'super root 2 name' | ||
458 | }) | ||
459 | }) | ||
460 | |||
461 | it('Should not send a new mention comment notification if I mention the video owner', async function () { | ||
462 | this.timeout(10000) | ||
463 | |||
464 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
465 | const uuid = resVideo.body.video.uuid | ||
466 | |||
467 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') | ||
468 | const commentId = resComment.body.comment.id | ||
469 | |||
470 | await wait(500) | ||
471 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | ||
472 | }) | ||
473 | |||
474 | it('Should not send a new mention comment notification if I mention myself', async function () { | ||
475 | this.timeout(10000) | ||
476 | |||
477 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
478 | const uuid = resVideo.body.video.uuid | ||
479 | |||
480 | const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello') | ||
481 | const commentId = resComment.body.comment.id | ||
482 | |||
483 | await wait(500) | ||
484 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | ||
485 | }) | ||
486 | |||
487 | it('Should not send a new mention notification if the account is muted', async function () { | ||
488 | this.timeout(10000) | ||
489 | |||
490 | await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root') | ||
491 | |||
492 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
493 | const uuid = resVideo.body.video.uuid | ||
494 | |||
495 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') | ||
496 | const commentId = resComment.body.comment.id | ||
497 | |||
498 | await wait(500) | ||
499 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | ||
500 | |||
501 | await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root') | ||
502 | }) | ||
503 | |||
504 | it('Should send a new mention notification after local comments', async function () { | ||
505 | this.timeout(10000) | ||
506 | |||
507 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
508 | const uuid = resVideo.body.video.uuid | ||
509 | |||
510 | const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1') | ||
511 | const threadId = resThread.body.comment.id | ||
512 | |||
513 | await wait(500) | ||
514 | await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence') | ||
515 | |||
516 | const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1') | ||
517 | const commentId = resComment.body.comment.id | ||
518 | |||
519 | await wait(500) | ||
520 | await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence') | ||
521 | }) | ||
522 | |||
523 | it('Should send a new mention notification after remote comments', async function () { | ||
524 | this.timeout(20000) | ||
525 | |||
526 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
527 | const uuid = resVideo.body.video.uuid | ||
528 | |||
529 | await waitJobs(servers) | ||
530 | const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1') | ||
531 | const threadId = resThread.body.comment.id | ||
532 | |||
533 | await waitJobs(servers) | ||
534 | await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'presence') | ||
535 | |||
536 | const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001' | ||
537 | const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, text) | ||
538 | const commentId = resComment.body.comment.id | ||
539 | |||
540 | await waitJobs(servers) | ||
541 | await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root 2 name', 'presence') | ||
542 | }) | ||
543 | }) | ||
544 | |||
427 | describe('Video abuse for moderators notification' , function () { | 545 | describe('Video abuse for moderators notification' , function () { |
428 | let baseParams: CheckerBaseParams | 546 | let baseParams: CheckerBaseParams |
429 | 547 | ||
@@ -645,6 +763,101 @@ describe('Test users notifications', function () { | |||
645 | }) | 763 | }) |
646 | }) | 764 | }) |
647 | 765 | ||
766 | describe('New registration', function () { | ||
767 | let baseParams: CheckerBaseParams | ||
768 | |||
769 | before(() => { | ||
770 | baseParams = { | ||
771 | server: servers[0], | ||
772 | emails, | ||
773 | socketNotifications: adminNotifications, | ||
774 | token: servers[0].accessToken | ||
775 | } | ||
776 | }) | ||
777 | |||
778 | it('Should send a notification only to moderators when a user registers on the instance', async function () { | ||
779 | await registerUser(servers[0].url, 'user_45', 'password') | ||
780 | |||
781 | await waitJobs(servers) | ||
782 | |||
783 | await checkUserRegistered(baseParams, 'user_45', 'presence') | ||
784 | |||
785 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | ||
786 | await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence') | ||
787 | }) | ||
788 | }) | ||
789 | |||
790 | describe('New actor follow', function () { | ||
791 | let baseParams: CheckerBaseParams | ||
792 | let myChannelName = 'super channel name' | ||
793 | let myUserName = 'super user name' | ||
794 | |||
795 | before(async () => { | ||
796 | baseParams = { | ||
797 | server: servers[0], | ||
798 | emails, | ||
799 | socketNotifications: userNotifications, | ||
800 | token: userAccessToken | ||
801 | } | ||
802 | |||
803 | await updateMyUser({ | ||
804 | url: servers[0].url, | ||
805 | accessToken: servers[0].accessToken, | ||
806 | displayName: 'super root name' | ||
807 | }) | ||
808 | |||
809 | await updateMyUser({ | ||
810 | url: servers[0].url, | ||
811 | accessToken: userAccessToken, | ||
812 | displayName: myUserName | ||
813 | }) | ||
814 | |||
815 | await updateMyUser({ | ||
816 | url: servers[1].url, | ||
817 | accessToken: servers[1].accessToken, | ||
818 | displayName: 'super root 2 name' | ||
819 | }) | ||
820 | |||
821 | await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName }) | ||
822 | }) | ||
823 | |||
824 | it('Should notify when a local channel is following one of our channel', async function () { | ||
825 | await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') | ||
826 | |||
827 | await waitJobs(servers) | ||
828 | |||
829 | await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') | ||
830 | |||
831 | await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') | ||
832 | }) | ||
833 | |||
834 | it('Should notify when a remote channel is following one of our channel', async function () { | ||
835 | await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') | ||
836 | |||
837 | await waitJobs(servers) | ||
838 | |||
839 | await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') | ||
840 | |||
841 | await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') | ||
842 | }) | ||
843 | |||
844 | it('Should notify when a local account is following one of our channel', async function () { | ||
845 | await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001') | ||
846 | |||
847 | await waitJobs(servers) | ||
848 | |||
849 | await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence') | ||
850 | }) | ||
851 | |||
852 | it('Should notify when a remote account is following one of our channel', async function () { | ||
853 | await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001') | ||
854 | |||
855 | await waitJobs(servers) | ||
856 | |||
857 | await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence') | ||
858 | }) | ||
859 | }) | ||
860 | |||
648 | describe('Mark as read', function () { | 861 | describe('Mark as read', function () { |
649 | it('Should mark as read some notifications', async function () { | 862 | it('Should mark as read some notifications', async function () { |
650 | const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3) | 863 | const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3) |