]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/multiple-servers.ts
Add ability to disable video comments
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / multiple-servers.ts
index 0c6508e71dbfd9a08112d3379696cbb00ae2b30b..b6dfe0d1b569d51075687682ef453d0273c31192 100644 (file)
@@ -4,19 +4,18 @@ import * as chai from 'chai'
 import 'mocha'
 import { join } from 'path'
 import * as request from 'supertest'
+import { VideoPrivacy } from '../../../../shared/models/videos'
 import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
 
 import {
-  addVideoChannel, dateIsValid, doubleFollow, flushAndRunMultipleServers, flushTests, userLogin, getVideo,
+  addVideoChannel, completeVideoCheck, createUser, dateIsValid, doubleFollow, flushAndRunMultipleServers, flushTests, getVideo,
   getVideoChannelsList, getVideosList, killallServers, rateVideo, removeVideo, ServerInfo, setAccessTokensToServers, testVideoImage,
-  updateVideo, uploadVideo, wait, webtorrentAdd
-} from '../../utils/index'
-import { createUser } from '../../utils/users/users'
+  updateVideo, uploadVideo, userLogin, viewVideo, wait, webtorrentAdd
+} from '../../utils'
 import {
   addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads,
   getVideoThreadComments
 } from '../../utils/videos/video-comments'
-import { viewVideo } from '../../utils/videos/videos'
 
 const expect = chai.expect
 
