]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/multiple-servers.ts
Fix getting avatars in videos list
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / multiple-servers.ts
index 562079a154d78fddf21f65a77ae9a7bed106bc4d..2a49fd360c31b09e51e63d87d8409a007fdd657f 100644 (file)
@@ -2,25 +2,30 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import * as request from 'supertest'
-import { HttpStatusCode } from '@shared/core-utils'
+import { and } from 'sequelize/dist'
+import request from 'supertest'
 import {
-  buildAbsoluteFixturePath,
   checkTmpIsEmpty,
   checkVideoFilesWereRemoved,
-  cleanupTests,
   completeVideoCheck,
   dateIsValid,
-  doubleFollow,
+  saveVideoInServers,
+  testImage
+} from '@server/tests/shared'
+import { buildAbsoluteFixturePath, wait } from '@shared/core-utils'
+import { HttpStatusCode, VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
+import {
+  cleanupTests,
   createMultipleServers,
+  doubleFollow,
+  makeGetRequest,
   PeerTubeServer,
   setAccessTokensToServers,
-  testImage,
-  wait,
+  setDefaultAccountAvatar,
+  setDefaultChannelAvatar,
   waitJobs,
   webtorrentAdd
-} from '@shared/extra-utils'
-import { VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
+} from '@shared/server-commands'
 
 const expect = chai.expect
 
@@ -45,6 +50,9 @@ describe('Test multiple servers', function () {
         description: 'super channel'
       }
       await servers[0].channels.create({ attributes: videoChannel })
+      await setDefaultChannelAvatar(servers[0], videoChannel.name)
+      await setDefaultAccountAvatar(servers)
+
       const { data } = await servers[0].channels.list({ start: 0, count: 1 })
       videoChannelId = data[0].id
     }
@@ -132,6 +140,22 @@ describe('Test multiple servers', function () {
 
         await completeVideoCheck(server, video, checkAttributes)
         publishedAt = video.publishedAt as string
+
+        expect(video.channel.avatars).to.have.lengthOf(2)
+        expect(video.account.avatars).to.have.lengthOf(2)
+
+        for (const image of [ ...video.channel.avatars, ...video.account.avatars ]) {
+          expect(image.createdAt).to.exist
+          expect(image.updatedAt).to.exist
+          expect(image.width).to.be.above(20).and.below(1000)
+          expect(image.path).to.exist
+
+          await makeGetRequest({
+            url: server.url,
+            path: image.path,
+            expectedStatus: HttpStatusCode.OK_200
+          })
+        }
       }
     })
 
@@ -206,7 +230,7 @@ describe('Test multiple servers', function () {
             },
             {
               resolution: 720,
-              size: 788000
+              size: 750000
             }
           ],
           thumbnailfile: 'thumbnail',
