]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Refractor check video tests
authorChocobozzz <me@florianbigard.com>
Fri, 29 Dec 2017 10:51:55 +0000 (11:51 +0100)
committerChocobozzz <me@florianbigard.com>
Fri, 29 Dec 2017 11:33:19 +0000 (12:33 +0100)
server/tests/api/server/follows.ts
server/tests/api/videos/multiple-servers.ts
server/tests/api/videos/single-server.ts
server/tests/utils/miscs/miscs.ts
server/tests/utils/videos/videos.ts

index 6c815ace84f4317f8641a2bc58650f1b5b2079ee..311631aae6baa3cfdb2284ef31c5fc3f58bdac2a 100644 (file)
@@ -2,7 +2,9 @@
 
 import * as chai from 'chai'
 import 'mocha'
+import { Video, VideoPrivacy } from '../../../../shared/models/videos'
 import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
+import { completeVideoCheck } from '../../utils'
 
 import {
   flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo,
@@ -163,111 +165,109 @@ describe('Test follows', function () {
     expect(res.body.data[0].name).to.equal('server3')
   })
 
-  it('Should propagate previous uploaded videos on a new following', async function () {
-    this.timeout(20000)
-
-    const video4Attributes = {
-      name: 'server3-4',
-      category: 2,
-      nsfw: true,
-      licence: 6,
-      tags: [ 'tag1', 'tag2', 'tag3' ]
-    }
+  describe('Should propagate data on a new following', async function () {
+    let video4: Video
 
-    await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-2' })
-    await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-3' })
-    await uploadVideo(servers[2].url, servers[2].accessToken, video4Attributes)
-    await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-5' })
-    await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' })
+    before(async function () {
+      this.timeout(20000)
 
-    {
-      const user = { username: 'captain', password: 'password' }
-      await createUser(servers[2].url, servers[2].accessToken, user.username, user.password)
-      const userAccessToken = await userLogin(servers[2], user)
+      const video4Attributes = {
+        name: 'server3-4',
+        category: 2,
+        nsfw: true,
+        licence: 6,
+        tags: [ 'tag1', 'tag2', 'tag3' ]
+      }
 
-      const resVideos = await getVideosList(servers[ 2 ].url)
-      const video4 = resVideos.body.data.find(v => v.name === 'server3-4')
+      await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, { name: 'server3-2' })
+      await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, { name: 'server3-3' })
+      await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, video4Attributes)
+      await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, { name: 'server3-5' })
+      await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, { name: 'server3-6' })
 
       {
-        await rateVideo(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, 'like')
-        await rateVideo(servers[ 2 ].url, userAccessToken, video4.id, 'dislike')
-      }
+        const user = { username: 'captain', password: 'password' }
+        await createUser(servers[ 2 ].url, servers[ 2 ].accessToken, user.username, user.password)
+        const userAccessToken = await userLogin(servers[ 2 ], user)
 
-      {
-        const text = 'my super first comment'
-        const res = await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, text)
-        const threadId = res.body.comment.id
+        const resVideos = await getVideosList(servers[ 2 ].url)
+        video4 = resVideos.body.data.find(v => v.name === 'server3-4')
 
-        const text1 = 'my super answer to thread 1'
-        const childCommentRes = await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text1)
-        const childCommentId = childCommentRes.body.comment.id
+        {
+          await rateVideo(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, 'like')
+          await rateVideo(servers[ 2 ].url, userAccessToken, video4.id, 'dislike')
+        }
 
-        const text2 = 'my super answer to answer of thread 1'
-        await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, childCommentId, text2)
+        {
+          const text = 'my super first comment'
+          const res = await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, text)
+          const threadId = res.body.comment.id
 
-        const text3 = 'my second answer to thread 1'
-        await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text3)
-      }
-    }
+          const text1 = 'my super answer to thread 1'
+          const childCommentRes = await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text1)
+          const childCommentId = childCommentRes.body.comment.id
 
-    await wait(5000)
+          const text2 = 'my super answer to answer of thread 1'
+          await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, childCommentId, text2)
 
-    // Server 1 follows server 3
-    await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken)
+          const text3 = 'my second answer to thread 1'
+          await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text3)
+        }
+      }
 
