Upgrade server dep'
[oweals/peertube.git] / server / tests / api / multiple-servers.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4 import * as chai from 'chai'
5
6 import {
7   dateIsValid,
8   flushAndRunMultipleServers,
9   flushTests,
10   getVideo,
11   getVideosList,
12   killallServers,
13   rateVideo,
14   removeVideo,
15   ServerInfo,
16   setAccessTokensToServers,
17   testVideoImage,
18   updateVideo,
19   uploadVideo,
20   wait,
21   webtorrentAdd,
22   addVideoChannel,
23   getVideoChannelsList,
24   getUserAccessToken,
25   doubleFollow
26 } from '../utils'
27 import { createUser } from '../utils/users'
28
29 const expect = chai.expect
30
31 describe('Test multiple servers', function () {
32   let servers: ServerInfo[] = []
33   const toRemove = []
34   let videoUUID = ''
35   let videoChannelId: number
36
37   before(async function () {
38     this.timeout(120000)
39
40     servers = await flushAndRunMultipleServers(3)
41
42     // Get the access tokens
43     await setAccessTokensToServers(servers)
44
45     const videoChannel = {
46       name: 'my channel',
47       description: 'super channel'
48     }
49     await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
50     const channelRes = await getVideoChannelsList(servers[0].url, 0, 1)
51     videoChannelId = channelRes.body.data[0].id
52
53     // Server 1 and server 2 follow each other
54     await doubleFollow(servers[0], servers[1])
55     // Server 1 and server 3 follow each other
56     await doubleFollow(servers[0], servers[2])
57     // Server 2 and server 3 follow each other
58     await doubleFollow(servers[1], servers[2])
59   })
60
61   it('Should not have videos for all servers', async function () {
62     for (const server of servers) {
63       const res = await getVideosList(server.url)
64       const videos = res.body.data
65       expect(videos).to.be.an('array')
66       expect(videos.length).to.equal(0)
67     }
68   })
69
70   describe('Should upload the video and propagate on each server', function () {
71     it('Should upload the video on server 1 and propagate on each server', async function () {
72       this.timeout(25000)
73
74       const videoAttributes = {
75         name: 'my super name for server 1',
76         category: 5,
77         licence: 4,
78         language: 9,
79         nsfw: true,
80         description: 'my super description for server 1',
81         tags: [ 'tag1p1', 'tag2p1' ],
82         channelId: videoChannelId,
83         fixture: 'video_short1.webm'
84       }
85       await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
86
87       await wait(10000)
88
89       // All servers should have this video
90       for (const server of servers) {
91         let baseMagnet = null
92
93         const res = await getVideosList(server.url)
94
95         const videos = res.body.data
96         expect(videos).to.be.an('array')
97         expect(videos.length).to.equal(1)
98         const video = videos[0]
99         expect(video.name).to.equal('my super name for server 1')
100         expect(video.category).to.equal(5)
101         expect(video.categoryLabel).to.equal('Sports')
102         expect(video.licence).to.equal(4)
103         expect(video.licenceLabel).to.equal('Attribution - Non Commercial')
104         expect(video.language).to.equal(9)
105         expect(video.languageLabel).to.equal('Japanese')
106         expect(video.nsfw).to.be.ok
107         expect(video.description).to.equal('my super description for server 1')
108         expect(video.serverHost).to.equal('localhost:9001')
109         expect(video.duration).to.equal(10)
110         expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
111         expect(dateIsValid(video.createdAt)).to.be.true
112         expect(dateIsValid(video.updatedAt)).to.be.true
113         expect(video.account).to.equal('root')
114
115         const res2 = await getVideo(server.url, video.uuid)
116         const videoDetails = res2.body
117
118         expect(videoDetails.channel.name).to.equal('my channel')
119         expect(videoDetails.channel.description).to.equal('super channel')
120         expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true
121         expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true
122         expect(videoDetails.files).to.have.lengthOf(1)
123
124         const file = videoDetails.files[0]
125         const magnetUri = file.magnetUri
126         expect(file.magnetUri).to.have.lengthOf.above(2)
127         expect(file.torrentUrl).to
128           .equal(`http://${videoDetails.serverHost}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
129         expect(file.fileUrl).to.equal(`http://${videoDetails.serverHost}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)
130         expect(file.resolution).to.equal(720)
131         expect(file.resolutionLabel).to.equal('720p')
132         expect(file.size).to.equal(572456)
133
134         if (server.url !== 'http://localhost:9001') {
135           expect(video.isLocal).to.be.false
136           expect(videoDetails.channel.isLocal).to.be.false
137         } else {
138           expect(video.isLocal).to.be.true
139           expect(videoDetails.channel.isLocal).to.be.true
140         }
141
142         // All servers should have the same magnet Uri
143         if (baseMagnet === null) {
144           baseMagnet = magnetUri
145         } else {
146           expect(baseMagnet).to.equal(magnetUri)
147         }
148
149         const test = await testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath)
150         expect(test).to.equal(true)
151       }
152     })
153
154     it('Should upload the video on server 2 and propagate on each server', async function () {
155       this.timeout(50000)
156
157       const user = {
158         username: 'user1',
159         password: 'super_password'
160       }
161       await createUser(servers[1].url, servers[1].accessToken, user.username, user.password)
162       const userAccessToken = await getUserAccessToken(servers[1], user)
163
164       const videoAttributes = {
165         name: 'my super name for server 2',
166         category: 4,
167         licence: 3,
168         language: 11,
169         nsfw: true,
170         description: 'my super description for server 2',
171         tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
172         fixture: 'video_short2.webm'
173       }
174       await uploadVideo(servers[1].url, userAccessToken, videoAttributes)
175
176       // Transcoding
177       await wait(30000)
178
179       // All servers should have this video
180       for (const server of servers) {
181         let baseMagnet = {}
182
183         const res = await getVideosList(server.url)
184
185         const videos = res.body.data
186         expect(videos).to.be.an('array')
187         expect(videos.length).to.equal(2)
188         const video = videos[1]
189         expect(video.name).to.equal('my super name for server 2')
190         expect(video.category).to.equal(4)
191         expect(video.categoryLabel).to.equal('Art')
192         expect(video.licence).to.equal(3)
193         expect(video.licenceLabel).to.equal('Attribution - No Derivatives')
194         expect(video.language).to.equal(11)
195         expect(video.languageLabel).to.equal('German')
196         expect(video.nsfw).to.be.true
197         expect(video.description).to.equal('my super description for server 2')
198         expect(video.serverHost).to.equal('localhost:9002')
199         expect(video.duration).to.equal(5)
200         expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
201         expect(dateIsValid(video.createdAt)).to.be.true
202         expect(dateIsValid(video.updatedAt)).to.be.true
203         expect(video.account).to.equal('user1')
204
205         if (server.url !== 'http://localhost:9002') {
206           expect(video.isLocal).to.be.false
207         } else {
208           expect(video.isLocal).to.be.true
209         }
210
211         const res2 = await getVideo(server.url, video.uuid)
212         const videoDetails = res2.body
213
214         expect(videoDetails.channel.name).to.equal('Default user1 channel')
215         expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true
216         expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true
217
218         expect(videoDetails.files).to.have.lengthOf(4)
219
220         // Check common attributes
221         for (const file of videoDetails.files) {
222           expect(file.magnetUri).to.have.lengthOf.above(2)
223
224           // All servers should have the same magnet Uri
225           if (baseMagnet[file.resolution] === undefined) {
226             baseMagnet[file.resolution] = file.magnet
227           } else {
228             expect(baseMagnet[file.resolution]).to.equal(file.magnet)
229           }
230         }
231
232         const file240p = videoDetails.files.find(f => f.resolution === 240)
233         expect(file240p).not.to.be.undefined
234         expect(file240p.resolutionLabel).to.equal('240p')
235         expect(file240p.size).to.be.above(180000).and.below(200000)
236
237         const file360p = videoDetails.files.find(f => f.resolution === 360)
238         expect(file360p).not.to.be.undefined
239         expect(file360p.resolutionLabel).to.equal('360p')
240         expect(file360p.size).to.be.above(270000).and.below(290000)
241
242         const file480p = videoDetails.files.find(f => f.resolution === 480)
243         expect(file480p).not.to.be.undefined
244         expect(file480p.resolutionLabel).to.equal('480p')
245         expect(file480p.size).to.be.above(380000).and.below(400000)
246
247         const file720p = videoDetails.files.find(f => f.resolution === 720)
248         expect(file720p).not.to.be.undefined
249         expect(file720p.resolutionLabel).to.equal('720p')
250         expect(file720p.size).to.be.above(700000).and.below(7200000)
251
252         const test = await testVideoImage(server.url, 'video_short2.webm', videoDetails.thumbnailPath)
253         expect(test).to.equal(true)
254       }
255     })
256
257     it('Should upload two videos on server 3 and propagate on each server', async function () {
258       this.timeout(45000)
259
260       const videoAttributes1 = {
261         name: 'my super name for server 3',
262         category: 6,
263         licence: 5,
264         language: 11,
265         nsfw: true,
266         description: 'my super description for server 3',
267         tags: [ 'tag1p3' ],
268         fixture: 'video_short3.webm'
269       }
270       await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1)
271
272       const videoAttributes2 = {
273         name: 'my super name for server 3-2',
274         category: 7,
275         licence: 6,
276         language: 12,
277         nsfw: false,
278         description: 'my super description for server 3-2',
279         tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
280         fixture: 'video_short.webm'
281       }
282       await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2)
283
284       await wait(10000)
285
286       let baseMagnet = null
287       // All servers should have this video
288       for (const server of servers) {
289         const res = await getVideosList(server.url)
290
291         const videos = res.body.data
292         expect(videos).to.be.an('array')
293         expect(videos.length).to.equal(4)
294
295         // We not sure about the order of the two last uploads
296         let video1 = null
297         let video2 = null
298         if (videos[2].name === 'my super name for server 3') {
299           video1 = videos[2]
300           video2 = videos[3]
301         } else {
302           video1 = videos[3]
303           video2 = videos[2]
304         }
305
306         expect(video1.name).to.equal('my super name for server 3')
307         expect(video1.category).to.equal(6)
308         expect(video1.categoryLabel).to.equal('Travels')
309         expect(video1.licence).to.equal(5)
310         expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike')
311         expect(video1.language).to.equal(11)
312         expect(video1.languageLabel).to.equal('German')
313         expect(video1.nsfw).to.be.ok
314         expect(video1.description).to.equal('my super description for server 3')
315         expect(video1.serverHost).to.equal('localhost:9003')
316         expect(video1.duration).to.equal(5)
317         expect(video1.tags).to.deep.equal([ 'tag1p3' ])
318         expect(video1.account).to.equal('root')
319         expect(dateIsValid(video1.createdAt)).to.be.true
320         expect(dateIsValid(video1.updatedAt)).to.be.true
321
322         const res2 = await getVideo(server.url, video1.id)
323         const video1Details = res2.body
324         expect(video1Details.files).to.have.lengthOf(1)
325
326         const file1 = video1Details.files[0]
327         expect(file1.magnetUri).to.have.lengthOf.above(2)
328         expect(file1.resolution).to.equal(720)
329         expect(file1.resolutionLabel).to.equal('720p')
330         expect(file1.size).to.equal(292677)
331
332         expect(video2.name).to.equal('my super name for server 3-2')
333         expect(video2.category).to.equal(7)
334         expect(video2.categoryLabel).to.equal('Gaming')
335         expect(video2.licence).to.equal(6)
336         expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
337         expect(video2.language).to.equal(12)
338         expect(video2.languageLabel).to.equal('Korean')
339         expect(video2.nsfw).to.be.false
340         expect(video2.description).to.equal('my super description for server 3-2')
341         expect(video2.serverHost).to.equal('localhost:9003')
342         expect(video2.duration).to.equal(5)
343         expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
344         expect(video2.account).to.equal('root')
345         expect(dateIsValid(video2.createdAt)).to.be.true
346         expect(dateIsValid(video2.updatedAt)).to.be.true
347
348         const res3 = await getVideo(server.url, video2.id)
349         const video2Details = res3.body
350
351         expect(video2Details.files).to.have.lengthOf(1)
352
353         const file2 = video2Details.files[0]
354         const magnetUri2 = file2.magnetUri
355         expect(file2.magnetUri).to.have.lengthOf.above(2)
356         expect(file2.resolution).to.equal(720)
357         expect(file2.resolutionLabel).to.equal('720p')
358         expect(file2.size).to.equal(218910)
359
360         if (server.url !== 'http://localhost:9003') {
361           expect(video1.isLocal).to.be.false
362           expect(video2.isLocal).to.be.false
363         } else {
364           expect(video1.isLocal).to.be.true
365           expect(video2.isLocal).to.be.true
366         }
367
368         // All servers should have the same magnet Uri
369         if (baseMagnet === null) {
370           baseMagnet = magnetUri2
371         } else {
372           expect(baseMagnet).to.equal(magnetUri2)
373         }
374
375         const test1 = await testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath)
376         expect(test1).to.equal(true)
377
378         const test2 = await testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath)
379         expect(test2).to.equal(true)
380       }
381     })
382   })
383
384   describe('Should seed the uploaded video', function () {
385     it('Should add the file 1 by asking server 3', async function () {
386       this.timeout(10000)
387
388       const res = await getVideosList(servers[2].url)
389
390       const video = res.body.data[0]
391       toRemove.push(res.body.data[2])
392       toRemove.push(res.body.data[3])
393
394       const res2 = await getVideo(servers[2].url, video.id)
395       const videoDetails = res2.body
396
397       const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
398       expect(torrent.files).to.be.an('array')
399       expect(torrent.files.length).to.equal(1)
400       expect(torrent.files[0].path).to.exist.and.to.not.equal('')
401     })
402
403     it('Should add the file 2 by asking server 1', async function () {
404       this.timeout(10000)
405
406       const res = await getVideosList(servers[0].url)
407
408       const video = res.body.data[1]
409       const res2 = await getVideo(servers[0].url, video.id)
410       const videoDetails = res2.body
411
412       const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
413       expect(torrent.files).to.be.an('array')
414       expect(torrent.files.length).to.equal(1)
415       expect(torrent.files[0].path).to.exist.and.to.not.equal('')
416     })
417
418     it('Should add the file 3 by asking server 2', async function () {
419       this.timeout(10000)
420
421       const res = await getVideosList(servers[1].url)
422
423       const video = res.body.data[2]
424       const res2 = await getVideo(servers[1].url, video.id)
425       const videoDetails = res2.body
426
427       const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
428       expect(torrent.files).to.be.an('array')
429       expect(torrent.files.length).to.equal(1)
430       expect(torrent.files[0].path).to.exist.and.to.not.equal('')
431     })
432
433     it('Should add the file 3-2 by asking server 1', async function () {
434       this.timeout(10000)
435
436       const res = await getVideosList(servers[0].url)
437
438       const video = res.body.data[3]
439       const res2 = await getVideo(servers[0].url, video.id)
440       const videoDetails = res2.body
441
442       const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
443       expect(torrent.files).to.be.an('array')
444       expect(torrent.files.length).to.equal(1)
445       expect(torrent.files[0].path).to.exist.and.to.not.equal('')
446     })
447
448     it('Should add the file 2 in 360p by asking server 1', async function () {
449       this.timeout(10000)
450
451       const res = await getVideosList(servers[0].url)
452
453       const video = res.body.data.find(v => v.name === 'my super name for server 2')
454       const res2 = await getVideo(servers[0].url, video.id)
455       const videoDetails = res2.body
456
457       const file = videoDetails.files.find(f => f.resolution === 360)
458       expect(file).not.to.be.undefined
459
460       const torrent = await webtorrentAdd(file.magnetUri)
461       expect(torrent.files).to.be.an('array')
462       expect(torrent.files.length).to.equal(1)
463       expect(torrent.files[0].path).to.exist.and.to.not.equal('')
464     })
465   })
466
467   describe('Should update video views, likes and dislikes', function () {
468     let localVideosServer3 = []
469     let remoteVideosServer1 = []
470     let remoteVideosServer2 = []
471     let remoteVideosServer3 = []
472
473     before(async function () {
474       const res1 = await getVideosList(servers[0].url)
475       remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
476
477       const res2 = await getVideosList(servers[1].url)
478       remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
479
480       const res3 = await getVideosList(servers[2].url)
481       localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid)
482       remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
483     })
484
485     it('Should view multiple videos on owned servers', async function () {
486       this.timeout(10000)
487
488       const tasks: Promise<any>[] = []
489       tasks.push(getVideo(servers[2].url, localVideosServer3[0]))
490       tasks.push(getVideo(servers[2].url, localVideosServer3[0]))
491       tasks.push(getVideo(servers[2].url, localVideosServer3[0]))
492       tasks.push(getVideo(servers[2].url, localVideosServer3[1]))
493
494       await Promise.all(tasks)
495
496       await wait(5000)
497
498       for (const server of servers) {
499         const res = await getVideosList(server.url)
500
501         const videos = res.body.data
502         const video0 = videos.find(v => v.uuid === localVideosServer3[0])
503         const video1 = videos.find(v => v.uuid === localVideosServer3[1])
504
505         expect(video0.views).to.equal(7)
506         expect(video1.views).to.equal(5)
507       }
508     })
509
510     it('Should view multiple videos on each servers', async function () {
511       this.timeout(15000)
512
513       const tasks: Promise<any>[] = []
514       tasks.push(getVideo(servers[0].url, remoteVideosServer1[0]))
515       tasks.push(getVideo(servers[1].url, remoteVideosServer2[0]))
516       tasks.push(getVideo(servers[1].url, remoteVideosServer2[0]))
517       tasks.push(getVideo(servers[2].url, remoteVideosServer3[0]))
518       tasks.push(getVideo(servers[2].url, remoteVideosServer3[1]))
519       tasks.push(getVideo(servers[2].url, remoteVideosServer3[1]))
520       tasks.push(getVideo(servers[2].url, remoteVideosServer3[1]))
521       tasks.push(getVideo(servers[2].url, localVideosServer3[1]))
522       tasks.push(getVideo(servers[2].url, localVideosServer3[1]))
523       tasks.push(getVideo(servers[2].url, localVideosServer3[1]))
524
525       await Promise.all(tasks)
526
527       await wait(10000)
528
529       let baseVideos = null
530
531       for (const server of servers) {
532         const res = await getVideosList(server.url)
533
534         const videos = res.body.data
535
536         // Initialize base videos for future comparisons
537         if (baseVideos === null) {
538           baseVideos = videos
539           continue
540         }
541
542         for (const baseVideo of baseVideos) {
543           const sameVideo = videos.find(video => video.name === baseVideo.name)
544           expect(baseVideo.views).to.equal(sameVideo.views)
545         }
546       }
547     })
548
549     it('Should like and dislikes videos on different services', async function () {
550       this.timeout(20000)
551
552       const tasks: Promise<any>[] = []
553       tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like'))
554       tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike'))
555       tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like'))
556       tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like'))
557       tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike'))
558       tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike'))
559       tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like'))
560
561       await Promise.all(tasks)
562
563       await wait(10000)
564
565       let baseVideos = null
566       for (const server of servers) {
567         const res = await getVideosList(server.url)
568
569         const videos = res.body.data
570
571         // Initialize base videos for future comparisons
572         if (baseVideos === null) {
573           baseVideos = videos
574           continue
575         }
576
577         for (const baseVideo of baseVideos) {
578           const sameVideo = videos.find(video => video.name === baseVideo.name)
579           expect(baseVideo.likes).to.equal(sameVideo.likes)
580           expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
581         }
582       }
583     })
584   })
585
586   describe('Should manipulate these videos', function () {
587     it('Should update the video 3 by asking server 3', async function () {
588       this.timeout(10000)
589
590       const attributes = {
591         name: 'my super video updated',
592         category: 10,
593         licence: 7,
594         language: 13,
595         nsfw: true,
596         description: 'my super description updated',
597         tags: [ 'tag_up_1', 'tag_up_2' ]
598       }
599
600       await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes)
601
602       await wait(5000)
603     })
604
605     it('Should have the video 3 updated on each server', async function () {
606       this.timeout(10000)
607
608       for (const server of servers) {
609         const res = await getVideosList(server.url)
610
611         const videos = res.body.data
612         const videoUpdated = videos.find(video => video.name === 'my super video updated')
613
614         expect(!!videoUpdated).to.be.true
615         expect(videoUpdated.category).to.equal(10)
616         expect(videoUpdated.categoryLabel).to.equal('Entertainment')
617         expect(videoUpdated.licence).to.equal(7)
618         expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication')
619         expect(videoUpdated.language).to.equal(13)
620         expect(videoUpdated.languageLabel).to.equal('French')
621         expect(videoUpdated.nsfw).to.be.ok
622         expect(videoUpdated.description).to.equal('my super description updated')
623         expect(videoUpdated.tags).to.deep.equal([ 'tag_up_1', 'tag_up_2' ])
624         expect(dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
625
626         const res2 = await getVideo(server.url, videoUpdated.uuid)
627         const videoUpdatedDetails = res2.body
628
629         const file = videoUpdatedDetails .files[0]
630         expect(file.magnetUri).to.have.lengthOf.above(2)
631         expect(file.resolution).to.equal(720)
632         expect(file.resolutionLabel).to.equal('720p')
633         expect(file.size).to.equal(292677)
634
635         const test = await testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath)
636         expect(test).to.equal(true)
637
638         // Avoid "duplicate torrent" errors
639         const refreshWebTorrent = true
640         const torrent = await webtorrentAdd(videoUpdatedDetails .files[0].magnetUri, refreshWebTorrent)
641         expect(torrent.files).to.be.an('array')
642         expect(torrent.files.length).to.equal(1)
643         expect(torrent.files[0].path).to.exist.and.to.not.equal('')
644       }
645     })
646
647     it('Should remove the videos 3 and 3-2 by asking server 3', async function () {
648       this.timeout(10000)
649
650       await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id)
651       await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id)
652
653       await wait(5000)
654     })
655
656     it('Should have videos 1 and 3 on each server', async function () {
657       for (const server of servers) {
658         const res = await getVideosList(server.url)
659
660         const videos = res.body.data
661         expect(videos).to.be.an('array')
662         expect(videos.length).to.equal(2)
663         expect(videos[0].name).not.to.equal(videos[1].name)
664         expect(videos[0].name).not.to.equal(toRemove[0].name)
665         expect(videos[1].name).not.to.equal(toRemove[0].name)
666         expect(videos[0].name).not.to.equal(toRemove[1].name)
667         expect(videos[1].name).not.to.equal(toRemove[1].name)
668
669         videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid
670       }
671     })
672
673     it('Should get the same video by UUID on each server', async function () {
674       let baseVideo = null
675       for (const server of servers) {
676         const res = await getVideo(server.url, videoUUID)
677
678         const video = res.body
679
680         if (baseVideo === null) {
681           baseVideo = video
682           continue
683         }
684
685         expect(baseVideo.name).to.equal(video.name)
686         expect(baseVideo.uuid).to.equal(video.uuid)
687         expect(baseVideo.category).to.equal(video.category)
688         expect(baseVideo.language).to.equal(video.language)
689         expect(baseVideo.licence).to.equal(video.licence)
690         expect(baseVideo.category).to.equal(video.category)
691         expect(baseVideo.nsfw).to.equal(video.nsfw)
692         expect(baseVideo.account).to.equal(video.account)
693         expect(baseVideo.tags).to.deep.equal(video.tags)
694       }
695     })
696
697     it('Should get the preview from each server', async function () {
698       for (const server of servers) {
699         const res = await getVideo(server.url, videoUUID)
700         const video = res.body
701
702         const test = await testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath)
703         expect(test).to.equal(true)
704       }
705     })
706   })
707
708   after(async function () {
709     killallServers(servers)
710
711     // Keep the logs if the test failed
712     if (this['ok']) {
713       await flushTests()
714     }
715   })
716 })