@@ -349,7 +373,7 @@ describe('Test multiple servers', function () {
 
   describe('It should list local videos', function () {
     it('Should list only local videos on server 1', async function () {
-      const { data, total } = await servers[0].videos.list({ filter: 'local' })
+      const { data, total } = await servers[0].videos.list({ isLocal: true })
 
       expect(total).to.equal(1)
       expect(data).to.be.an('array')
@@ -358,7 +382,7 @@ describe('Test multiple servers', function () {
     })
 
     it('Should list only local videos on server 2', async function () {
-      const { data, total } = await servers[1].videos.list({ filter: 'local' })
+      const { data, total } = await servers[1].videos.list({ isLocal: true })
 
       expect(total).to.equal(1)
       expect(data).to.be.an('array')
@@ -367,7 +391,7 @@ describe('Test multiple servers', function () {
     })
 
     it('Should list only local videos on server 3', async function () {
-      const { data, total } = await servers[2].videos.list({ filter: 'local' })
+      const { data, total } = await servers[2].videos.list({ isLocal: true })
 
       expect(total).to.equal(2)
       expect(data).to.be.an('array')
@@ -379,7 +403,7 @@ 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.timeout(10000)
+      this.timeout(30000)
 
       const { data } = await servers[2].videos.list()
 
@@ -395,7 +419,7 @@ describe('Test multiple servers', function () {
     })
 
     it('Should add the file 2 by asking server 1', async function () {
-      this.timeout(10000)
+      this.timeout(30000)
 
       const { data } = await servers[0].videos.list()
 
@@ -409,7 +433,7 @@ describe('Test multiple servers', function () {
     })
 
     it('Should add the file 3 by asking server 2', async function () {
-      this.timeout(10000)
+      this.timeout(30000)
 
       const { data } = await servers[1].videos.list()
 
@@ -423,7 +447,7 @@ describe('Test multiple servers', function () {
     })
 
     it('Should add the file 3-2 by asking server 1', async function () {
-      this.timeout(10000)
+      this.timeout(30000)
 
       const { data } = await servers[0].videos.list()
 
@@ -437,7 +461,7 @@ describe('Test multiple servers', function () {
     })
 
     it('Should add the file 2 in 360p by asking server 1', async function () {
-      this.timeout(10000)
+      this.timeout(30000)
 
       const { data } = await servers[0].videos.list()
 
@@ -591,8 +615,10 @@ describe('Test multiple servers', function () {
   })
 
   describe('Should manipulate these videos', function () {
-    it('Should update the video 3 by asking server 3', async function () {
-      this.timeout(10000)
+    let updatedAtMin: Date
+
+    it('Should update video 3', async function () {
+      this.timeout(30000)
 
       const attributes = {
         name: 'my super video updated',
@@ -608,13 +634,14 @@ describe('Test multiple servers', function () {
         previewfile: 'preview.jpg'
       }
 
+      updatedAtMin = new Date()
       await servers[2].videos.update({ id: toRemove[0].id, attributes })
 
       await waitJobs(servers)
     })
 
     it('Should have the video 3 updated on each server', async function () {
-      this.timeout(10000)
+      this.timeout(30000)
 
       for (const server of servers) {
         const { data } = await server.videos.list()
@@ -622,6 +649,8 @@ describe('Test multiple servers', function () {
         const videoUpdated = data.find(video => video.name === 'my super video updated')
         expect(!!videoUpdated).to.be.true
 
+        expect(new Date(videoUpdated.updatedAt)).to.be.greaterThan(updatedAtMin)
+
         const isLocal = server.url === 'http://localhost:' + servers[2].port
         const checkAttributes = {
           name: 'my super video updated',
@@ -662,19 +691,39 @@ describe('Test multiple servers', function () {
       }
     })
 
-    it('Should remove the videos 3 and 3-2 by asking server 3', async function () {
-      this.timeout(10000)
+    it('Should only update thumbnail and update updatedAt attribute', async function () {
+      this.timeout(30000)
 
-      await servers[2].videos.remove({ id: toRemove[0].id })
-      await servers[2].videos.remove({ id: toRemove[1].id })
+      const attributes = {
+        thumbnailfile: 'thumbnail.jpg'
+      }
+
+      updatedAtMin = new Date()
+      await servers[2].videos.update({ id: toRemove[0].id, attributes })
 
       await waitJobs(servers)
-    })
 
-    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)
-        await checkVideoFilesWereRemoved(toRemove[1].uuid, server)
+        const { data } = await server.videos.list()
+
+        const videoUpdated = data.find(video => video.name === 'my super video updated')
+        expect(new Date(videoUpdated.updatedAt)).to.be.greaterThan(updatedAtMin)
+      }
+    })
+
+    it('Should remove the videos 3 and 3-2 by asking server 3 and correctly delete files', async function () {
+      this.timeout(30000)
+
+      for (const id of [ toRemove[0].id, toRemove[1].id ]) {
+        await saveVideoInServers(servers, id)
+
+        await servers[2].videos.remove({ id })
+
+        await waitJobs(servers)
+
+        for (const server of servers) {
+          await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
+        }
       }
     })
 
@@ -835,7 +884,7 @@ describe('Test multiple servers', function () {
     })
 
     it('Should delete a reply', async function () {
-      this.timeout(10000)
+      this.timeout(30000)
 
       await servers[2].comments.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id })
 
@@ -866,7 +915,7 @@ describe('Test multiple servers', function () {
     })
 
     it('Should delete the thread comments', async function () {
-      this.timeout(10000)
+      this.timeout(30000)
 
       const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
       const commentId = data.find(c => c.text === 'my super first comment').id
@@ -1024,15 +1073,15 @@ describe('Test multiple servers', function () {
           files: [
             {
               resolution: 720,
-              size: 59000
+              size: 61000
             },
             {
               resolution: 480,
-              size: 34000
+              size: 40000
             },
             {
               resolution: 360,
-              size: 31000
+              size: 32000
             },
             {
               resolution: 240,