+function getAllNotificationsSettings () {
+ return {
+ newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
+ newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
+ abuseAsModerator: 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,
+ newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
+ autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
+ } as UserNotificationSetting
+}
+
+async function prepareNotificationsTest (serversCount = 3) {
+ const userNotifications: UserNotification[] = []
+ const adminNotifications: UserNotification[] = []
+ const adminNotificationsServer2: UserNotification[] = []
+ const emails: object[] = []
+
+ const port = await MockSmtpServer.Instance.collectEmails(emails)
+
+ const overrideConfig = {
+ smtp: {
+ hostname: 'localhost',
+ port
+ }
+ }
+ const servers = await flushAndRunMultipleServers(serversCount, overrideConfig)
+
+ await setAccessTokensToServers(servers)
+
+ if (serversCount > 1) {
+ await doubleFollow(servers[0], servers[1])
+ }
+
+ const user = {
+ username: 'user_1',
+ password: 'super password'
+ }
+ await createUser({
+ url: servers[0].url,
+ accessToken: servers[0].accessToken,
+ username: user.username,
+ password: user.password,
+ videoQuota: 10 * 1000 * 1000
+ })
+ const userAccessToken = await userLogin(servers[0], user)
+
+ await updateMyNotificationSettings(servers[0].url, userAccessToken, getAllNotificationsSettings())
+ await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, getAllNotificationsSettings())
+
+ if (serversCount > 1) {
+ await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, getAllNotificationsSettings())
+ }
+
+ {
+ 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))
+ }
+
+ if (serversCount > 1) {
+ 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)
+ const channelId = resChannel.body.videoChannels[0].id
+
+ return {
+ userNotifications,
+ adminNotifications,
+ adminNotificationsServer2,
+ userAccessToken,
+ emails,
+ servers,
+ channelId
+ }
+}
+