-    await wait(7000)
+      await wait(5000)
+
+      // Server 1 follows server 3
+      await follow(servers[ 0 ].url, [ servers[ 2 ].url ], servers[ 0 ].accessToken)
+
+      await wait(7000)
+    })
+
+    it('Should propagate videos', async function () {
+      const res = await getVideosList(servers[ 0 ].url)
+      expect(res.body.total).to.equal(7)
+
+      const video2 = res.body.data.find(v => v.name === 'server3-2')
+      video4 = res.body.data.find(v => v.name === 'server3-4')
+      const video6 = res.body.data.find(v => v.name === 'server3-6')
+
+      expect(video2).to.not.be.undefined
+      expect(video4).to.not.be.undefined
+      expect(video6).to.not.be.undefined
+
+      const isLocal = false
+      const checkAttributes = {
+        name: 'server3-4',
+        category: 2,
+        licence: 6,
+        language: 3,
+        nsfw: true,
+        description: 'my super description',
+        host: 'localhost:9003',
+        account: 'root',
+        isLocal,
+        duration: 5,
+        tags: [ 'tag1', 'tag2', 'tag3' ],
+        privacy: VideoPrivacy.PUBLIC,
+        likes: 1,
+        dislikes: 1,
+        channel: {
+          name: 'Default root channel',
+          description: '',
+          isLocal
+        },
+        fixture: 'video_short.webm',
+        files: [
+          {
+            resolution: 720,
+            size: 218910
+          }
+        ]
+      }
+      await completeVideoCheck(servers[ 0 ].url, video4, checkAttributes)
+    })
 
-    let res = await getVideosList(servers[0].url)
-    expect(res.body.total).to.equal(7)
-
-    const video2 = res.body.data.find(v => v.name === 'server3-2')
-    const video4 = res.body.data.find(v => v.name === 'server3-4')
-    const video6 = res.body.data.find(v => v.name === 'server3-6')
-
-    expect(video2).to.not.be.undefined
-    expect(video4).to.not.be.undefined
-    expect(video6).to.not.be.undefined
-
-    const res2 = await getVideo(servers[0].url, video4.id)
-    const videoDetails = res2.body
-
-    expect(videoDetails.name).to.equal('server3-4')
-    expect(videoDetails.category).to.equal(2)
-    expect(videoDetails.categoryLabel).to.equal('Films')
-    expect(videoDetails.licence).to.equal(6)
-    expect(videoDetails.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
-    expect(videoDetails.language).to.equal(3)
-    expect(videoDetails.languageLabel).to.equal('Mandarin')
-    expect(videoDetails.nsfw).to.be.ok
-    expect(videoDetails.description).to.equal('my super description')
-    expect(videoDetails.serverHost).to.equal('localhost:9003')
-    expect(videoDetails.accountName).to.equal('root')
-    expect(videoDetails.likes).to.equal(1)
-    expect(videoDetails.dislikes).to.equal(1)
-    expect(videoDetails.isLocal).to.be.false
-    expect(videoDetails.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
-    expect(dateIsValid(videoDetails.createdAt)).to.be.true
-    expect(dateIsValid(videoDetails.updatedAt)).to.be.true
-    expect(videoDetails.files).to.have.lengthOf(1)
-
-    const file = videoDetails.files[0]
-    const magnetUri = file.magnetUri
-    expect(file.magnetUri).to.have.lengthOf.above(2)
-    expect(file.torrentUrl).to.equal(`${servers[2].url}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
-    expect(file.fileUrl).to.equal(`${servers[2].url}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)
-    expect(file.resolution).to.equal(720)
-    expect(file.resolutionLabel).to.equal('720p')
-    expect(file.size).to.equal(218910)
-
-    const test = await testVideoImage(servers[2].url, 'video_short.webm', videoDetails.thumbnailPath)
-    expect(test).to.equal(true)
-
-    const torrent = await webtorrentAdd(magnetUri)
-    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('')
-
-    {
+    it('Should propagate comments', async function () {
       const res1 = await getVideoCommentThreads(servers[0].url, video4.id, 0, 5)
 
       expect(res1.body.total).to.equal(1)
@@ -304,7 +304,7 @@ describe('Test follows', function () {
       const secondChild = tree.children[1]
       expect(secondChild.comment.text).to.equal('my second answer to thread 1')
       expect(secondChild.children).to.have.lengthOf(0)
-    }
+    })
   })
 
   after(async function () {
index 2a943fe45633781a09fa492408c3d3e7d7ae68e5..d35d1204a1f6a9492f7aa37beb986b6ed2824370 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,41 @@ 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,
+          channel: {
+            name: 'my channel',
+            description: 'super channel',
+            isLocal
+          },
+          fixture: 'video_short.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 +144,53 @@ 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,
+          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 +223,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 +243,61 @@ 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,
+          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',
+          isLocal,
+          duration: 5,
+          tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
+          privacy: VideoPrivacy.PUBLIC,
+          channel: {
+            name: 'Default root channel',
+            description: '',
+            isLocal
+          },
+          fixture: 'video_short3.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 +315,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 +330,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 +345,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 +531,36 @@ 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,
+          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)
       }
     })
 
@@ -833,19 +760,46 @@ 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,
+          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)
       }
     })
   })
