]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/multiple-servers.ts
Fix tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / multiple-servers.ts
index d47807a796b4e8c8ab081c673db594a98030dbf1..27ba00d3d5d7887c324f09d616a349c30dbd47c8 100644 (file)
@@ -5,6 +5,7 @@ import request from 'supertest'
 import {
   checkTmpIsEmpty,
   checkVideoFilesWereRemoved,
+  checkWebTorrentWorks,
   completeVideoCheck,
   dateIsValid,
   saveVideoInServers,
@@ -21,8 +22,7 @@ import {
   setAccessTokensToServers,
   setDefaultAccountAvatar,
   setDefaultChannelAvatar,
-  waitJobs,
-  webtorrentAdd
+  waitJobs
 } from '@shared/server-commands'
 
 describe('Test multiple servers', function () {
@@ -105,7 +105,7 @@ describe('Test multiple servers', function () {
           originallyPublishedAt: '2019-02-10T13:38:14.449Z',
           account: {
             name: 'root',
-            host: 'localhost:' + servers[0].port
+            host: servers[0].host
           },
           isLocal,
           publishedAt,
@@ -134,7 +134,7 @@ describe('Test multiple servers', function () {
         expect(data.length).to.equal(1)
         const video = data[0]
 
-        await completeVideoCheck(server, video, checkAttributes)
+        await completeVideoCheck({ server, originServer: servers[0], videoUUID: video.uuid, attributes: checkAttributes })
         publishedAt = video.publishedAt as string
 
         expect(video.channel.avatars).to.have.lengthOf(2)
@@ -156,7 +156,7 @@ describe('Test multiple servers', function () {
     })
 
     it('Should upload the video on server 2 and propagate on each server', async function () {
-      this.timeout(100000)
+      this.timeout(240000)
 
       const user = {
         username: 'user1',
@@ -185,7 +185,7 @@ describe('Test multiple servers', function () {
 
       // All servers should have this video
       for (const server of servers) {
-        const isLocal = server.url === 'http://localhost:' + servers[1].port
+        const isLocal = server.url === servers[1].url
         const checkAttributes = {
           name: 'my super name for server 2',
           category: 4,
@@ -196,7 +196,7 @@ describe('Test multiple servers', function () {
           support: 'my super support text for server 2',
           account: {
             name: 'user1',
-            host: 'localhost:' + servers[1].port
+            host: servers[1].host
           },
           isLocal,
           commentsEnabled: true,
@@ -238,7 +238,7 @@ describe('Test multiple servers', function () {
         expect(data.length).to.equal(2)
         const video = data[1]
 
-        await completeVideoCheck(server, video, checkAttributes)
+        await completeVideoCheck({ server, originServer: servers[1], videoUUID: video.uuid, attributes: checkAttributes })
       }
     })
 
@@ -279,7 +279,7 @@ describe('Test multiple servers', function () {
 
       // All servers should have this video
       for (const server of servers) {
-        const isLocal = server.url === 'http://localhost:' + servers[2].port
+        const isLocal = server.url === servers[2].url
         const { data } = await server.videos.list()
 
         expect(data).to.be.an('array')
@@ -306,7 +306,7 @@ describe('Test multiple servers', function () {
           support: 'my super support text for server 3',
           account: {
             name: 'root',
-            host: 'localhost:' + servers[2].port
+            host: servers[2].host
           },
           isLocal,
           duration: 5,
@@ -328,7 +328,7 @@ describe('Test multiple servers', function () {
             }
           ]
         }
-        await completeVideoCheck(server, video1, checkAttributesVideo1)
+        await completeVideoCheck({ server, originServer: servers[2], videoUUID: video1.uuid, attributes: checkAttributesVideo1 })
 
         const checkAttributesVideo2 = {
           name: 'my super name for server 3-2',
@@ -340,7 +340,7 @@ describe('Test multiple servers', function () {
           support: 'my super support text for server 3-2',
           account: {
             name: 'root',
-            host: 'localhost:' + servers[2].port
+            host: servers[2].host
           },
           commentsEnabled: true,
           downloadEnabled: true,
@@ -362,7 +362,7 @@ describe('Test multiple servers', function () {
             }
           ]
         }
-        await completeVideoCheck(server, video2, checkAttributesVideo2)
+        await completeVideoCheck({ server, originServer: servers[2], videoUUID: video2.uuid, attributes: checkAttributesVideo2 })
       }
     })
   })
@@ -398,7 +398,9 @@ describe('Test multiple servers', function () {
   })
 
   describe('Should seed the uploaded video', function () {
+
     it('Should add the file 1 by asking server 3', async function () {
+      this.retries(2)
       this.timeout(30000)
 
       const { data } = await servers[2].videos.list()
@@ -408,13 +410,12 @@ describe('Test multiple servers', function () {
       toRemove.push(data[3])
 
       const videoDetails = await servers[2].videos.get({ id: video.id })
-      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('')
+
+      await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
     })
 
     it('Should add the file 2 by asking server 1', async function () {
+      this.retries(2)
       this.timeout(30000)
 
       const { data } = await servers[0].videos.list()
@@ -422,13 +423,11 @@ describe('Test multiple servers', function () {
       const video = data[1]
       const videoDetails = await servers[0].videos.get({ id: video.id })
 
-      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('')
+      await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
     })
 
     it('Should add the file 3 by asking server 2', async function () {
+      this.retries(2)
       this.timeout(30000)
 
       const { data } = await servers[1].videos.list()
@@ -436,13 +435,11 @@ describe('Test multiple servers', function () {
       const video = data[2]
       const videoDetails = await servers[1].videos.get({ id: video.id })
 
-      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('')
+      await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
     })
 
     it('Should add the file 3-2 by asking server 1', async function () {
+      this.retries(2)
       this.timeout(30000)
 
       const { data } = await servers[0].videos.list()
@@ -450,13 +447,11 @@ describe('Test multiple servers', function () {
       const video = data[3]
       const videoDetails = await servers[0].videos.get({ id: video.id })
 
-      const torrent = await webtorrentAdd(videoDetails.files[0].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('')
+      await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
     })
 
     it('Should add the file 2 in 360p by asking server 1', async function () {
+      this.retries(2)
       this.timeout(30000)
 
       const { data } = await servers[0].videos.list()
@@ -467,10 +462,7 @@ describe('Test multiple servers', function () {
       const file = videoDetails.files.find(f => f.resolution.id === 360)
       expect(file).not.to.be.undefined
 
-      const torrent = await webtorrentAdd(file.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('')
+      await checkWebTorrentWorks(file.magnetUri)
     })
   })
 
@@ -649,7 +641,7 @@ describe('Test multiple servers', function () {
 
         expect(new Date(videoUpdated.updatedAt)).to.be.greaterThan(updatedAtMin)
 
-        const isLocal = server.url === 'http://localhost:' + servers[2].port
+        const isLocal = server.url === servers[2].url
         const checkAttributes = {
           name: 'my super video updated',
           category: 10,
@@ -661,7 +653,7 @@ describe('Test multiple servers', function () {
           originallyPublishedAt: '2019-02-11T13:38:14.449Z',
           account: {
             name: 'root',
-            host: 'localhost:' + servers[2].port
+            host: servers[2].host
           },
           isLocal,
           duration: 5,
@@ -685,7 +677,7 @@ describe('Test multiple servers', function () {
           thumbnailfile: 'thumbnail',
           previewfile: 'preview'
         }
-        await completeVideoCheck(server, videoUpdated, checkAttributes)
+        await completeVideoCheck({ server, originServer: servers[2], videoUUID: videoUpdated.uuid, attributes: checkAttributes })
       }
     })
 
@@ -830,7 +822,7 @@ describe('Test multiple servers', function () {
           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:' + servers[0].port)
+          expect(comment.account.host).to.equal(servers[0].host)
           expect(comment.totalReplies).to.equal(3)
           expect(dateIsValid(comment.createdAt as string)).to.be.true
           expect(dateIsValid(comment.updatedAt as string)).to.be.true
@@ -841,7 +833,7 @@ describe('Test multiple servers', function () {
           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:' + servers[2].port)
+          expect(comment.account.host).to.equal(servers[2].host)
           expect(comment.totalReplies).to.equal(0)
           expect(dateIsValid(comment.createdAt as string)).to.be.true
           expect(dateIsValid(comment.updatedAt as string)).to.be.true
@@ -858,25 +850,25 @@ describe('Test multiple servers', function () {
 
         expect(tree.comment.text).equal('my super first comment')
         expect(tree.comment.account.name).equal('root')
-        expect(tree.comment.account.host).equal('localhost:' + servers[0].port)
+        expect(tree.comment.account.host).equal(servers[0].host)
         expect(tree.children).to.have.lengthOf(2)
 
         const firstChild = tree.children[0]
         expect(firstChild.comment.text).to.equal('my super answer to thread 1')
         expect(firstChild.comment.account.name).equal('root')
-        expect(firstChild.comment.account.host).equal('localhost:' + servers[1].port)
+        expect(firstChild.comment.account.host).equal(servers[1].host)
         expect(firstChild.children).to.have.lengthOf(1)
 
         childOfFirstChild = firstChild.children[0]
         expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
         expect(childOfFirstChild.comment.account.name).equal('root')
-        expect(childOfFirstChild.comment.account.host).equal('localhost:' + servers[2].port)
+        expect(childOfFirstChild.comment.account.host).equal(servers[2].host)
         expect(childOfFirstChild.children).to.have.lengthOf(0)
 
         const secondChild = tree.children[1]
         expect(secondChild.comment.text).to.equal('my second answer to thread 1')
         expect(secondChild.comment.account.name).equal('root')
-        expect(secondChild.comment.account.host).equal('localhost:' + servers[2].port)
+        expect(secondChild.comment.account.host).equal(servers[2].host)
         expect(secondChild.children).to.have.lengthOf(0)
       }
     })
@@ -935,7 +927,7 @@ describe('Test multiple servers', function () {
           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:' + servers[2].port)
+          expect(comment.account.host).to.equal(servers[2].host)
           expect(comment.totalReplies).to.equal(0)
           expect(dateIsValid(comment.createdAt as string)).to.be.true
           expect(dateIsValid(comment.updatedAt as string)).to.be.true
@@ -1042,7 +1034,7 @@ describe('Test multiple servers', function () {
         const { data } = await server.videos.list()
         const video = data.find(v => v.name === 'minimum parameters')
 
-        const isLocal = server.url === 'http://localhost:' + servers[1].port
+        const isLocal = server.url === servers[1].url
         const checkAttributes = {
           name: 'minimum parameters',
           category: null,
@@ -1053,7 +1045,7 @@ describe('Test multiple servers', function () {
           support: null,
           account: {
             name: 'root',
-            host: 'localhost:' + servers[1].port
+            host: servers[1].host
           },
           isLocal,
           duration: 5,
@@ -1087,7 +1079,7 @@ describe('Test multiple servers', function () {
             }
           ]
         }
-        await completeVideoCheck(server, video, checkAttributes)
+        await completeVideoCheck({ server, originServer: servers[1], videoUUID: video.uuid, attributes: checkAttributes })
       }
     })
   })