@@ -80,67 +79,42 @@ describe('Test multiple servers', function () {
 
       // All servers should have this video
       for (const server of servers) {
-        let baseMagnet = null
+        const isLocal = server.url === 'http://localhost:9001'
+        const checkAttributes = {
+          name: 'my super name for server 1',
+          category: 5,
+          licence: 4,
+          language: 9,
+          nsfw: true,
+          description: 'my super description for server 1',
+          host: 'localhost:9001',
+          account: 'root',
+          isLocal,
+          duration: 10,
+          tags: [ 'tag1p1', 'tag2p1' ],
+          privacy: VideoPrivacy.PUBLIC,
+          commentsEnabled: true,
+          channel: {
+            name: 'my channel',
+            description: 'super channel',
+            isLocal
+          },
+          fixture: 'video_short1.webm',
+          files: [
+            {
+              resolution: 720,
+              size: 572456
+            }
+          ]
+        }
 
         const res = await getVideosList(server.url)
-
         const videos = res.body.data
         expect(videos).to.be.an('array')
         expect(videos.length).to.equal(1)
         const video = videos[0]
-        expect(video.name).to.equal('my super name for server 1')
-        expect(video.category).to.equal(5)
-        expect(video.categoryLabel).to.equal('Sports')
-        expect(video.licence).to.equal(4)
-        expect(video.licenceLabel).to.equal('Attribution - Non Commercial')
-        expect(video.language).to.equal(9)
-        expect(video.languageLabel).to.equal('Japanese')
-        expect(video.nsfw).to.be.ok
-        expect(video.description).to.equal('my super description for server 1')
-        expect(video.serverHost).to.equal('localhost:9001')
-        expect(video.duration).to.equal(10)
-        expect(dateIsValid(video.createdAt)).to.be.true
-        expect(dateIsValid(video.updatedAt)).to.be.true
-        expect(video.accountName).to.equal('root')
-
-        const res2 = await getVideo(server.url, video.uuid)
-        const videoDetails = res2.body
-
-        expect(videoDetails.channel.name).to.equal('my channel')
-        expect(videoDetails.channel.description).to.equal('super channel')
-        expect(videoDetails.account.name).to.equal('root')
-        expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true
-        expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true
-        expect(videoDetails.files).to.have.lengthOf(1)
-        expect(videoDetails.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
-
-        const file = videoDetails.files[0]
-        const magnetUri = file.magnetUri
-        expect(file.magnetUri).to.have.lengthOf.above(2)
-        expect(file.torrentUrl).to
-          .equal(`http://${videoDetails.serverHost}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
-        expect(file.fileUrl).to.equal(`http://${videoDetails.serverHost}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)
-        expect(file.resolution).to.equal(720)
-        expect(file.resolutionLabel).to.equal('720p')
-        expect(file.size).to.equal(572456)
-
-        if (server.url !== 'http://localhost:9001') {
-          expect(video.isLocal).to.be.false
-          expect(videoDetails.channel.isLocal).to.be.false
-        } else {
-          expect(video.isLocal).to.be.true
-          expect(videoDetails.channel.isLocal).to.be.true
-        }
-
-        // All servers should have the same magnet Uri
-        if (baseMagnet === null) {
-          baseMagnet = magnetUri
-        } else {
-          expect(baseMagnet).to.equal(magnetUri)
-        }
 
-        const test = await testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath)
-        expect(test).to.equal(true)
+        await completeVideoCheck(server.url, video, checkAttributes)
       }
     })
 
@@ -171,79 +145,54 @@ describe('Test multiple servers', function () {
 
       // All servers should have this video
       for (const server of servers) {
-        let baseMagnet = {}
+        const isLocal = server.url === 'http://localhost:9002'
+        const checkAttributes = {
+          name: 'my super name for server 2',
+          category: 4,
+          licence: 3,
+          language: 11,
+          nsfw: true,
+          description: 'my super description for server 2',
+          host: 'localhost:9002',
+          account: 'user1',
+          isLocal,
+          commentsEnabled: true,
+          duration: 5,
+          tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
+          privacy: VideoPrivacy.PUBLIC,
+          channel: {
+            name: 'Default user1 channel',
+            description: 'super channel',
+            isLocal
+          },
+          fixture: 'video_short2.webm',
+          files: [
+            {
+              resolution: 240,
+              size: 190000
+            },
+            {
+              resolution: 360,
+              size: 280000
+            },
+            {
+              resolution: 480,
+              size: 390000
+            },
+            {
+              resolution: 720,
+              size: 710000
+            }
+          ]
+        }
 
         const res = await getVideosList(server.url)
-
         const videos = res.body.data
         expect(videos).to.be.an('array')
         expect(videos.length).to.equal(2)
         const video = videos[1]
-        expect(video.name).to.equal('my super name for server 2')
-        expect(video.category).to.equal(4)
-        expect(video.categoryLabel).to.equal('Art')
-        expect(video.licence).to.equal(3)
-        expect(video.licenceLabel).to.equal('Attribution - No Derivatives')
-        expect(video.language).to.equal(11)
-        expect(video.languageLabel).to.equal('German')
-        expect(video.nsfw).to.be.true
-        expect(video.description).to.equal('my super description for server 2')
-        expect(video.serverHost).to.equal('localhost:9002')
-        expect(video.duration).to.equal(5)
-        expect(dateIsValid(video.createdAt)).to.be.true
-        expect(dateIsValid(video.updatedAt)).to.be.true
-        expect(video.accountName).to.equal('user1')
-
-        if (server.url !== 'http://localhost:9002') {
-          expect(video.isLocal).to.be.false
-        } else {
-          expect(video.isLocal).to.be.true
-        }
-
-        const res2 = await getVideo(server.url, video.uuid)
-        const videoDetails = res2.body
 
-        expect(videoDetails.channel.name).to.equal('Default user1 channel')
-        expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true
-        expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true
-        expect(videoDetails.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
-
-        expect(videoDetails.files).to.have.lengthOf(4)
-
-        // Check common attributes
-        for (const file of videoDetails.files) {
-          expect(file.magnetUri).to.have.lengthOf.above(2)
-
-          // All servers should have the same magnet Uri
-          if (baseMagnet[file.resolution] === undefined) {
-            baseMagnet[file.resolution] = file.magnet
-          } else {
-            expect(baseMagnet[file.resolution]).to.equal(file.magnet)
-          }
-        }
-
-        const file240p = videoDetails.files.find(f => f.resolution === 240)
-        expect(file240p).not.to.be.undefined
-        expect(file240p.resolutionLabel).to.equal('240p')
-        expect(file240p.size).to.be.above(180000).and.below(200000)
-
-        const file360p = videoDetails.files.find(f => f.resolution === 360)
-        expect(file360p).not.to.be.undefined
-        expect(file360p.resolutionLabel).to.equal('360p')
-        expect(file360p.size).to.be.above(270000).and.below(290000)
-
-        const file480p = videoDetails.files.find(f => f.resolution === 480)
-        expect(file480p).not.to.be.undefined
-        expect(file480p.resolutionLabel).to.equal('480p')
-        expect(file480p.size).to.be.above(380000).and.below(400000)
-
-        const file720p = videoDetails.files.find(f => f.resolution === 720)
-        expect(file720p).not.to.be.undefined
-        expect(file720p.resolutionLabel).to.equal('720p')
-        expect(file720p.size).to.be.above(700000).and.below(7200000)
-
-        const test = await testVideoImage(server.url, 'video_short2.webm', videoDetails.thumbnailPath)
-        expect(test).to.equal(true)
+        await completeVideoCheck(server.url, video, checkAttributes)
       }
     })
 
@@ -276,9 +225,9 @@ describe('Test multiple servers', function () {
 
       await wait(10000)
 
-      let baseMagnet = null
       // All servers should have this video
       for (const server of servers) {
+        const isLocal = server.url === 'http://localhost:9003'
         const res = await getVideosList(server.url)
 
         const videos = res.body.data
@@ -296,80 +245,63 @@ describe('Test multiple servers', function () {
           video2 = videos[2]
         }
 
-        expect(video1.name).to.equal('my super name for server 3')
-        expect(video1.category).to.equal(6)
-        expect(video1.categoryLabel).to.equal('Travels')
-        expect(video1.licence).to.equal(5)
-        expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike')
-        expect(video1.language).to.equal(11)
-        expect(video1.languageLabel).to.equal('German')
-        expect(video1.nsfw).to.be.ok
-        expect(video1.description).to.equal('my super description for server 3')
-        expect(video1.serverHost).to.equal('localhost:9003')
-        expect(video1.duration).to.equal(5)
-        expect(video1.accountName).to.equal('root')
-        expect(dateIsValid(video1.createdAt)).to.be.true
-        expect(dateIsValid(video1.updatedAt)).to.be.true
-
-        const res2 = await getVideo(server.url, video1.id)
-        const video1Details = res2.body
-        expect(video1Details.files).to.have.lengthOf(1)
-        expect(video1Details.tags).to.deep.equal([ 'tag1p3' ])
-
-        const file1 = video1Details.files[0]
-        expect(file1.magnetUri).to.have.lengthOf.above(2)
-        expect(file1.resolution).to.equal(720)
-        expect(file1.resolutionLabel).to.equal('720p')
-        expect(file1.size).to.equal(292677)
-
-        expect(video2.name).to.equal('my super name for server 3-2')
-        expect(video2.category).to.equal(7)
-        expect(video2.categoryLabel).to.equal('Gaming')
-        expect(video2.licence).to.equal(6)
-        expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
-        expect(video2.language).to.equal(12)
-        expect(video2.languageLabel).to.equal('Korean')
-        expect(video2.nsfw).to.be.false
-        expect(video2.description).to.equal('my super description for server 3-2')
-        expect(video2.serverHost).to.equal('localhost:9003')
-        expect(video2.duration).to.equal(5)
-        expect(video2.accountName).to.equal('root')
-        expect(dateIsValid(video2.createdAt)).to.be.true
-        expect(dateIsValid(video2.updatedAt)).to.be.true
-
-        const res3 = await getVideo(server.url, video2.id)
-        const video2Details = res3.body
-        expect(video2Details.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
-
-        expect(video2Details.files).to.have.lengthOf(1)
-
-        const file2 = video2Details.files[0]
-        const magnetUri2 = file2.magnetUri
-        expect(file2.magnetUri).to.have.lengthOf.above(2)
-        expect(file2.resolution).to.equal(720)
-        expect(file2.resolutionLabel).to.equal('720p')
-        expect(file2.size).to.equal(218910)
-
-        if (server.url !== 'http://localhost:9003') {
-          expect(video1.isLocal).to.be.false
-          expect(video2.isLocal).to.be.false
-        } else {
-          expect(video1.isLocal).to.be.true
-          expect(video2.isLocal).to.be.true
+        const checkAttributesVideo1 = {
+          name: 'my super name for server 3',
+          category: 6,
+          licence: 5,
+          language: 11,
+          nsfw: true,
+          description: 'my super description for server 3',
+          host: 'localhost:9003',
+          account: 'root',
+          isLocal,
+          duration: 5,
+          commentsEnabled: true,
+          tags: [ 'tag1p3' ],
+          privacy: VideoPrivacy.PUBLIC,
+          channel: {
+            name: 'Default root channel',
+            description: '',
+            isLocal
+          },
+          fixture: 'video_short3.webm',
+          files: [
+            {
+              resolution: 720,
+              size: 292677
+            }
+          ]
         }
-
-        // All servers should have the same magnet Uri
-        if (baseMagnet === null) {
-          baseMagnet = magnetUri2
-        } else {
-          expect(baseMagnet).to.equal(magnetUri2)
+        await completeVideoCheck(server.url, video1, checkAttributesVideo1)
+
+        const checkAttributesVideo2 = {
+          name: 'my super name for server 3-2',
+          category: 7,
+          licence: 6,
+          language: 12,
+          nsfw: false,
+          description: 'my super description for server 3-2',
+          host: 'localhost:9003',
+          account: 'root',
+          commentsEnabled: true,
+          isLocal,
+          duration: 5,
+          tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
+          privacy: VideoPrivacy.PUBLIC,
+          channel: {
+            name: 'Default root channel',
+            description: '',
+            isLocal
+          },
+          fixture: 'video_short.webm',
+          files: [
+            {
+              resolution: 720,
+              size: 218910
+            }
+          ]
         }
-
-        const test1 = await testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath)
-        expect(test1).to.equal(true)
-
-        const test2 = await testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath)
-        expect(test2).to.equal(true)
+        await completeVideoCheck(server.url, video2, checkAttributesVideo2)
       }
     })
   })
@@ -387,7 +319,7 @@ describe('Test multiple servers', function () {
       const res2 = await getVideo(servers[2].url, video.id)
       const videoDetails = res2.body
 
-      const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
+      const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
       expect(torrent.files).to.be.an('array')
       expect(torrent.files.length).to.equal(1)
       expect(torrent.files[0].path).to.exist.and.to.not.equal('')
@@ -402,7 +334,7 @@ describe('Test multiple servers', function () {
       const res2 = await getVideo(servers[0].url, video.id)
       const videoDetails = res2.body
 
-      const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
+      const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
       expect(torrent.files).to.be.an('array')
       expect(torrent.files.length).to.equal(1)
       expect(torrent.files[0].path).to.exist.and.to.not.equal('')
@@ -417,7 +349,7 @@ describe('Test multiple servers', function () {
       const res2 = await getVideo(servers[1].url, video.id)
       const videoDetails = res2.body
 
-      const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
+      const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
       expect(torrent.files).to.be.an('array')
       expect(torrent.files.length).to.equal(1)
       expect(torrent.files[0].path).to.exist.and.to.not.equal('')
@@ -603,37 +535,37 @@ describe('Test multiple servers', function () {
 
         const videos = res.body.data
         const videoUpdated = videos.find(video => video.name === 'my super video updated')
-
         expect(!!videoUpdated).to.be.true
-        expect(videoUpdated.category).to.equal(10)
-        expect(videoUpdated.categoryLabel).to.equal('Entertainment')
-        expect(videoUpdated.licence).to.equal(7)
-        expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication')
-        expect(videoUpdated.language).to.equal(13)
-        expect(videoUpdated.languageLabel).to.equal('French')
-        expect(videoUpdated.nsfw).to.be.ok
-        expect(videoUpdated.description).to.equal('my super description updated')
-        expect(dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
-
-        const res2 = await getVideo(server.url, videoUpdated.uuid)
-        const videoUpdatedDetails = res2.body
-        expect(videoUpdatedDetails.tags).to.deep.equal([ 'tag_up_1', 'tag_up_2' ])
-
-        const file = videoUpdatedDetails.files[0]
-        expect(file.magnetUri).to.have.lengthOf.above(2)
-        expect(file.resolution).to.equal(720)
-        expect(file.resolutionLabel).to.equal('720p')
-        expect(file.size).to.equal(292677)
-
-        const test = await testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath)
-        expect(test).to.equal(true)
 
-        // Avoid "duplicate torrent" errors
-        const refreshWebTorrent = true
-        const torrent = await webtorrentAdd(videoUpdatedDetails .files[0].magnetUri, refreshWebTorrent)
-        expect(torrent.files).to.be.an('array')
-        expect(torrent.files.length).to.equal(1)
-        expect(torrent.files[0].path).to.exist.and.to.not.equal('')
+        const isLocal = server.url === 'http://localhost:9003'
+        const checkAttributes = {
+          name: 'my super video updated',
+          category: 10,
+          licence: 7,
+          language: 13,
+          nsfw: true,
+          description: 'my super description updated',
+          host: 'localhost:9003',
+          account: 'root',
+          isLocal,
+          duration: 5,
+          commentsEnabled: true,
+          tags: [ 'tag_up_1', 'tag_up_2' ],
+          privacy: VideoPrivacy.PUBLIC,
+          channel: {
+            name: 'Default root channel',
+            description: '',
+            isLocal
+          },
+          fixture: 'video_short3.webm',
+          files: [
+            {
+              resolution: 720,
+              size: 292677
+            }
+          ]
+        }
+        await completeVideoCheck(server.url, videoUpdated, checkAttributes)
       }
     })
 
@@ -805,6 +737,26 @@ describe('Test multiple servers', function () {
         expect(secondChild.children).to.have.lengthOf(0)
       }
     })
+
+    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 () {
@@ -821,8 +773,9 @@ 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')
+      const filePath = join(__dirname, '..', '..', 'api', 'fixtures', 'video_short.webm')
 
       await req.attach('videofile', filePath)
         .expect(200)
@@ -833,19 +786,47 @@ describe('Test multiple servers', function () {
         const res = await getVideosList(server.url)
         const video = res.body.data.find(v => v.name === 'minimum parameters')
 
-        expect(video.name).to.equal('minimum parameters')
-        expect(video.category).to.equal(null)
-        expect(video.categoryLabel).to.equal('Misc')
-        expect(video.licence).to.equal(null)
-        expect(video.licenceLabel).to.equal('Unknown')
-        expect(video.language).to.equal(null)
-        expect(video.languageLabel).to.equal('Unknown')
-        expect(video.nsfw).to.not.be.ok
-        expect(video.description).to.equal(null)
-        expect(video.serverHost).to.equal('localhost:9002')
-        expect(video.accountName).to.equal('root')
-        expect(dateIsValid(video.createdAt)).to.be.true
-        expect(dateIsValid(video.updatedAt)).to.be.true
+        const isLocal = server.url === 'http://localhost:9002'
+        const checkAttributes = {
+          name: 'minimum parameters',
+          category: null,
+          licence: null,
+          language: null,
+          nsfw: false,
+          description: null,
+          host: 'localhost:9002',
+          account: 'root',
+          isLocal,
+          duration: 5,
+          commentsEnabled: true,
+          tags: [ ],
+          privacy: VideoPrivacy.PUBLIC,
+          channel: {
+            name: 'Default root channel',
+            description: '',
+            isLocal
+          },
+          fixture: 'video_short.webm',
+          files: [
+            {
+              resolution: 720,
+              size: 40315
+            },
+            {
+              resolution: 480,
+              size: 22808
+            },
+            {
+              resolution: 360,
+              size: 18617
+            },
+            {
+              resolution: 240,
+              size: 15217
+            }
+          ]
+        }
+        await completeVideoCheck(server.url, video, checkAttributes)
       }
     })
   })