updateVideo,
updateVideoChannel,
userLogin,
- wait
+ wait,
+ getCustomConfig,
+ updateCustomConfig, getVideoThreadComments, getVideoCommentThreads
} from '../../../../shared/utils'
import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index'
import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
checkNewBlacklistOnMyVideo,
checkNewCommentOnMyVideo,
checkNewVideoAbuseForModerators,
+ checkVideoAutoBlacklistForModerators,
checkNewVideoFromSubscription,
checkUserRegistered,
checkVideoIsPublished,
getLastNotification,
getUserNotifications,
markAsReadNotifications,
- updateMyNotificationSettings
+ updateMyNotificationSettings,
+ markAsReadAllNotifications
} from '../../../../shared/utils/users/user-notifications'
import {
User,
import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments'
import * as uuidv4 from 'uuid/v4'
import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist'
+import { CustomConfig } from '../../../../shared/models/server'
+import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
const expect = chai.expect
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,
+ videoAutoBlacklistAsModerator: 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 () {
})
it('Should not send notifications if the user does not follow the video publisher', async function () {
+ this.timeout(10000)
+
await uploadVideoByLocalAccount(servers)
const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
})
it('Should send a new video notification if the user follows the local video publisher', async function () {
+ this.timeout(15000)
+
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')
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')
})
it('Should send a new video notification on a remote scheduled publication', async function () {
- this.timeout(20000)
+ this.timeout(50000)
// In 2 seconds
let updateAt = new Date(new Date().getTime() + 2000)
it('Should not send a notification before the video is published', async function () {
this.timeout(20000)
- let updateAt = new Date(new Date().getTime() + 100000)
+ let updateAt = new Date(new Date().getTime() + 1000000)
const data = {
privacy: VideoPrivacy.PRIVATE,
})
it('Should send a new video notification after a video import', async function () {
- this.timeout(30000)
+ this.timeout(100000)
const name = 'video import ' + uuidv4()
await waitJobs(servers)
- const resComment = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
- const commentId = resComment.body.comment.id
+ await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
await waitJobs(servers)
+
+ const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
+ expect(resComment.body.data).to.have.lengthOf(1)
+ const commentId = resComment.body.data[0].id
+
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
})
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
+ {
+ const resThread = await addVideoCommentThread(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, 'comment')
+ const threadId = resThread.body.comment.id
+ await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, threadId, 'reply')
+ }
await waitJobs(servers)
+
+ const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
+ expect(resThread.body.data).to.have.lengthOf(1)
+ const threadId = resThread.body.data[0].id
+
+ const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
+ const tree = resComments.body as VideoCommentThreadTree
+
+ expect(tree.children).to.have.lengthOf(1)
+ const commentId = tree.children[0].comment.id
+
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
})
})
await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
})
+ it('Should not send a new mention notification if the remote account mention a local account', 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, '@user_1 hello')
+ const threadId = resThread.body.comment.id
+
+ await waitJobs(servers)
+ await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
+ })
+
it('Should send a new mention notification after local comments', async function () {
this.timeout(10000)
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
+ const server2ThreadId = resThread.body.comment.id
await waitJobs(servers)
- await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'presence')
+
+ const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
+ expect(resThread2.body.data).to.have.lengthOf(1)
+ const server1ThreadId = resThread2.body.data[0].id
+ await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, '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 addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text)
await waitJobs(servers)
- await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root 2 name', 'presence')
+
+ const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
+ const tree = resComments.body as VideoCommentThreadTree
+
+ expect(tree.children).to.have.lengthOf(1)
+ const commentId = tree.children[0].comment.id
+
+ await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
})
})
})
it('Should not send a notification if transcoding is not enabled', async function () {
+ this.timeout(10000)
+
const { name, uuid } = await uploadVideoByLocalAccount(servers)
await waitJobs(servers)
await wait(6000)
await checkVideoIsPublished(baseParams, name, uuid, 'presence')
})
+
+ it('Should not send a notification before the video is published', async function () {
+ this.timeout(20000)
+
+ let updateAt = new Date(new Date().getTime() + 100000)
+
+ 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, 'absence')
+ })
})
describe('My video is imported', function () {
})
it('Should send a notification only to moderators when a user registers on the instance', async function () {
+ this.timeout(10000)
+
await registerUser(servers[0].url, 'user_45', 'password')
await waitJobs(servers)
})
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')
})
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')
})
it('Should notify when a local account is following one of our channel', async function () {
+ this.timeout(10000)
+
await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
await waitJobs(servers)
})
it('Should notify when a remote account is following one of our channel', async function () {
+ this.timeout(10000)
+
await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
await waitJobs(servers)
})
})
+ describe('Video-related notifications when video auto-blacklist is enabled', function () {
+ let userBaseParams: CheckerBaseParams
+ let adminBaseParamsServer1: CheckerBaseParams
+ let adminBaseParamsServer2: CheckerBaseParams
+ let videoUUID: string
+ let videoName: string
+ let currentCustomConfig: CustomConfig
+
+ before(async () => {
+
+ adminBaseParamsServer1 = {
+ server: servers[0],
+ emails,
+ socketNotifications: adminNotifications,
+ token: servers[0].accessToken
+ }
+
+ adminBaseParamsServer2 = {
+ server: servers[1],
+ emails,
+ socketNotifications: adminNotificationsServer2,
+ token: servers[1].accessToken
+ }
+
+ userBaseParams = {
+ server: servers[0],
+ emails,
+ socketNotifications: userNotifications,
+ token: userAccessToken
+ }
+
+ const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken)
+ currentCustomConfig = resCustomConfig.body
+ const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, {
+ autoBlacklist: {
+ videos: {
+ ofUsers: {
+ enabled: true
+ }
+ }
+ }
+ })
+ // enable transcoding otherwise own publish notification after transcoding not expected
+ autoBlacklistTestsCustomConfig.transcoding.enabled = true
+ await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig)
+
+ await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
+ await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
+
+ })
+
+ it('Should send notification to moderators on new video with auto-blacklist', async function () {
+ this.timeout(20000)
+
+ videoName = 'video with auto-blacklist ' + uuidv4()
+ const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
+ videoUUID = resVideo.body.video.uuid
+
+ await waitJobs(servers)
+ await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
+ })
+
+ it('Should not send video publish notification if auto-blacklisted', async function () {
+ await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence')
+ })
+
+ it('Should not send a local user subscription notification if auto-blacklisted', async function () {
+ await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence')
+ })
+
+ it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
+ await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence')
+ })
+
+ it('Should send video published and unblacklist after video unblacklisted', async function () {
+ this.timeout(20000)
+
+ await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID)
+
+ await waitJobs(servers)
+
+ // FIXME: Can't test as two notifications sent to same user and util only checks last one
+ // One notification might be better anyways
+ // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist')
+ // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence')
+ })
+
+ it('Should send a local user subscription notification after removed from blacklist', async function () {
+ await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence')
+ })
+
+ it('Should send a remote user subscription notification after removed from blacklist', async function () {
+ await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence')
+ })
+
+ it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
+ this.timeout(20000)
+
+ let updateAt = new Date(new Date().getTime() + 100000)
+
+ const name = 'video with auto-blacklist and future schedule ' + uuidv4()
+
+ const data = {
+ name,
+ privacy: VideoPrivacy.PRIVATE,
+ scheduleUpdate: {
+ updateAt: updateAt.toISOString(),
+ privacy: VideoPrivacy.PUBLIC
+ }
+ }
+
+ const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
+ const uuid = resVideo.body.video.uuid
+
+ await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
+
+ await waitJobs(servers)
+ await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
+
+ // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
+ // One notification might be better anyways
+ // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
+
+ await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
+ await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
+ })
+
+ it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
+ this.timeout(20000)
+
+ // In 2 seconds
+ let updateAt = new Date(new Date().getTime() + 2000)
+
+ const name = 'video with schedule done and still auto-blacklisted ' + uuidv4()
+
+ const data = {
+ name,
+ privacy: VideoPrivacy.PRIVATE,
+ scheduleUpdate: {
+ updateAt: updateAt.toISOString(),
+ privacy: VideoPrivacy.PUBLIC
+ }
+ }
+
+ const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
+ const uuid = resVideo.body.video.uuid
+
+ await wait(6000)
+ await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
+ await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
+ await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
+ })
+
+ it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
+ this.timeout(20000)
+
+ const name = 'video without auto-blacklist ' + uuidv4()
+
+ // admin with blacklist right will not be auto-blacklisted
+ const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name })
+ const uuid = resVideo.body.video.uuid
+
+ await waitJobs(servers)
+ await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
+ })
+
+ after(async () => {
+ await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig)
+
+ await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
+ await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
+ })
+ })
+
describe('Mark as read', function () {
it('Should mark as read some notifications', async function () {
const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
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 () {
})
it('Should not have notifications', async function () {
+ this.timeout(20000)
+
await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
newVideoFromSubscription: UserNotificationSettingValue.NONE
}))
})
it('Should only have web notifications', async function () {
+ this.timeout(20000)
+
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)
})
it('Should only have mail notifications', async function () {
+ this.timeout(20000)
+
await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
newVideoFromSubscription: UserNotificationSettingValue.EMAIL
}))
})
it('Should have email and web notifications', async function () {
+ this.timeout(20000)
+
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)
})
after(async function () {
+ MockSmtpServer.Instance.kill()
+
killallServers(servers)
})
})