]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/notifications/moderation-notifications.ts
Introduce server commands
[github/Chocobozzz/PeerTube.git] / server / tests / api / notifications / moderation-notifications.ts
index f77719c6839ed50b8147fc0338d41ebd24c3f366..99b4346068f34626a3346db8153394e25df91772 100644 (file)
@@ -3,9 +3,6 @@
 import 'mocha'
 import { buildUUID } from '@server/helpers/uuid'
 import {
-  addUserSubscription,
-  addVideoCommentThread,
-  addVideoToBlacklist,
   checkAbuseStateChange,
   checkAutoInstanceFollowing,
   CheckerBaseParams,
@@ -21,23 +18,13 @@ import {
   checkVideoIsPublished,
   cleanupTests,
   createUser,
-  follow,
   generateUserAccessToken,
-  getAccount,
-  getCustomConfig,
-  getVideoCommentThreads,
   getVideoIdFromUUID,
-  immutableAssign,
   MockInstancesIndex,
   MockSmtpServer,
   prepareNotificationsTest,
   registerUser,
-  removeUserSubscription,
-  removeVideoFromBlacklist,
   ServerInfo,
-  unfollow,
-  updateCustomConfig,
-  updateCustomSubConfig,
   uploadVideo,
   wait,
   waitJobs
@@ -111,8 +98,11 @@ describe('Test moderation notifications', function () {
       const name = 'video for abuse ' + buildUUID()
       const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
       const video = resVideo.body.video
-      const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + buildUUID())
-      const comment = resComment.body.comment
+      const comment = await servers[0].commentsCommand.createThread({
+        token: userAccessToken,
+        videoId: video.id,
+        text: 'comment abuse ' + buildUUID()
+      })
 
       await waitJobs(servers)
 
@@ -128,12 +118,17 @@ describe('Test moderation notifications', function () {
       const name = 'video for abuse ' + buildUUID()
       const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
       const video = resVideo.body.video
-      await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + buildUUID())
+
+      await servers[0].commentsCommand.createThread({
+        token: userAccessToken,
+        videoId: video.id,
+        text: 'comment abuse ' + buildUUID()
+      })
 
       await waitJobs(servers)
 
-      const resComments = await getVideoCommentThreads(servers[1].url, video.uuid, 0, 5)
-      const commentId = resComments.body.data[0].id
+      const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.uuid })
+      const commentId = data[0].id
       await servers[1].abusesCommand.report({ commentId, reason: 'super reason' })
 
       await waitJobs(servers)
@@ -162,8 +157,8 @@ describe('Test moderation notifications', function () {
 
       await waitJobs(servers)
 
-      const resAccount = await getAccount(servers[1].url, username + '@' + servers[0].host)
-      await servers[1].abusesCommand.report({ accountId: resAccount.body.id, reason: 'super reason' })
+      const account = await servers[1].accountsCommand.get({ accountName: username + '@' + servers[0].host })
+      await servers[1].abusesCommand.report({ accountId: account.id, reason: 'super reason' })
 
       await waitJobs(servers)
       await checkNewAccountAbuseForModerators(baseParams, username, 'presence')
@@ -235,7 +230,7 @@ describe('Test moderation notifications', function () {
       const video = resVideo.body.video
 
       {
-        const body  = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' })
+        const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' })
         abuseId = body.abuse.id
       }
 
@@ -305,7 +300,7 @@ describe('Test moderation notifications', function () {
       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 servers[0].blacklistCommand.add({ videoId: uuid })
 
       await waitJobs(servers)
       await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
@@ -318,10 +313,10 @@ describe('Test moderation notifications', function () {
       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 servers[0].blacklistCommand.add({ videoId: uuid })
 
       await waitJobs(servers)
-      await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
+      await servers[0].blacklistCommand.remove({ videoId: uuid })
       await waitJobs(servers)
 
       await wait(500)
@@ -351,7 +346,7 @@ describe('Test moderation notifications', function () {
       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')
+      await checkUserRegistered({ ...baseParams, ...userOverride }, 'user_45', 'absence')
     })
   })
 
@@ -386,20 +381,20 @@ describe('Test moderation notifications', function () {
     it('Should send a notification only to admin when there is a new instance follower', async function () {
       this.timeout(20000)
 
-      await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
+      await servers[2].followsCommand.follow({ targets: [ servers[0].url ] })
 
       await waitJobs(servers)
 
       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:' + servers[2].port, 'absence')
+      await checkNewInstanceFollower({ ...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 servers[2].followsCommand.unfollow({ target: servers[0] })
       await waitJobs(servers)
 
       const config = {
@@ -409,9 +404,9 @@ describe('Test moderation notifications', function () {
           }
         }
       }
-      await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
+      await servers[0].configCommand.updateCustomSubConfig({ newConfig: config })
 
-      await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
+      await servers[2].followsCommand.follow({ targets: [ servers[0].url ] })
 
       await waitJobs(servers)
 
@@ -420,19 +415,19 @@ describe('Test moderation notifications', function () {
       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')
+      await checkAutoInstanceFollowing({ ...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])
+      await servers[0].configCommand.updateCustomSubConfig({ newConfig: config })
+      await servers[0].followsCommand.unfollow({ target: servers[2] })
+      await servers[2].followsCommand.unfollow({ target: 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 servers[0].followsCommand.unfollow({ target: servers[1] })
 
-      await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
+      await servers[0].configCommand.updateCustomSubConfig({ newConfig: config })
 
       await wait(5000)
       await waitJobs(servers)
@@ -442,8 +437,8 @@ describe('Test moderation notifications', function () {
       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])
+      await servers[0].configCommand.updateCustomSubConfig({ newConfig: config })
+      await servers[0].followsCommand.unfollow({ target: servers[1] })
     })
   })
 
@@ -478,9 +473,11 @@ describe('Test moderation notifications', function () {
         token: userAccessToken
       }
 
-      const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken)
-      currentCustomConfig = resCustomConfig.body
-      const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, {
+      currentCustomConfig = await servers[0].configCommand.getCustomConfig()
+
+      const autoBlacklistTestsCustomConfig = {
+        ...currentCustomConfig,
+
         autoBlacklist: {
           videos: {
             ofUsers: {
@@ -488,13 +485,14 @@ describe('Test moderation notifications', function () {
             }
           }
         }
-      })
+      }
+
       // enable transcoding otherwise own publish notification after transcoding not expected
       autoBlacklistTestsCustomConfig.transcoding.enabled = true
-      await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig)
+      await servers[0].configCommand.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig })
 
-      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)
+      await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
+      await servers[1].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
 
     })
 
@@ -524,7 +522,7 @@ describe('Test moderation notifications', function () {
     it('Should send video published and unblacklist after video unblacklisted', async function () {
       this.timeout(40000)
 
-      await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID)
+      await servers[0].blacklistCommand.remove({ videoId: videoUUID })
 
       await waitJobs(servers)
 
@@ -561,7 +559,7 @@ describe('Test moderation notifications', function () {
       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 servers[0].blacklistCommand.remove({ videoId: uuid })
 
       await waitJobs(servers)
       await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
@@ -614,10 +612,10 @@ describe('Test moderation notifications', function () {
     })
 
     after(async () => {
-      await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig)
+      await servers[0].configCommand.updateCustomConfig({ newCustomConfig: currentCustomConfig })
 
-      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)
+      await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
+      await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
     })
   })