index 831be34223cc7de932c0c0bae440962ad2ec6eee..934c653b19dd0bfe992781fbbe70aa5a36668316 100644 (file)
@@ -52,10 +52,12 @@ describe('Test a single server', function () {
     host: 'localhost:9001',
     account: 'root',
     isLocal: true,
+    duration: 5,
     tags: [ 'tag1', 'tag2', 'tag3' ],
     privacy: VideoPrivacy.PUBLIC,
     channel: {
       name: 'Default root channel',
+      description: '',
       isLocal: true
     },
     fixture: 'video_short.webm',
@@ -79,8 +81,10 @@ describe('Test a single server', function () {
     isLocal: true,
     tags: [ 'tagup1', 'tagup2' ],
     privacy: VideoPrivacy.PUBLIC,
+    duration: 5,
     channel: {
       name: 'Default root channel',
+      description: '',
       isLocal: true
     },
     fixture: 'video_short3.webm',
index 2147a07ff6387c9037c52188abdb15e642225b6d..2c51d1f0a248b68c65943af181e790dcd0ee05e2 100644 (file)
@@ -27,8 +27,8 @@ function readdirPromise (path: string) {
   })
 }
 
-  // Default interval -> 2 minutes
-function dateIsValid (dateString: string, interval = 120000) {
+  // Default interval -> 5 minutes
+function dateIsValid (dateString: string, interval = 300000) {
   const dateToCheck = new Date(dateString)
   const now = new Date()
 
index 17c3dbc15a67d4f6bd96fe1a132a328c11a082b7..d6bf27dc7a8b5d10586d48c21cdb3134a6d1979d 100644 (file)
@@ -3,7 +3,7 @@
 import { expect } from 'chai'
 import { readFile } from 'fs'
 import * as parseTorrent from 'parse-torrent'
-import { isAbsolute, join } from 'path'
+import { extname, isAbsolute, join } from 'path'
 import * as request from 'supertest'
 import { getMyUserInformation, makeGetRequest, readFilePromise, ServerInfo } from '../'
 import { VideoPrivacy } from '../../../../shared/models/videos'
@@ -332,8 +332,12 @@ async function completeVideoCheck (
     isLocal: boolean,
     tags: string[],
     privacy: number,
+    likes?: number,
+    dislikes?: number,
+    duration: number,
     channel: {
       name: string,
+      description
       isLocal: boolean
     }
     fixture: string,
@@ -343,18 +347,24 @@ async function completeVideoCheck (
     }[]
   }
 ) {
+  if (!attributes.likes) attributes.likes = 0
+  if (!attributes.dislikes) attributes.dislikes = 0
+
   expect(video.name).to.equal(attributes.name)
   expect(video.category).to.equal(attributes.category)
-  expect(video.categoryLabel).to.equal(VIDEO_CATEGORIES[attributes.category])
+  expect(video.categoryLabel).to.equal(VIDEO_CATEGORIES[attributes.category] || 'Misc')
   expect(video.licence).to.equal(attributes.licence)
-  expect(video.licenceLabel).to.equal(VIDEO_LICENCES[attributes.licence])
+  expect(video.licenceLabel).to.equal(VIDEO_LICENCES[attributes.licence] || 'Unknown')
   expect(video.language).to.equal(attributes.language)
-  expect(video.languageLabel).to.equal(VIDEO_LANGUAGES[attributes.language])
+  expect(video.languageLabel).to.equal(VIDEO_LANGUAGES[attributes.language] || 'Unknown')
   expect(video.nsfw).to.equal(attributes.nsfw)
   expect(video.description).to.equal(attributes.description)
   expect(video.serverHost).to.equal(attributes.host)
   expect(video.accountName).to.equal(attributes.account)
+  expect(video.likes).to.equal(attributes.likes)
+  expect(video.dislikes).to.equal(attributes.dislikes)
   expect(video.isLocal).to.equal(attributes.isLocal)
+  expect(video.duration).to.equal(attributes.duration)
   expect(dateIsValid(video.createdAt)).to.be.true
   expect(dateIsValid(video.updatedAt)).to.be.true
 
@@ -376,13 +386,20 @@ async function completeVideoCheck (
     const file = videoDetails.files.find(f => f.resolution === attributeFile.resolution)
     expect(file).not.to.be.undefined
 
+    let extension = extname(attributes.fixture)
+    // Transcoding enabled on server 2, extension will always be .mp4
+    if (attributes.host === 'localhost:9002') extension = '.mp4'
+
     const magnetUri = file.magnetUri
     expect(file.magnetUri).to.have.lengthOf.above(2)
-    expect(file.torrentUrl).to.equal(`${url}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
-    expect(file.fileUrl).to.equal(`${url}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)
+    expect(file.torrentUrl).to.equal(`http://${attributes.host}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
+    expect(file.fileUrl).to.equal(`http://${attributes.host}/static/webseed/${videoDetails.uuid}-${file.resolution}${extension}`)
     expect(file.resolution).to.equal(attributeFile.resolution)
     expect(file.resolutionLabel).to.equal(attributeFile.resolution + 'p')
-    expect(file.size).to.equal(attributeFile.size)
+
+    const minSize = attributeFile.size - ((10 * attributeFile.size) / 100)
+    const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100)
+    expect(file.size).to.be.above(minSize).and.below(maxSize)
 
     const test = await testVideoImage(url, attributes.fixture, videoDetails.thumbnailPath)
     expect(test).to.equal(true)