]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/multiple-servers.ts
Add tests for emails
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / multiple-servers.ts
index d35d1204a1f6a9492f7aa37beb986b6ed2824370..0215b30118693ae06b093b2608577fd9e6c66694 100644 (file)
@@ -8,12 +8,13 @@ import { VideoPrivacy } from '../../../../shared/models/videos'
 import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
 
 import {
-  addVideoChannel, completeVideoCheck, createUser, dateIsValid, doubleFollow, flushAndRunMultipleServers, flushTests, getVideo,
-  getVideoChannelsList, getVideosList, killallServers, rateVideo, removeVideo, ServerInfo, setAccessTokensToServers, testVideoImage,
+  addVideoChannel, checkVideoFilesWereRemoved, completeVideoCheck, createUser, dateIsValid, doubleFollow, flushAndRunMultipleServers,
+  flushTests, getVideo,
+  getVideoChannelsList, getVideosList, killallServers, rateVideo, removeVideo, ServerInfo, setAccessTokensToServers, testImage,
   updateVideo, uploadVideo, userLogin, viewVideo, wait, webtorrentAdd
 } from '../../utils'
 import {
-  addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads,
+  addVideoCommentReply, addVideoCommentThread, deleteVideoComment, getVideoCommentThreads,
   getVideoThreadComments
 } from '../../utils/videos/video-comments'
 
@@ -93,12 +94,13 @@ describe('Test multiple servers', function () {
           duration: 10,
           tags: [ 'tag1p1', 'tag2p1' ],
           privacy: VideoPrivacy.PUBLIC,
+          commentsEnabled: true,
           channel: {
             name: 'my channel',
             description: 'super channel',
             isLocal
           },
-          fixture: 'video_short.webm',
+          fixture: 'video_short1.webm',
           files: [
             {
               resolution: 720,
@@ -155,6 +157,7 @@ describe('Test multiple servers', function () {
           host: 'localhost:9002',
           account: 'user1',
           isLocal,
+          commentsEnabled: true,
           duration: 5,
           tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
           privacy: VideoPrivacy.PUBLIC,
@@ -254,6 +257,7 @@ describe('Test multiple servers', function () {
           account: 'root',
           isLocal,
           duration: 5,
+          commentsEnabled: true,
           tags: [ 'tag1p3' ],
           privacy: VideoPrivacy.PUBLIC,
           channel: {
@@ -280,6 +284,7 @@ describe('Test multiple servers', function () {
           description: 'my super description for server 3-2',
           host: 'localhost:9003',
           account: 'root',
+          commentsEnabled: true,
           isLocal,
           duration: 5,
           tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
@@ -289,7 +294,7 @@ describe('Test multiple servers', function () {
             description: '',
             isLocal
           },
-          fixture: 'video_short3.webm',
+          fixture: 'video_short.webm',
           files: [
             {
               resolution: 720,
@@ -470,16 +475,17 @@ describe('Test multiple servers', function () {
     it('Should like and dislikes videos on different services', async function () {
       this.timeout(20000)
 
-      const tasks: Promise<any>[] = []
-      tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like'))
-      tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike'))
-      tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like'))
-      tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like'))
-      tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike'))
-      tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike'))
-      tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like'))
-
-      await Promise.all(tasks)
+      await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')
+      await wait(200)
+      await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike')
+      await wait(200)
+      await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')
+      await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like')
+      await wait(200)
+      await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike')
+      await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike')
+      await wait(200)
+      await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like')
 
       await wait(10000)
 
@@ -545,6 +551,7 @@ describe('Test multiple servers', function () {
           account: 'root',
           isLocal,
           duration: 5,
+          commentsEnabled: true,
           tags: [ 'tag_up_1', 'tag_up_2' ],
           privacy: VideoPrivacy.PUBLIC,
           channel: {
@@ -573,6 +580,13 @@ describe('Test multiple servers', function () {
       await wait(5000)
     })
 
+    it('Should not have files of videos 3 and 3-2 on each server', async function () {
+      for (const server of servers) {
+        await checkVideoFilesWereRemoved(toRemove[0].uuid, server.serverNumber)
+        await checkVideoFilesWereRemoved(toRemove[1].uuid, server.serverNumber)
+      }
+    })
+
     it('Should have videos 1 and 3 on each server', async function () {
       for (const server of servers) {
         const res = await getVideosList(server.url)
@@ -619,7 +633,7 @@ describe('Test multiple servers', function () {
         const res = await getVideo(server.url, videoUUID)
         const video = res.body
 
-        const test = await testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath)
+        const test = await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
         expect(test).to.equal(true)
       }
     })
@@ -732,6 +746,57 @@ describe('Test multiple servers', function () {
         expect(secondChild.children).to.have.lengthOf(0)
       }
     })
+
+    it('Should delete the thread comments', async function () {
+      this.timeout(10000)
+
+      const res1 = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5)
+      const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
+      await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
+
+      await wait(5000)
+    })
+
+    it('Should have the thread comments deleted on other servers too', async function () {
+      for (const server of servers) {
+        const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
+
+        expect(res.body.total).to.equal(1)
+        expect(res.body.data).to.be.an('array')
+        expect(res.body.data).to.have.lengthOf(1)
+
+        {
+          const comment: VideoComment = res.body.data[0]
+          expect(comment).to.not.be.undefined
+          expect(comment.inReplyToCommentId).to.be.null
+          expect(comment.account.name).to.equal('root')
+          expect(comment.account.host).to.equal('localhost:9003')
+          expect(comment.totalReplies).to.equal(0)
+          expect(dateIsValid(comment.createdAt as string)).to.be.true
+          expect(dateIsValid(comment.updatedAt as string)).to.be.true
+        }
+      }
+    })
+
+    it('Should disable comments', async function () {
+      this.timeout(20000)
+
+      const attributes = {
+        commentsEnabled: false
+      }
+
+      await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes)
+
+      await wait(5000)
+
+      for (const server of servers) {
+        const res = await getVideo(server.url, videoUUID)
+        expect(res.body.commentsEnabled).to.be.false
+
+        const text = 'my super forbidden comment'
+        await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, 409)
+      }
+    })
   })
 
   describe('With minimum parameters', function () {
@@ -748,6 +813,7 @@ describe('Test multiple servers', function () {
         .field('privacy', '1')
         .field('nsfw', 'false')
         .field('channelId', '1')
+        .field('commentsEnabled', 'true')
 
       const filePath = join(__dirname, '..', '..', 'api', 'fixtures', 'video_short.webm')
 
@@ -772,6 +838,7 @@ describe('Test multiple servers', function () {
           account: 'root',
           isLocal,
           duration: 5,
+          commentsEnabled: true,
           tags: [ ],
           privacy: VideoPrivacy.PUBLIC,
           channel: {