From 9639bd175726b73f8fe664b5ced12a72407b1f0b Mon Sep 17 00:00:00 2001 From: buoyantair Date: Mon, 29 Oct 2018 22:18:31 +0530 Subject: Move utils to /shared Move utils used by /server/tools/* & /server/tests/**/* into /shared folder. Issue: #1336 --- server/tests/api/users/blocklist.ts | 12 ++++++------ server/tests/api/users/user-subscriptions.ts | 19 ++++++++++++++----- server/tests/api/users/users-multiple-servers.ts | 10 +++++----- server/tests/api/users/users-verification.ts | 8 ++++---- server/tests/api/users/users.ts | 8 ++++---- 5 files changed, 33 insertions(+), 24 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/blocklist.ts b/server/tests/api/users/blocklist.ts index eed4b9f3e..4bca27a94 100644 --- a/server/tests/api/users/blocklist.ts +++ b/server/tests/api/users/blocklist.ts @@ -12,16 +12,16 @@ import { ServerInfo, uploadVideo, userLogin -} from '../../utils/index' -import { setAccessTokensToServers } from '../../utils/users/login' -import { getVideosListWithToken, getVideosList } from '../../utils/videos/videos' +} from '../../../../shared/utils/index' +import { setAccessTokensToServers } from '../../../../shared/utils/users/login' +import { getVideosListWithToken, getVideosList } from '../../../../shared/utils/videos/videos' import { addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, getVideoThreadComments -} from '../../utils/videos/video-comments' -import { waitJobs } from '../../utils/server/jobs' +} from '../../../../shared/utils/videos/video-comments' +import { waitJobs } from '../../../../shared/utils/server/jobs' import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' import { addAccountToAccountBlocklist, @@ -36,7 +36,7 @@ import { removeAccountFromServerBlocklist, removeServerFromAccountBlocklist, removeServerFromServerBlocklist -} from '../../utils/users/blocklist' +} from '../../../../shared/utils/users/blocklist' const expect = chai.expect diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 65b80540c..88a7187d6 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -2,18 +2,27 @@ import * as chai from 'chai' import 'mocha' -import { createUser, doubleFollow, flushAndRunMultipleServers, follow, getVideosList, unfollow, updateVideo, userLogin } from '../../utils' -import { killallServers, ServerInfo, uploadVideo } from '../../utils/index' -import { setAccessTokensToServers } from '../../utils/users/login' +import { + createUser, + doubleFollow, + flushAndRunMultipleServers, + follow, + getVideosList, + unfollow, + updateVideo, + userLogin +} from '../../../../shared/utils' +import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index' +import { setAccessTokensToServers } from '../../../../shared/utils/users/login' import { Video, VideoChannel } from '../../../../shared/models/videos' -import { waitJobs } from '../../utils/server/jobs' +import { waitJobs } from '../../../../shared/utils/server/jobs' import { addUserSubscription, listUserSubscriptions, listUserSubscriptionVideos, removeUserSubscription, getUserSubscription, areSubscriptionsExist -} from '../../utils/users/user-subscriptions' +} from '../../../../shared/utils/users/user-subscriptions' const expect = chai.expect diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index d8699db17..006d6cdf0 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -13,13 +13,13 @@ import { removeUser, updateMyUser, userLogin -} from '../../utils' -import { getMyUserInformation, killallServers, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../utils/index' -import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../utils/users/accounts' -import { setAccessTokensToServers } from '../../utils/users/login' +} from '../../../../shared/utils' +import { getMyUserInformation, killallServers, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/utils/index' +import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/utils/users/accounts' +import { setAccessTokensToServers } from '../../../../shared/utils/users/login' import { User } from '../../../../shared/models/users' import { VideoChannel } from '../../../../shared/models/videos' -import { waitJobs } from '../../utils/server/jobs' +import { waitJobs } from '../../../../shared/utils/server/jobs' const expect = chai.expect diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index fa5f5e371..b1733e45e 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -5,10 +5,10 @@ import 'mocha' import { registerUser, flushTests, getUserInformation, getMyUserInformation, killallServers, userLogin, login, runServer, ServerInfo, verifyEmail, updateCustomSubConfig -} from '../../utils' -import { setAccessTokensToServers } from '../../utils/users/login' -import { mockSmtpServer } from '../../utils/miscs/email' -import { waitJobs } from '../../utils/server/jobs' +} from '../../../../shared/utils' +import { setAccessTokensToServers } from '../../../../shared/utils/users/login' +import { mockSmtpServer } from '../../../../shared/utils/miscs/email' +import { waitJobs } from '../../../../shared/utils/server/jobs' const expect = chai.expect diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 513bca8a0..7dffbb0b1 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -32,10 +32,10 @@ import { updateUser, uploadVideo, userLogin -} from '../../utils/index' -import { follow } from '../../utils/server/follows' -import { setAccessTokensToServers } from '../../utils/users/login' -import { getMyVideos } from '../../utils/videos/videos' +} from '../../../../shared/utils/index' +import { follow } from '../../../../shared/utils/server/follows' +import { setAccessTokensToServers } from '../../../../shared/utils/users/login' +import { getMyVideos } from '../../../../shared/utils/videos/videos' const expect = chai.expect -- cgit v1.2.3 From af37210c0bd7bf343fe366ddd2b253e2214f5547 Mon Sep 17 00:00:00 2001 From: Josh Morel Date: Sat, 15 Dec 2018 08:51:51 -0500 Subject: throw error if MailDev doesn't run also allow calling in multiple file --- server/tests/api/users/users-verification.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index b1733e45e..afc8a0059 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -7,7 +7,7 @@ import { userLogin, login, runServer, ServerInfo, verifyEmail, updateCustomSubConfig } from '../../../../shared/utils' import { setAccessTokensToServers } from '../../../../shared/utils/users/login' -import { mockSmtpServer } from '../../../../shared/utils/miscs/email' +import { MockSmtpServer } from '../../../../shared/utils/miscs/email' import { waitJobs } from '../../../../shared/utils/server/jobs' const expect = chai.expect @@ -30,7 +30,7 @@ describe('Test users account verification', function () { before(async function () { this.timeout(30000) - await mockSmtpServer(emails) + await MockSmtpServer.Instance.collectEmails(emails) await flushTests() -- cgit v1.2.3 From cef534ed53e4518fe0acf581bfe880788d42fc36 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 26 Dec 2018 10:36:24 +0100 Subject: Add user notification base code --- server/tests/api/users/index.ts | 1 + server/tests/api/users/user-notifications.ts | 628 +++++++++++++++++++++++++++ 2 files changed, 629 insertions(+) create mode 100644 server/tests/api/users/user-notifications.ts (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/index.ts b/server/tests/api/users/index.ts index ff433315d..63e6e827a 100644 --- a/server/tests/api/users/index.ts +++ b/server/tests/api/users/index.ts @@ -1,5 +1,6 @@ import './blocklist' import './user-subscriptions' +import './user-notifications' import './users' import './users-multiple-servers' import './users-verification' diff --git a/server/tests/api/users/user-notifications.ts b/server/tests/api/users/user-notifications.ts new file mode 100644 index 000000000..ea35e6390 --- /dev/null +++ b/server/tests/api/users/user-notifications.ts @@ -0,0 +1,628 @@ +/* tslint:disable:no-unused-expression */ + +import * as chai from 'chai' +import 'mocha' +import { + addVideoToBlacklist, + createUser, + doubleFollow, + flushAndRunMultipleServers, + flushTests, + getMyUserInformation, + immutableAssign, + removeVideoFromBlacklist, + reportVideoAbuse, + updateVideo, + userLogin, + wait +} from '../../../../shared/utils' +import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index' +import { setAccessTokensToServers } from '../../../../shared/utils/users/login' +import { waitJobs } from '../../../../shared/utils/server/jobs' +import { getUserNotificationSocket } from '../../../../shared/utils/socket/socket-io' +import { + CheckerBaseParams, + checkNewBlacklistOnMyVideo, + checkNewCommentOnMyVideo, + checkNewVideoAbuseForModerators, + checkNewVideoFromSubscription, + getLastNotification, + getUserNotifications, + markAsReadNotifications, + updateMyNotificationSettings +} from '../../../../shared/utils/users/user-notifications' +import { User, UserNotification, UserNotificationSettingValue } from '../../../../shared/models/users' +import { MockSmtpServer } from '../../../../shared/utils/miscs/email' +import { addUserSubscription } from '../../../../shared/utils/users/user-subscriptions' +import { VideoPrivacy } from '../../../../shared/models/videos' +import { getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports' +import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments' + +const expect = chai.expect + +async function uploadVideoByRemoteAccount (servers: ServerInfo[], videoNameId: number, additionalParams: any = {}) { + const data = Object.assign({ name: 'remote video ' + videoNameId }, additionalParams) + const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data) + + await waitJobs(servers) + + return res.body.video.uuid +} + +async function uploadVideoByLocalAccount (servers: ServerInfo[], videoNameId: number, additionalParams: any = {}) { + const data = Object.assign({ name: 'local video ' + videoNameId }, additionalParams) + const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data) + + await waitJobs(servers) + + return res.body.video.uuid +} + +describe('Test users notifications', function () { + let servers: ServerInfo[] = [] + let userAccessToken: string + let userNotifications: UserNotification[] = [] + let adminNotifications: UserNotification[] = [] + const emails: object[] = [] + + before(async function () { + this.timeout(120000) + + await MockSmtpServer.Instance.collectEmails(emails) + + await flushTests() + + const overrideConfig = { + smtp: { + hostname: 'localhost' + } + } + servers = await flushAndRunMultipleServers(2, overrideConfig) + + // Get the access tokens + await setAccessTokensToServers(servers) + + // Server 1 and server 2 follow each other + await doubleFollow(servers[0], servers[1]) + + await waitJobs(servers) + + const user = { + username: 'user_1', + password: 'super password' + } + await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000) + userAccessToken = await userLogin(servers[0], user) + + await updateMyNotificationSettings(servers[0].url, userAccessToken, { + newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL + }) + + { + const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken) + socket.on('new-notification', n => userNotifications.push(n)) + } + { + const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken) + socket.on('new-notification', n => adminNotifications.push(n)) + } + }) + + describe('New video from my subscription notification', function () { + let baseParams: CheckerBaseParams + + before(() => { + baseParams = { + server: servers[0], + emails, + socketNotifications: userNotifications, + token: userAccessToken + } + }) + + it('Should not send notifications if the user does not follow the video publisher', async function () { + await uploadVideoByLocalAccount(servers, 1) + + const notification = await getLastNotification(servers[ 0 ].url, userAccessToken) + expect(notification).to.be.undefined + + expect(emails).to.have.lengthOf(0) + expect(userNotifications).to.have.lengthOf(0) + }) + + it('Should send a new video notification if the user follows the local video publisher', async function () { + await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001') + + const videoNameId = 10 + const videoName = 'local video ' + videoNameId + + const uuid = await uploadVideoByLocalAccount(servers, videoNameId) + await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + }) + + it('Should send a new video notification from a remote account', async function () { + this.timeout(50000) // Server 2 has transcoding enabled + + await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002') + + const videoNameId = 20 + const videoName = 'remote video ' + videoNameId + + const uuid = await uploadVideoByRemoteAccount(servers, videoNameId) + await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + }) + + it('Should send a new video notification on a scheduled publication', async function () { + this.timeout(20000) + + const videoNameId = 30 + const videoName = 'local video ' + videoNameId + + // In 2 seconds + let updateAt = new Date(new Date().getTime() + 2000) + + const data = { + privacy: VideoPrivacy.PRIVATE, + scheduleUpdate: { + updateAt: updateAt.toISOString(), + privacy: VideoPrivacy.PUBLIC + } + } + const uuid = await uploadVideoByLocalAccount(servers, videoNameId, data) + + await wait(6000) + await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + }) + + it('Should send a new video notification on a remote scheduled publication', async function () { + this.timeout(20000) + + const videoNameId = 40 + const videoName = 'remote video ' + videoNameId + + // In 2 seconds + let updateAt = new Date(new Date().getTime() + 2000) + + const data = { + privacy: VideoPrivacy.PRIVATE, + scheduleUpdate: { + updateAt: updateAt.toISOString(), + privacy: VideoPrivacy.PUBLIC + } + } + const uuid = await uploadVideoByRemoteAccount(servers, videoNameId, data) + + await wait(6000) + await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + }) + + it('Should not send a notification before the video is published', async function () { + this.timeout(20000) + + const videoNameId = 50 + const videoName = 'local video ' + videoNameId + + let updateAt = new Date(new Date().getTime() + 100000) + + const data = { + privacy: VideoPrivacy.PRIVATE, + scheduleUpdate: { + updateAt: updateAt.toISOString(), + privacy: VideoPrivacy.PUBLIC + } + } + const uuid = await uploadVideoByLocalAccount(servers, videoNameId, data) + + await wait(6000) + await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') + }) + + it('Should send a new video notification when a video becomes public', async function () { + this.timeout(10000) + + const videoNameId = 60 + const videoName = 'local video ' + videoNameId + + const data = { privacy: VideoPrivacy.PRIVATE } + const uuid = await uploadVideoByLocalAccount(servers, videoNameId, data) + + await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') + + await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) + + await wait(500) + await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + }) + + it('Should send a new video notification when a remote video becomes public', async function () { + this.timeout(20000) + + const videoNameId = 70 + const videoName = 'remote video ' + videoNameId + + const data = { privacy: VideoPrivacy.PRIVATE } + const uuid = await uploadVideoByRemoteAccount(servers, videoNameId, data) + + await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') + + await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) + + await waitJobs(servers) + await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + }) + + it('Should not send a new video notification when a video becomes unlisted', async function () { + this.timeout(20000) + + const videoNameId = 80 + const videoName = 'local video ' + videoNameId + + const data = { privacy: VideoPrivacy.PRIVATE } + const uuid = await uploadVideoByLocalAccount(servers, videoNameId, data) + + await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) + + await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') + }) + + it('Should not send a new video notification when a remote video becomes unlisted', async function () { + this.timeout(20000) + + const videoNameId = 90 + const videoName = 'remote video ' + videoNameId + + const data = { privacy: VideoPrivacy.PRIVATE } + const uuid = await uploadVideoByRemoteAccount(servers, videoNameId, data) + + await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) + + await waitJobs(servers) + await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') + }) + + it('Should send a new video notification after a video import', async function () { + this.timeout(30000) + + const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken) + const channelId = resChannel.body.videoChannels[0].id + const videoName = 'local video 100' + + const attributes = { + name: videoName, + channelId, + privacy: VideoPrivacy.PUBLIC, + targetUrl: getYoutubeVideoUrl() + } + const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) + const uuid = res.body.video.uuid + + await waitJobs(servers) + + await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + }) + }) + + describe('Comment on my video notifications', function () { + let baseParams: CheckerBaseParams + + before(() => { + baseParams = { + server: servers[0], + emails, + socketNotifications: userNotifications, + token: userAccessToken + } + }) + + it('Should not send a new comment notification after a comment on another video', async function () { + this.timeout(10000) + + const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) + const uuid = resVideo.body.video.uuid + + const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') + const commentId = resComment.body.comment.id + + await wait(500) + await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') + }) + + it('Should not send a new comment notification if I comment my own video', async function () { + this.timeout(10000) + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) + const uuid = resVideo.body.video.uuid + + const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment') + const commentId = resComment.body.comment.id + + await wait(500) + await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') + }) + + it('Should send a new comment notification after a local comment on my video', async function () { + this.timeout(10000) + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) + const uuid = resVideo.body.video.uuid + + const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') + const commentId = resComment.body.comment.id + + await wait(500) + await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') + }) + + it('Should send a new comment notification after a remote comment on my video', async function () { + this.timeout(10000) + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) + const uuid = resVideo.body.video.uuid + + await waitJobs(servers) + + const resComment = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment') + const commentId = resComment.body.comment.id + + await waitJobs(servers) + await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') + }) + + it('Should send a new comment notification after a local reply on my video', async function () { + this.timeout(10000) + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) + const uuid = resVideo.body.video.uuid + + const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') + const threadId = resThread.body.comment.id + + const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply') + const commentId = resComment.body.comment.id + + await wait(500) + await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') + }) + + it('Should send a new comment notification after a remote reply on my video', async function () { + this.timeout(10000) + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) + const uuid = resVideo.body.video.uuid + await waitJobs(servers) + + const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment') + const threadId = resThread.body.comment.id + + const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply') + const commentId = resComment.body.comment.id + + await waitJobs(servers) + await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') + }) + }) + + describe('Video abuse for moderators notification' , function () { + let baseParams: CheckerBaseParams + + before(() => { + baseParams = { + server: servers[0], + emails, + socketNotifications: adminNotifications, + token: servers[0].accessToken + } + }) + + it('Should send a notification to moderators on local video abuse', async function () { + this.timeout(10000) + + const videoName = 'local video 110' + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) + const uuid = resVideo.body.video.uuid + + await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason') + + await waitJobs(servers) + await checkNewVideoAbuseForModerators(baseParams, uuid, videoName, 'presence') + }) + + it('Should send a notification to moderators on remote video abuse', async function () { + this.timeout(10000) + + const videoName = 'remote video 120' + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) + const uuid = resVideo.body.video.uuid + + await waitJobs(servers) + + await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason') + + await waitJobs(servers) + await checkNewVideoAbuseForModerators(baseParams, uuid, videoName, 'presence') + }) + }) + + describe('Video blacklist on my video', function () { + let baseParams: CheckerBaseParams + + before(() => { + baseParams = { + server: servers[0], + emails, + socketNotifications: userNotifications, + token: userAccessToken + } + }) + + it('Should send a notification to video owner on blacklist', async function () { + this.timeout(10000) + + const videoName = 'local video 130' + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) + const uuid = resVideo.body.video.uuid + + await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) + + await waitJobs(servers) + await checkNewBlacklistOnMyVideo(baseParams, uuid, videoName, 'blacklist') + }) + + it('Should send a notification to video owner on unblacklist', async function () { + this.timeout(10000) + + const videoName = 'local video 130' + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) + const uuid = resVideo.body.video.uuid + + await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) + + await waitJobs(servers) + await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) + await waitJobs(servers) + + await wait(500) + await checkNewBlacklistOnMyVideo(baseParams, uuid, videoName, 'unblacklist') + }) + }) + + describe('Mark as read', function () { + it('Should mark as read some notifications', async function () { + const res = await getUserNotifications(servers[0].url, userAccessToken, 2, 3) + const ids = res.body.data.map(n => n.id) + + await markAsReadNotifications(servers[0].url, userAccessToken, ids) + }) + + it('Should have the notifications marked as read', async function () { + const res = await getUserNotifications(servers[0].url, userAccessToken, 0, 10) + + const notifications = res.body.data as UserNotification[] + expect(notifications[0].read).to.be.false + expect(notifications[1].read).to.be.false + expect(notifications[2].read).to.be.true + expect(notifications[3].read).to.be.true + expect(notifications[4].read).to.be.true + expect(notifications[5].read).to.be.false + }) + }) + + describe('Notification settings', function () { + const baseUpdateNotificationParams = { + newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL + } + let baseParams: CheckerBaseParams + + before(() => { + baseParams = { + server: servers[0], + emails, + socketNotifications: userNotifications, + token: userAccessToken + } + }) + + it('Should not have notifications', async function () { + await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(baseUpdateNotificationParams, { + newVideoFromSubscription: UserNotificationSettingValue.NONE + })) + + { + const res = await getMyUserInformation(servers[0].url, userAccessToken) + const info = res.body as User + expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) + } + + const videoNameId = 42 + const videoName = 'local video ' + videoNameId + const uuid = await uploadVideoByLocalAccount(servers, videoNameId) + + const check = { web: true, mail: true } + await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'absence') + }) + + it('Should only have web notifications', async function () { + await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(baseUpdateNotificationParams, { + newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION + })) + + { + const res = await getMyUserInformation(servers[0].url, userAccessToken) + const info = res.body as User + expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB_NOTIFICATION) + } + + const videoNameId = 52 + const videoName = 'local video ' + videoNameId + const uuid = await uploadVideoByLocalAccount(servers, videoNameId) + + { + const check = { mail: true, web: false } + await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'absence') + } + + { + const check = { mail: false, web: true } + await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'presence') + } + }) + + it('Should only have mail notifications', async function () { + await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(baseUpdateNotificationParams, { + newVideoFromSubscription: UserNotificationSettingValue.EMAIL + })) + + { + const res = await getMyUserInformation(servers[0].url, userAccessToken) + const info = res.body as User + expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) + } + + const videoNameId = 62 + const videoName = 'local video ' + videoNameId + const uuid = await uploadVideoByLocalAccount(servers, videoNameId) + + { + const check = { mail: false, web: true } + await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'absence') + } + + { + const check = { mail: true, web: false } + await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'presence') + } + }) + + it('Should have email and web notifications', async function () { + await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(baseUpdateNotificationParams, { + newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL + })) + + { + const res = await getMyUserInformation(servers[0].url, userAccessToken) + const info = res.body as User + expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL) + } + + const videoNameId = 72 + const videoName = 'local video ' + videoNameId + const uuid = await uploadVideoByLocalAccount(servers, videoNameId) + + await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + }) + }) + + after(async function () { + killallServers(servers) + }) +}) -- cgit v1.2.3 From e8d246d5267ea8b6b3114d4bcf4f34fe5f3a5241 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 28 Dec 2018 13:47:17 +0100 Subject: Add notification settings migration --- server/tests/api/users/user-notifications.ts | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/user-notifications.ts b/server/tests/api/users/user-notifications.ts index ea35e6390..09c0479fd 100644 --- a/server/tests/api/users/user-notifications.ts +++ b/server/tests/api/users/user-notifications.ts @@ -152,6 +152,8 @@ describe('Test users notifications', function () { const videoName = 'remote video ' + videoNameId const uuid = await uploadVideoByRemoteAccount(servers, videoNameId) + await waitJobs(servers) + await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') }) @@ -194,6 +196,7 @@ describe('Test users notifications', function () { } } const uuid = await uploadVideoByRemoteAccount(servers, videoNameId, data) + await waitJobs(servers) await wait(6000) await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') @@ -245,6 +248,7 @@ describe('Test users notifications', function () { const data = { privacy: VideoPrivacy.PRIVATE } const uuid = await uploadVideoByRemoteAccount(servers, videoNameId, data) + await waitJobs(servers) await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') @@ -276,6 +280,7 @@ describe('Test users notifications', function () { const data = { privacy: VideoPrivacy.PRIVATE } const uuid = await uploadVideoByRemoteAccount(servers, videoNameId, data) + await waitJobs(servers) await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) -- cgit v1.2.3 From dc13348070d808d0ba3feb56a435b835c2e7e791 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 2 Jan 2019 16:37:43 +0100 Subject: Add import finished and video published notifs --- server/tests/api/users/user-notifications.ts | 401 ++++++++++++++++++--------- 1 file changed, 276 insertions(+), 125 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/user-notifications.ts b/server/tests/api/users/user-notifications.ts index 09c0479fd..e4966dbf5 100644 --- a/server/tests/api/users/user-notifications.ts +++ b/server/tests/api/users/user-notifications.ts @@ -29,33 +29,46 @@ import { getLastNotification, getUserNotifications, markAsReadNotifications, - updateMyNotificationSettings + updateMyNotificationSettings, + checkVideoIsPublished, checkMyVideoImportIsFinished } from '../../../../shared/utils/users/user-notifications' -import { User, UserNotification, UserNotificationSettingValue } from '../../../../shared/models/users' +import { + User, + UserNotification, + UserNotificationSetting, + UserNotificationSettingValue, + UserNotificationType +} from '../../../../shared/models/users' import { MockSmtpServer } from '../../../../shared/utils/miscs/email' import { addUserSubscription } from '../../../../shared/utils/users/user-subscriptions' import { VideoPrivacy } from '../../../../shared/models/videos' -import { getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports' +import { getYoutubeVideoUrl, importVideo, getBadVideoUrl } from '../../../../shared/utils/videos/video-imports' import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments' +import * as uuidv4 from 'uuid/v4' +import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist' const expect = chai.expect -async function uploadVideoByRemoteAccount (servers: ServerInfo[], videoNameId: number, additionalParams: any = {}) { - const data = Object.assign({ name: 'remote video ' + videoNameId }, additionalParams) +async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) { + const name = 'remote video ' + uuidv4() + + const data = Object.assign({ name }, additionalParams) const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data) await waitJobs(servers) - return res.body.video.uuid + return { uuid: res.body.video.uuid, name } } -async function uploadVideoByLocalAccount (servers: ServerInfo[], videoNameId: number, additionalParams: any = {}) { - const data = Object.assign({ name: 'local video ' + videoNameId }, additionalParams) +async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) { + const name = 'local video ' + uuidv4() + + const data = Object.assign({ name }, additionalParams) const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data) await waitJobs(servers) - return res.body.video.uuid + return { uuid: res.body.video.uuid, name } } describe('Test users notifications', function () { @@ -63,7 +76,18 @@ describe('Test users notifications', function () { let userAccessToken: string let userNotifications: UserNotification[] = [] let adminNotifications: UserNotification[] = [] + let adminNotificationsServer2: UserNotification[] = [] const emails: object[] = [] + let channelId: number + + const allNotificationSettings: UserNotificationSetting = { + myVideoPublished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + myVideoImportFinished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL + } before(async function () { this.timeout(120000) @@ -94,12 +118,9 @@ describe('Test users notifications', function () { await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000) userAccessToken = await userLogin(servers[0], user) - await updateMyNotificationSettings(servers[0].url, userAccessToken, { - newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL - }) + await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings) + await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings) + await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings) { const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken) @@ -109,6 +130,15 @@ describe('Test users notifications', function () { const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken) socket.on('new-notification', n => adminNotifications.push(n)) } + { + const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken) + socket.on('new-notification', n => adminNotificationsServer2.push(n)) + } + + { + const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken) + channelId = resChannel.body.videoChannels[0].id + } }) describe('New video from my subscription notification', function () { @@ -124,7 +154,7 @@ describe('Test users notifications', function () { }) it('Should not send notifications if the user does not follow the video publisher', async function () { - await uploadVideoByLocalAccount(servers, 1) + await uploadVideoByLocalAccount(servers) const notification = await getLastNotification(servers[ 0 ].url, userAccessToken) expect(notification).to.be.undefined @@ -136,11 +166,8 @@ describe('Test users notifications', function () { it('Should send a new video notification if the user follows the local video publisher', async function () { await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001') - const videoNameId = 10 - const videoName = 'local video ' + videoNameId - - const uuid = await uploadVideoByLocalAccount(servers, videoNameId) - await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + const { name, uuid } = await uploadVideoByLocalAccount(servers) + await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') }) it('Should send a new video notification from a remote account', async function () { @@ -148,21 +175,13 @@ describe('Test users notifications', function () { await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002') - const videoNameId = 20 - const videoName = 'remote video ' + videoNameId - - const uuid = await uploadVideoByRemoteAccount(servers, videoNameId) - await waitJobs(servers) - - await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + const { name, uuid } = await uploadVideoByRemoteAccount(servers) + await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') }) it('Should send a new video notification on a scheduled publication', async function () { this.timeout(20000) - const videoNameId = 30 - const videoName = 'local video ' + videoNameId - // In 2 seconds let updateAt = new Date(new Date().getTime() + 2000) @@ -173,18 +192,15 @@ describe('Test users notifications', function () { privacy: VideoPrivacy.PUBLIC } } - const uuid = await uploadVideoByLocalAccount(servers, videoNameId, data) + const { name, uuid } = await uploadVideoByLocalAccount(servers, data) await wait(6000) - await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') }) it('Should send a new video notification on a remote scheduled publication', async function () { this.timeout(20000) - const videoNameId = 40 - const videoName = 'remote video ' + videoNameId - // In 2 seconds let updateAt = new Date(new Date().getTime() + 2000) @@ -195,19 +211,16 @@ describe('Test users notifications', function () { privacy: VideoPrivacy.PUBLIC } } - const uuid = await uploadVideoByRemoteAccount(servers, videoNameId, data) + const { name, uuid } = await uploadVideoByRemoteAccount(servers, data) await waitJobs(servers) await wait(6000) - await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') }) it('Should not send a notification before the video is published', async function () { this.timeout(20000) - const videoNameId = 50 - const videoName = 'local video ' + videoNameId - let updateAt = new Date(new Date().getTime() + 100000) const data = { @@ -217,86 +230,70 @@ describe('Test users notifications', function () { privacy: VideoPrivacy.PUBLIC } } - const uuid = await uploadVideoByLocalAccount(servers, videoNameId, data) + const { name, uuid } = await uploadVideoByLocalAccount(servers, data) await wait(6000) - await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') + await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') }) it('Should send a new video notification when a video becomes public', async function () { this.timeout(10000) - const videoNameId = 60 - const videoName = 'local video ' + videoNameId - const data = { privacy: VideoPrivacy.PRIVATE } - const uuid = await uploadVideoByLocalAccount(servers, videoNameId, data) + const { name, uuid } = await uploadVideoByLocalAccount(servers, data) - await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') + await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) await wait(500) - await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') }) it('Should send a new video notification when a remote video becomes public', async function () { this.timeout(20000) - const videoNameId = 70 - const videoName = 'remote video ' + videoNameId - const data = { privacy: VideoPrivacy.PRIVATE } - const uuid = await uploadVideoByRemoteAccount(servers, videoNameId, data) - await waitJobs(servers) + const { name, uuid } = await uploadVideoByRemoteAccount(servers, data) - await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') + await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) await waitJobs(servers) - await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') }) it('Should not send a new video notification when a video becomes unlisted', async function () { this.timeout(20000) - const videoNameId = 80 - const videoName = 'local video ' + videoNameId - const data = { privacy: VideoPrivacy.PRIVATE } - const uuid = await uploadVideoByLocalAccount(servers, videoNameId, data) + const { name, uuid } = await uploadVideoByLocalAccount(servers, data) await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) - await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') + await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') }) it('Should not send a new video notification when a remote video becomes unlisted', async function () { this.timeout(20000) - const videoNameId = 90 - const videoName = 'remote video ' + videoNameId - const data = { privacy: VideoPrivacy.PRIVATE } - const uuid = await uploadVideoByRemoteAccount(servers, videoNameId, data) - await waitJobs(servers) + const { name, uuid } = await uploadVideoByRemoteAccount(servers, data) await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) await waitJobs(servers) - await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'absence') + await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') }) it('Should send a new video notification after a video import', async function () { this.timeout(30000) - const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken) - const channelId = resChannel.body.videoChannels[0].id - const videoName = 'local video 100' + const name = 'video import ' + uuidv4() const attributes = { - name: videoName, + name, channelId, privacy: VideoPrivacy.PUBLIC, targetUrl: getYoutubeVideoUrl() @@ -306,7 +303,7 @@ describe('Test users notifications', function () { await waitJobs(servers) - await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') }) }) @@ -348,6 +345,23 @@ describe('Test users notifications', function () { await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') }) + it('Should not send a new comment notification if the account is muted', async function () { + this.timeout(10000) + + await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root') + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) + const uuid = resVideo.body.video.uuid + + const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') + const commentId = resComment.body.comment.id + + await wait(500) + await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') + + await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root') + }) + it('Should send a new comment notification after a local comment on my video', async function () { this.timeout(10000) @@ -425,23 +439,21 @@ describe('Test users notifications', function () { it('Should send a notification to moderators on local video abuse', async function () { this.timeout(10000) - const videoName = 'local video 110' - - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) + const name = 'video for abuse ' + uuidv4() + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const uuid = resVideo.body.video.uuid await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason') await waitJobs(servers) - await checkNewVideoAbuseForModerators(baseParams, uuid, videoName, 'presence') + await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence') }) it('Should send a notification to moderators on remote video abuse', async function () { this.timeout(10000) - const videoName = 'remote video 120' - - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) + const name = 'video for abuse ' + uuidv4() + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const uuid = resVideo.body.video.uuid await waitJobs(servers) @@ -449,7 +461,7 @@ describe('Test users notifications', function () { await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason') await waitJobs(servers) - await checkNewVideoAbuseForModerators(baseParams, uuid, videoName, 'presence') + await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence') }) }) @@ -468,23 +480,21 @@ describe('Test users notifications', function () { it('Should send a notification to video owner on blacklist', async function () { this.timeout(10000) - const videoName = 'local video 130' - - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) + const name = 'video for abuse ' + uuidv4() + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const uuid = resVideo.body.video.uuid await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) await waitJobs(servers) - await checkNewBlacklistOnMyVideo(baseParams, uuid, videoName, 'blacklist') + await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist') }) it('Should send a notification to video owner on unblacklist', async function () { this.timeout(10000) - const videoName = 'local video 130' - - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) + const name = 'video for abuse ' + uuidv4() + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const uuid = resVideo.body.video.uuid await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) @@ -494,38 +504,187 @@ describe('Test users notifications', function () { await waitJobs(servers) await wait(500) - await checkNewBlacklistOnMyVideo(baseParams, uuid, videoName, 'unblacklist') + await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist') + }) + }) + + describe('My video is published', function () { + let baseParams: CheckerBaseParams + + before(() => { + baseParams = { + server: servers[1], + emails, + socketNotifications: adminNotificationsServer2, + token: servers[1].accessToken + } + }) + + it('Should not send a notification if transcoding is not enabled', async function () { + const { name, uuid } = await uploadVideoByLocalAccount(servers) + await waitJobs(servers) + + await checkVideoIsPublished(baseParams, name, uuid, 'absence') + }) + + it('Should not send a notification if the wait transcoding is false', async function () { + this.timeout(50000) + + await uploadVideoByRemoteAccount(servers, { waitTranscoding: false }) + await waitJobs(servers) + + const notification = await getLastNotification(servers[ 0 ].url, userAccessToken) + if (notification) { + expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED) + } + }) + + it('Should send a notification even if the video is not transcoded in other resolutions', async function () { + this.timeout(50000) + + const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' }) + await waitJobs(servers) + + await checkVideoIsPublished(baseParams, name, uuid, 'presence') + }) + + it('Should send a notification with a transcoded video', async function () { + this.timeout(50000) + + const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true }) + await waitJobs(servers) + + await checkVideoIsPublished(baseParams, name, uuid, 'presence') + }) + + it('Should send a notification when an imported video is transcoded', async function () { + this.timeout(50000) + + const name = 'video import ' + uuidv4() + + const attributes = { + name, + channelId, + privacy: VideoPrivacy.PUBLIC, + targetUrl: getYoutubeVideoUrl(), + waitTranscoding: true + } + const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) + const uuid = res.body.video.uuid + + await waitJobs(servers) + await checkVideoIsPublished(baseParams, name, uuid, 'presence') + }) + + it('Should send a notification when the scheduled update has been proceeded', async function () { + this.timeout(70000) + + // In 2 seconds + let updateAt = new Date(new Date().getTime() + 2000) + + const data = { + privacy: VideoPrivacy.PRIVATE, + scheduleUpdate: { + updateAt: updateAt.toISOString(), + privacy: VideoPrivacy.PUBLIC + } + } + const { name, uuid } = await uploadVideoByRemoteAccount(servers, data) + + await wait(6000) + await checkVideoIsPublished(baseParams, name, uuid, 'presence') + }) + }) + + describe('My video is imported', function () { + let baseParams: CheckerBaseParams + + before(() => { + baseParams = { + server: servers[0], + emails, + socketNotifications: adminNotifications, + token: servers[0].accessToken + } + }) + + it('Should send a notification when the video import failed', async function () { + this.timeout(70000) + + const name = 'video import ' + uuidv4() + + const attributes = { + name, + channelId, + privacy: VideoPrivacy.PRIVATE, + targetUrl: getBadVideoUrl() + } + const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) + const uuid = res.body.video.uuid + + await waitJobs(servers) + await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence') + }) + + it('Should send a notification when the video import succeeded', async function () { + this.timeout(70000) + + const name = 'video import ' + uuidv4() + + const attributes = { + name, + channelId, + privacy: VideoPrivacy.PRIVATE, + targetUrl: getYoutubeVideoUrl() + } + const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) + const uuid = res.body.video.uuid + + await waitJobs(servers) + await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence') }) }) describe('Mark as read', function () { it('Should mark as read some notifications', async function () { - const res = await getUserNotifications(servers[0].url, userAccessToken, 2, 3) + const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3) const ids = res.body.data.map(n => n.id) - await markAsReadNotifications(servers[0].url, userAccessToken, ids) + await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids) }) it('Should have the notifications marked as read', async function () { - const res = await getUserNotifications(servers[0].url, userAccessToken, 0, 10) + const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10) + + const notifications = res.body.data as UserNotification[] + expect(notifications[ 0 ].read).to.be.false + expect(notifications[ 1 ].read).to.be.false + expect(notifications[ 2 ].read).to.be.true + expect(notifications[ 3 ].read).to.be.true + expect(notifications[ 4 ].read).to.be.true + expect(notifications[ 5 ].read).to.be.false + }) + + it('Should only list read notifications', async function () { + const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false) const notifications = res.body.data as UserNotification[] - expect(notifications[0].read).to.be.false - expect(notifications[1].read).to.be.false - expect(notifications[2].read).to.be.true - expect(notifications[3].read).to.be.true - expect(notifications[4].read).to.be.true - expect(notifications[5].read).to.be.false + for (const notification of notifications) { + expect(notification.read).to.be.true + } + }) + + it('Should only list unread notifications', async function () { + const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true) + + const notifications = res.body.data as UserNotification[] + for (const notification of notifications) { + expect(notification.read).to.be.false + } }) }) describe('Notification settings', function () { - const baseUpdateNotificationParams = { - newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL - } let baseParams: CheckerBaseParams before(() => { @@ -538,7 +697,7 @@ describe('Test users notifications', function () { }) it('Should not have notifications', async function () { - await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(baseUpdateNotificationParams, { + await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { newVideoFromSubscription: UserNotificationSettingValue.NONE })) @@ -548,16 +707,14 @@ describe('Test users notifications', function () { expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) } - const videoNameId = 42 - const videoName = 'local video ' + videoNameId - const uuid = await uploadVideoByLocalAccount(servers, videoNameId) + const { name, uuid } = await uploadVideoByLocalAccount(servers) const check = { web: true, mail: true } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'absence') + await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') }) it('Should only have web notifications', async function () { - await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(baseUpdateNotificationParams, { + await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION })) @@ -567,23 +724,21 @@ describe('Test users notifications', function () { expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB_NOTIFICATION) } - const videoNameId = 52 - const videoName = 'local video ' + videoNameId - const uuid = await uploadVideoByLocalAccount(servers, videoNameId) + const { name, uuid } = await uploadVideoByLocalAccount(servers) { const check = { mail: true, web: false } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'absence') + await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') } { const check = { mail: false, web: true } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'presence') + await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence') } }) it('Should only have mail notifications', async function () { - await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(baseUpdateNotificationParams, { + await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { newVideoFromSubscription: UserNotificationSettingValue.EMAIL })) @@ -593,23 +748,21 @@ describe('Test users notifications', function () { expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) } - const videoNameId = 62 - const videoName = 'local video ' + videoNameId - const uuid = await uploadVideoByLocalAccount(servers, videoNameId) + const { name, uuid } = await uploadVideoByLocalAccount(servers) { const check = { mail: false, web: true } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'absence') + await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') } { const check = { mail: true, web: false } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), videoName, uuid, 'presence') + await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence') } }) it('Should have email and web notifications', async function () { - await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(baseUpdateNotificationParams, { + await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL })) @@ -619,11 +772,9 @@ describe('Test users notifications', function () { expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL) } - const videoNameId = 72 - const videoName = 'local video ' + videoNameId - const uuid = await uploadVideoByLocalAccount(servers, videoNameId) + const { name, uuid } = await uploadVideoByLocalAccount(servers) - await checkNewVideoFromSubscription(baseParams, videoName, uuid, 'presence') + await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') }) }) -- cgit v1.2.3 From f7cc67b455a12ccae9b0ea16876d166720364357 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 4 Jan 2019 08:56:20 +0100 Subject: Add new follow, mention and user registered notifs --- server/tests/api/users/user-notifications.ts | 229 ++++++++++++++++++++++++++- 1 file changed, 221 insertions(+), 8 deletions(-) (limited to 'server/tests/api/users') 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 { flushTests, getMyUserInformation, immutableAssign, + registerUser, removeVideoFromBlacklist, reportVideoAbuse, + updateMyUser, updateVideo, + updateVideoChannel, userLogin, wait } from '../../../../shared/utils' @@ -21,16 +24,20 @@ import { setAccessTokensToServers } from '../../../../shared/utils/users/login' import { waitJobs } from '../../../../shared/utils/server/jobs' import { getUserNotificationSocket } from '../../../../shared/utils/socket/socket-io' import { + checkCommentMention, CheckerBaseParams, + checkMyVideoImportIsFinished, + checkNewActorFollow, checkNewBlacklistOnMyVideo, checkNewCommentOnMyVideo, checkNewVideoAbuseForModerators, checkNewVideoFromSubscription, + checkUserRegistered, + checkVideoIsPublished, getLastNotification, getUserNotifications, markAsReadNotifications, - updateMyNotificationSettings, - checkVideoIsPublished, checkMyVideoImportIsFinished + updateMyNotificationSettings } from '../../../../shared/utils/users/user-notifications' import { User, @@ -40,9 +47,9 @@ import { UserNotificationType } from '../../../../shared/models/users' import { MockSmtpServer } from '../../../../shared/utils/miscs/email' -import { addUserSubscription } from '../../../../shared/utils/users/user-subscriptions' +import { addUserSubscription, removeUserSubscription } from '../../../../shared/utils/users/user-subscriptions' import { VideoPrivacy } from '../../../../shared/models/videos' -import { getYoutubeVideoUrl, importVideo, getBadVideoUrl } from '../../../../shared/utils/videos/video-imports' +import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports' import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments' import * as uuidv4 from 'uuid/v4' import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist' @@ -81,12 +88,15 @@ describe('Test users notifications', function () { let channelId: number const allNotificationSettings: UserNotificationSetting = { - myVideoPublished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - myVideoImportFinished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL + blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + myVideoImportFinished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + myVideoPublished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + commentMention: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + newFollow: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, + newUserRegistration: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL } before(async function () { @@ -424,6 +434,114 @@ describe('Test users notifications', function () { }) }) + describe('Mention notifications', function () { + let baseParams: CheckerBaseParams + + before(async () => { + baseParams = { + server: servers[0], + emails, + socketNotifications: userNotifications, + token: userAccessToken + } + + await updateMyUser({ + url: servers[0].url, + accessToken: servers[0].accessToken, + displayName: 'super root name' + }) + + await updateMyUser({ + url: servers[1].url, + accessToken: servers[1].accessToken, + displayName: 'super root 2 name' + }) + }) + + it('Should not send a new mention comment notification if I mention the video owner', async function () { + this.timeout(10000) + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) + const uuid = resVideo.body.video.uuid + + const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') + const commentId = resComment.body.comment.id + + await wait(500) + await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') + }) + + it('Should not send a new mention comment notification if I mention myself', async function () { + this.timeout(10000) + + const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) + const uuid = resVideo.body.video.uuid + + const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello') + const commentId = resComment.body.comment.id + + await wait(500) + await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') + }) + + it('Should not send a new mention notification if the account is muted', async function () { + this.timeout(10000) + + await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root') + + const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) + const uuid = resVideo.body.video.uuid + + const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') + const commentId = resComment.body.comment.id + + await wait(500) + await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') + + await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root') + }) + + it('Should send a new mention notification after local comments', async function () { + this.timeout(10000) + + const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) + const uuid = resVideo.body.video.uuid + + const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1') + const threadId = resThread.body.comment.id + + await wait(500) + await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence') + + const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1') + const commentId = resComment.body.comment.id + + await wait(500) + await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence') + }) + + it('Should send a new mention notification after remote comments', async function () { + this.timeout(20000) + + const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) + const uuid = resVideo.body.video.uuid + + await waitJobs(servers) + const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1') + const threadId = resThread.body.comment.id + + await waitJobs(servers) + await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'presence') + + const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001' + const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, text) + const commentId = resComment.body.comment.id + + await waitJobs(servers) + await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root 2 name', 'presence') + }) + }) + describe('Video abuse for moderators notification' , function () { let baseParams: CheckerBaseParams @@ -645,6 +763,101 @@ describe('Test users notifications', function () { }) }) + describe('New registration', function () { + let baseParams: CheckerBaseParams + + before(() => { + baseParams = { + server: servers[0], + emails, + socketNotifications: adminNotifications, + token: servers[0].accessToken + } + }) + + it('Should send a notification only to moderators when a user registers on the instance', async function () { + await registerUser(servers[0].url, 'user_45', 'password') + + await waitJobs(servers) + + await checkUserRegistered(baseParams, 'user_45', 'presence') + + const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } + await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence') + }) + }) + + describe('New actor follow', function () { + let baseParams: CheckerBaseParams + let myChannelName = 'super channel name' + let myUserName = 'super user name' + + before(async () => { + baseParams = { + server: servers[0], + emails, + socketNotifications: userNotifications, + token: userAccessToken + } + + await updateMyUser({ + url: servers[0].url, + accessToken: servers[0].accessToken, + displayName: 'super root name' + }) + + await updateMyUser({ + url: servers[0].url, + accessToken: userAccessToken, + displayName: myUserName + }) + + await updateMyUser({ + url: servers[1].url, + accessToken: servers[1].accessToken, + displayName: 'super root 2 name' + }) + + await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName }) + }) + + it('Should notify when a local channel is following one of our channel', async function () { + await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') + + await waitJobs(servers) + + await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') + + await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') + }) + + it('Should notify when a remote channel is following one of our channel', async function () { + await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') + + await waitJobs(servers) + + await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') + + await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') + }) + + it('Should notify when a local account is following one of our channel', async function () { + await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001') + + await waitJobs(servers) + + await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence') + }) + + it('Should notify when a remote account is following one of our channel', async function () { + await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001') + + await waitJobs(servers) + + await checkNewActorFollow(baseParams, 'account', 'root', 'super root 2 name', myUserName, 'presence') + }) + }) + describe('Mark as read', function () { it('Should mark as read some notifications', async function () { const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3) -- cgit v1.2.3 From 2f1548fda32c3ba9e53913270394eedfacd55986 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 8 Jan 2019 11:26:41 +0100 Subject: Add notifications in the client --- server/tests/api/users/user-notifications.ts | 50 +++++++++++++++++++--------- server/tests/api/users/users.ts | 4 --- 2 files changed, 34 insertions(+), 20 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/user-notifications.ts b/server/tests/api/users/user-notifications.ts index ae77b4db2..ad68d8e69 100644 --- a/server/tests/api/users/user-notifications.ts +++ b/server/tests/api/users/user-notifications.ts @@ -37,7 +37,8 @@ import { getLastNotification, getUserNotifications, markAsReadNotifications, - updateMyNotificationSettings + updateMyNotificationSettings, + markAsReadAllNotifications } from '../../../../shared/utils/users/user-notifications' import { User, @@ -88,15 +89,15 @@ describe('Test users notifications', function () { let channelId: number const allNotificationSettings: UserNotificationSetting = { - newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - myVideoImportFinished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - myVideoPublished: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - commentMention: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - newFollow: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL, - newUserRegistration: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL + newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL } before(async function () { @@ -174,7 +175,10 @@ describe('Test users notifications', function () { }) it('Should send a new video notification if the user follows the local video publisher', async function () { + this.timeout(10000) + await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001') + await waitJobs(servers) const { name, uuid } = await uploadVideoByLocalAccount(servers) await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') @@ -184,6 +188,7 @@ describe('Test users notifications', function () { this.timeout(50000) // Server 2 has transcoding enabled await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9002') + await waitJobs(servers) const { name, uuid } = await uploadVideoByRemoteAccount(servers) await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') @@ -822,8 +827,9 @@ describe('Test users notifications', function () { }) it('Should notify when a local channel is following one of our channel', async function () { - await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') + this.timeout(10000) + await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001') await waitJobs(servers) await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') @@ -832,8 +838,9 @@ describe('Test users notifications', function () { }) it('Should notify when a remote channel is following one of our channel', async function () { - await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') + this.timeout(10000) + await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001') await waitJobs(servers) await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') @@ -895,6 +902,15 @@ describe('Test users notifications', function () { expect(notification.read).to.be.false } }) + + it('Should mark as read all notifications', async function () { + await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken) + + const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true) + + expect(res.body.total).to.equal(0) + expect(res.body.data).to.have.lengthOf(0) + }) }) describe('Notification settings', function () { @@ -928,13 +944,13 @@ describe('Test users notifications', function () { it('Should only have web notifications', async function () { await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { - newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION + newVideoFromSubscription: UserNotificationSettingValue.WEB })) { const res = await getMyUserInformation(servers[0].url, userAccessToken) const info = res.body as User - expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB_NOTIFICATION) + expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) } const { name, uuid } = await uploadVideoByLocalAccount(servers) @@ -976,13 +992,15 @@ describe('Test users notifications', function () { it('Should have email and web notifications', async function () { await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { - newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL + newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL })) { const res = await getMyUserInformation(servers[0].url, userAccessToken) const info = res.body as User - expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB_NOTIFICATION_AND_EMAIL) + expect(info.notificationSettings.newVideoFromSubscription).to.equal( + UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL + ) } const { name, uuid } = await uploadVideoByLocalAccount(servers) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 4914c8ed5..ad98ab1c7 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -501,10 +501,6 @@ describe('Test users', function () { accessTokenUser = await userLogin(server, user) }) - it('Should not be able to delete a user by a moderator', async function () { - await removeUser(server.url, 2, accessTokenUser, 403) - }) - it('Should be able to list video blacklist by a moderator', async function () { await getBlacklistedVideosList(server.url, accessTokenUser) }) -- cgit v1.2.3 From 89ada4e26ca1df8ff0dd02acda1d1661f121a294 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 8 Jan 2019 15:51:52 +0100 Subject: Fix socket.io websocket connection --- server/tests/api/users/index.ts | 4 ++-- server/tests/api/users/user-notifications.ts | 4 +++- server/tests/api/users/users-verification.ts | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/index.ts b/server/tests/api/users/index.ts index 63e6e827a..52ba6984e 100644 --- a/server/tests/api/users/index.ts +++ b/server/tests/api/users/index.ts @@ -1,6 +1,6 @@ +import './users-verification' +import './user-notifications' import './blocklist' import './user-subscriptions' -import './user-notifications' import './users' import './users-multiple-servers' -import './users-verification' diff --git a/server/tests/api/users/user-notifications.ts b/server/tests/api/users/user-notifications.ts index ad68d8e69..5260d64cc 100644 --- a/server/tests/api/users/user-notifications.ts +++ b/server/tests/api/users/user-notifications.ts @@ -175,7 +175,7 @@ describe('Test users notifications', function () { }) it('Should send a new video notification if the user follows the local video publisher', async function () { - this.timeout(10000) + this.timeout(15000) await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001') await waitJobs(servers) @@ -1010,6 +1010,8 @@ describe('Test users notifications', function () { }) after(async function () { + MockSmtpServer.Instance.kill() + killallServers(servers) }) }) diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index afc8a0059..babeda2b8 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -4,7 +4,7 @@ import * as chai from 'chai' import 'mocha' import { registerUser, flushTests, getUserInformation, getMyUserInformation, killallServers, - userLogin, login, runServer, ServerInfo, verifyEmail, updateCustomSubConfig + userLogin, login, runServer, ServerInfo, verifyEmail, updateCustomSubConfig, wait } from '../../../../shared/utils' import { setAccessTokensToServers } from '../../../../shared/utils/users/login' import { MockSmtpServer } from '../../../../shared/utils/miscs/email' @@ -123,6 +123,7 @@ describe('Test users account verification', function () { }) after(async function () { + MockSmtpServer.Instance.kill() killallServers([ server ]) // Keep the logs if the test failed -- cgit v1.2.3