]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/notifications/user-notifications.ts
fix a few typos (#2141)
[github/Chocobozzz/PeerTube.git] / server / tests / api / notifications / user-notifications.ts
index eb4fdb87c9545b1f8eefaffb92b37269d364bf29..15a34f5aab9c86dc2c6a0addd84519dea6274d03 100644 (file)
@@ -4,44 +4,52 @@ import * as chai from 'chai'
 import 'mocha'
 import {
   addVideoToBlacklist,
+  cleanupTests,
   createUser,
   doubleFollow,
   flushAndRunMultipleServers,
-  flushTests,
+  follow,
+  getCustomConfig,
   getMyUserInformation,
+  getVideoCommentThreads,
+  getVideoThreadComments,
   immutableAssign,
+  MockInstancesIndex,
   registerUser,
   removeVideoFromBlacklist,
   reportVideoAbuse,
+  unfollow,
+  updateCustomConfig,
+  updateCustomSubConfig,
   updateMyUser,
   updateVideo,
   updateVideoChannel,
   userLogin,
-  wait,
-  getCustomConfig,
-  updateCustomConfig, getVideoThreadComments, getVideoCommentThreads, follow
+  wait
 } from '../../../../shared/extra-utils'
-import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
+import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
 import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
 import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io'
 import {
+  checkAutoInstanceFollowing,
   checkCommentMention,
   CheckerBaseParams,
   checkMyVideoImportIsFinished,
   checkNewActorFollow,
   checkNewBlacklistOnMyVideo,
   checkNewCommentOnMyVideo,
+  checkNewInstanceFollower,
   checkNewVideoAbuseForModerators,
-  checkVideoAutoBlacklistForModerators,
   checkNewVideoFromSubscription,
   checkUserRegistered,
+  checkVideoAutoBlacklistForModerators,
   checkVideoIsPublished,
   getLastNotification,
   getUserNotifications,
+  markAsReadAllNotifications,
   markAsReadNotifications,
-  updateMyNotificationSettings,
-  markAsReadAllNotifications, checkNewInstanceFollower
+  updateMyNotificationSettings
 } from '../../../../shared/extra-utils/users/user-notifications'
 import {
   User,
@@ -104,17 +112,19 @@ describe('Test users notifications', function () {
     commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
     newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
     newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
-    newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
+    newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
+    autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
   }
 
   before(async function () {
     this.timeout(120000)
 
-    await MockSmtpServer.Instance.collectEmails(emails)
+    const port = await MockSmtpServer.Instance.collectEmails(emails)
 
     const overrideConfig = {
       smtp: {
-        hostname: 'localhost'
+        hostname: 'localhost',
+        port
       }
     }
     servers = await flushAndRunMultipleServers(3, overrideConfig)
@@ -190,7 +200,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(15000)
 
-      await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
+      await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port)
       await waitJobs(servers)
 
       const { name, uuid } = await uploadVideoByLocalAccount(servers)
@@ -200,7 +210,7 @@ describe('Test users notifications', function () {
     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')
+      await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port)
       await waitJobs(servers)
 
       const { name, uuid } = await uploadVideoByRemoteAccount(servers)
@@ -574,7 +584,9 @@ describe('Test users notifications', function () {
       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 text1 = `hello @user_1@localhost:${servers[ 0 ].port} 1`
+      const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, text1)
       const server2ThreadId = resThread.body.comment.id
 
       await waitJobs(servers)
@@ -584,8 +596,8 @@ describe('Test users notifications', function () {
       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'
-      await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text)
+      const text2 = `@user_1@localhost:${servers[ 0 ].port} hello 2 @root@localhost:${servers[ 0 ].port}`
+      await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text2)
 
       await waitJobs(servers)
 
@@ -775,7 +787,7 @@ describe('Test users notifications', function () {
     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,
@@ -866,7 +878,18 @@ describe('Test users notifications', function () {
     })
   })
 
-  describe('New instance follower', function () {
+  describe('New instance follows', function () {
+    const instanceIndexServer = new MockInstancesIndex()
+    const config = {
+      followings: {
+        instance: {
+          autoFollowIndex: {
+            indexUrl: 'http://localhost:42100',
+            enabled: true
+          }
+        }
+      }
+    }
     let baseParams: CheckerBaseParams
 
     before(async () => {
@@ -876,19 +899,72 @@ describe('Test users notifications', function () {
         socketNotifications: adminNotifications,
         token: servers[0].accessToken
       }
+
+      await instanceIndexServer.initialize()
+      instanceIndexServer.addInstance(servers[1].host)
     })
 
     it('Should send a notification only to admin when there is a new instance follower', async function () {
-      this.timeout(10000)
+      this.timeout(20000)
 
       await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
 
       await waitJobs(servers)
 
-      await checkNewInstanceFollower(baseParams, 'localhost:9003', 'presence')
+      await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence')
 
       const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
-      await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:9003', 'absence')
+      await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence')
+    })
+
+    it('Should send a notification on auto follow back', async function () {
+      this.timeout(40000)
+
+      await unfollow(servers[2].url, servers[2].accessToken, servers[0])
+      await waitJobs(servers)
+
+      const config = {
+        followings: {
+          instance: {
+            autoFollowBack: { enabled: true }
+          }
+        }
+      }
+      await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
+
+      await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
+
+      await waitJobs(servers)
+
+      const followerHost = servers[0].host
+      const followingHost = servers[2].host
+      await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence')
+
+      const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
+      await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence')
+
+      config.followings.instance.autoFollowBack.enabled = false
+      await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
+      await unfollow(servers[0].url, servers[0].accessToken, servers[2])
+      await unfollow(servers[2].url, servers[2].accessToken, servers[0])
+    })
+
+    it('Should send a notification on auto instances index follow', async function () {
+      this.timeout(30000)
+      await unfollow(servers[0].url, servers[0].accessToken, servers[1])
+
+      await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
+
+      await wait(5000)
+      await waitJobs(servers)
+
+      const followerHost = servers[0].host
+      const followingHost = servers[1].host
+      await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence')
+
+      config.followings.instance.autoFollowIndex.enabled = false
+      await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
+      await unfollow(servers[0].url, servers[0].accessToken, servers[1])
     })
   })
 
@@ -929,29 +1005,29 @@ describe('Test users notifications', function () {
     it('Should notify when a local channel is following one of our channel', async function () {
       this.timeout(10000)
 
-      await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
+      await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
       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')
+      await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
     })
 
     it('Should notify when a remote channel is following one of our channel', async function () {
       this.timeout(10000)
 
-      await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
+      await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
       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')
+      await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
     })
 
     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 addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
 
       await waitJobs(servers)
 
@@ -961,7 +1037,7 @@ describe('Test users notifications', function () {
     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 addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:' + servers[0].port)
 
       await waitJobs(servers)
 
@@ -1015,8 +1091,8 @@ describe('Test users notifications', function () {
       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')
+      await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
+      await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
 
     })
 
@@ -1067,7 +1143,7 @@ describe('Test users notifications', function () {
     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)
+      let updateAt = new Date(new Date().getTime() + 1000000)
 
       const name = 'video with auto-blacklist and future schedule ' + uuidv4()
 
@@ -1138,8 +1214,8 @@ describe('Test users notifications', function () {
     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')
+      await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
+      await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
     })
   })
 
@@ -1295,9 +1371,9 @@ describe('Test users notifications', function () {
     })
   })
 
-  after(function () {
+  after(async function () {
     MockSmtpServer.Instance.kill()
 
-    killallServers(servers)
+    await cleanupTests(servers)
   })
 })