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