]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/multiple-pods.js
Move video file metadata in their own table
[github/Chocobozzz/PeerTube.git] / server / tests / api / multiple-pods.js
1 /* eslint-disable no-unused-expressions */
2
3 'use strict'
4
5 const chai = require('chai')
6 const each = require('async/each')
7 const eachSeries = require('async/eachSeries')
8 const expect = chai.expect
9 const parallel = require('async/parallel')
10 const series = require('async/series')
11 const WebTorrent = require('webtorrent')
12 const webtorrent = new WebTorrent()
13
14 const loginUtils = require('../utils/login')
15 const miscsUtils = require('../utils/miscs')
16 const podsUtils = require('../utils/pods')
17 const serversUtils = require('../utils/servers')
18 const videosUtils = require('../utils/videos')
19
20 describe('Test multiple pods', function () {
21 let servers = []
22 const toRemove = []
23 let videoUUID = ''
24
25 before(function (done) {
26 this.timeout(120000)
27
28 series([
29 // Run servers
30 function (next) {
31 serversUtils.flushAndRunMultipleServers(3, function (serversRun) {
32 servers = serversRun
33 next()
34 })
35 },
36 // Get the access tokens
37 function (next) {
38 each(servers, function (server, callbackEach) {
39 loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
40 if (err) return callbackEach(err)
41
42 server.accessToken = accessToken
43 callbackEach()
44 })
45 }, next)
46 },
47 // The second pod make friend with the third
48 function (next) {
49 const server = servers[1]
50 podsUtils.makeFriends(server.url, server.accessToken, next)
51 },
52 // Wait for the request between pods
53 function (next) {
54 setTimeout(next, 10000)
55 },
56 // Pod 1 make friends too
57 function (next) {
58 const server = servers[0]
59 podsUtils.makeFriends(server.url, server.accessToken, next)
60 }
61 ], done)
62 })
63
64 it('Should not have videos for all pods', function (done) {
65 each(servers, function (server, callback) {
66 videosUtils.getVideosList(server.url, function (err, res) {
67 if (err) throw err
68
69 const videos = res.body.data
70 expect(videos).to.be.an('array')
71 expect(videos.length).to.equal(0)
72
73 callback()
74 })
75 }, done)
76 })
77
78 describe('Should upload the video and propagate on each pod', function () {
79 it('Should upload the video on pod 1 and propagate on each pod', function (done) {
80 // Pod 1 has video transcoding activated
81 this.timeout(15000)
82
83 series([
84 function (next) {
85 const videoAttributes = {
86 name: 'my super name for pod 1',
87 category: 5,
88 licence: 4,
89 language: 9,
90 nsfw: true,
91 description: 'my super description for pod 1',
92 tags: [ 'tag1p1', 'tag2p1' ],
93 fixture: 'video_short1.webm'
94 }
95 videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes, next)
96 },
97 function (next) {
98 setTimeout(next, 11000)
99 }],
100 // All pods should have this video
101 function (err) {
102 if (err) throw err
103
104 each(servers, function (server, callback) {
105 let baseMagnet = null
106
107 videosUtils.getVideosList(server.url, function (err, res) {
108 if (err) throw err
109
110 const videos = res.body.data
111 expect(videos).to.be.an('array')
112 expect(videos.length).to.equal(1)
113 const video = videos[0]
114 expect(video.name).to.equal('my super name for pod 1')
115 expect(video.category).to.equal(5)
116 expect(video.categoryLabel).to.equal('Sports')
117 expect(video.licence).to.equal(4)
118 expect(video.licenceLabel).to.equal('Attribution - Non Commercial')
119 expect(video.language).to.equal(9)
120 expect(video.languageLabel).to.equal('Japanese')
121 expect(video.nsfw).to.be.ok
122 expect(video.description).to.equal('my super description for pod 1')
123 expect(video.podHost).to.equal('localhost:9001')
124 expect(video.duration).to.equal(10)
125 expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
126 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
127 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
128 expect(video.author).to.equal('root')
129
130 expect(video.files).to.have.lengthOf(1)
131
132 const file = video.files[0]
133 const magnetUri = file.magnetUri
134 expect(file.magnetUri).to.exist
135 expect(file.resolution).to.equal(0)
136 expect(file.resolutionLabel).to.equal('original')
137 expect(file.size).to.equal(572456)
138
139 if (server.url !== 'http://localhost:9001') {
140 expect(video.isLocal).to.be.false
141 } else {
142 expect(video.isLocal).to.be.true
143 }
144
145 // All pods should have the same magnet Uri
146 if (baseMagnet === null) {
147 baseMagnet = magnetUri
148 } else {
149 expect(baseMagnet).to.equal(magnetUri)
150 }
151
152 videosUtils.testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath, function (err, test) {
153 if (err) throw err
154 expect(test).to.equal(true)
155
156 callback()
157 })
158 })
159 }, done)
160 }
161 )
162 })
163
164 it('Should upload the video on pod 2 and propagate on each pod', function (done) {
165 this.timeout(60000)
166
167 series([
168 function (next) {
169 const videoAttributes = {
170 name: 'my super name for pod 2',
171 category: 4,
172 licence: 3,
173 language: 11,
174 nsfw: true,
175 description: 'my super description for pod 2',
176 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
177 fixture: 'video_short2.webm'
178 }
179 videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next)
180 },
181 function (next) {
182 // Transcoding, so wait more that 22 seconds
183 setTimeout(next, 42000)
184 }],
185 // All pods should have this video
186 function (err) {
187 if (err) throw err
188
189 each(servers, function (server, callback) {
190 let baseMagnet = null
191
192 videosUtils.getVideosList(server.url, function (err, res) {
193 if (err) throw err
194
195 const videos = res.body.data
196 expect(videos).to.be.an('array')
197 expect(videos.length).to.equal(2)
198 const video = videos[1]
199 expect(video.name).to.equal('my super name for pod 2')
200 expect(video.category).to.equal(4)
201 expect(video.categoryLabel).to.equal('Art')
202 expect(video.licence).to.equal(3)
203 expect(video.licenceLabel).to.equal('Attribution - No Derivatives')
204 expect(video.language).to.equal(11)
205 expect(video.languageLabel).to.equal('German')
206 expect(video.nsfw).to.be.true
207 expect(video.description).to.equal('my super description for pod 2')
208 expect(video.podHost).to.equal('localhost:9002')
209 expect(video.duration).to.equal(5)
210 expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
211 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
212 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
213 expect(video.author).to.equal('root')
214
215 expect(video.files).to.have.lengthOf(1)
216
217 const file = video.files[0]
218 const magnetUri = file.magnetUri
219 expect(file.magnetUri).to.exist
220 expect(file.resolution).to.equal(0)
221 expect(file.resolutionLabel).to.equal('original')
222 expect(file.size).to.equal(942961)
223
224 if (server.url !== 'http://localhost:9002') {
225 expect(video.isLocal).to.be.false
226 } else {
227 expect(video.isLocal).to.be.true
228 }
229
230 // All pods should have the same magnet Uri
231 if (baseMagnet === null) {
232 baseMagnet = magnetUri
233 } else {
234 expect(baseMagnet).to.equal(magnetUri)
235 }
236
237 videosUtils.testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath, function (err, test) {
238 if (err) throw err
239 expect(test).to.equal(true)
240
241 callback()
242 })
243 })
244 }, done)
245 }
246 )
247 })
248
249 it('Should upload two videos on pod 3 and propagate on each pod', function (done) {
250 this.timeout(45000)
251
252 series([
253 function (next) {
254 const videoAttributes = {
255 name: 'my super name for pod 3',
256 category: 6,
257 licence: 5,
258 language: 11,
259 nsfw: true,
260 description: 'my super description for pod 3',
261 tags: [ 'tag1p3' ],
262 fixture: 'video_short3.webm'
263 }
264 videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes, next)
265 },
266 function (next) {
267 const videoAttributes = {
268 name: 'my super name for pod 3-2',
269 category: 7,
270 licence: 6,
271 language: 12,
272 nsfw: false,
273 description: 'my super description for pod 3-2',
274 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
275 fixture: 'video_short.webm'
276 }
277 videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes, next)
278 },
279 function (next) {
280 setTimeout(next, 33000)
281 }],
282 function (err) {
283 if (err) throw err
284
285 let baseMagnet = null
286 // All pods should have this video
287 each(servers, function (server, callback) {
288 videosUtils.getVideosList(server.url, function (err, res) {
289 if (err) throw err
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 pod 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 pod 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 pod 3')
315 expect(video1.podHost).to.equal('localhost:9003')
316 expect(video1.duration).to.equal(5)
317 expect(video1.tags).to.deep.equal([ 'tag1p3' ])
318 expect(video1.author).to.equal('root')
319 expect(miscsUtils.dateIsValid(video1.createdAt)).to.be.true
320 expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true
321
322 expect(video1.files).to.have.lengthOf(1)
323
324 const file1 = video1.files[0]
325 const magnetUri1 = file1.magnetUri
326 expect(file1.magnetUri).to.exist
327 expect(file1.resolution).to.equal(0)
328 expect(file1.resolutionLabel).to.equal('original')
329 expect(file1.size).to.equal(292677)
330
331 expect(video2.name).to.equal('my super name for pod 3-2')
332 expect(video2.category).to.equal(7)
333 expect(video2.categoryLabel).to.equal('Gaming')
334 expect(video2.licence).to.equal(6)
335 expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
336 expect(video2.language).to.equal(12)
337 expect(video2.languageLabel).to.equal('Korean')
338 expect(video2.nsfw).to.be.false
339 expect(video2.description).to.equal('my super description for pod 3-2')
340 expect(video2.podHost).to.equal('localhost:9003')
341 expect(video2.duration).to.equal(5)
342 expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
343 expect(video2.author).to.equal('root')
344 expect(miscsUtils.dateIsValid(video2.createdAt)).to.be.true
345 expect(miscsUtils.dateIsValid(video2.updatedAt)).to.be.true
346
347 expect(video2.files).to.have.lengthOf(1)
348
349 const file2 = video2.files[0]
350 const magnetUri2 = file2.magnetUri
351 expect(file2.magnetUri).to.exist
352 expect(file2.resolution).to.equal(0)
353 expect(file2.resolutionLabel).to.equal('original')
354 expect(file2.size).to.equal(218910)
355
356 if (server.url !== 'http://localhost:9003') {
357 expect(video1.isLocal).to.be.false
358 expect(video2.isLocal).to.be.false
359 } else {
360 expect(video1.isLocal).to.be.true
361 expect(video2.isLocal).to.be.true
362 }
363
364 // All pods should have the same magnet Uri
365 if (baseMagnet === null) {
366 baseMagnet = magnetUri2
367 } else {
368 expect(baseMagnet).to.equal(magnetUri2)
369 }
370
371 videosUtils.testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath, function (err, test) {
372 if (err) throw err
373 expect(test).to.equal(true)
374
375 videosUtils.testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath, function (err, test) {
376 if (err) throw err
377 expect(test).to.equal(true)
378
379 callback()
380 })
381 })
382 })
383 }, done)
384 }
385 )
386 })
387 })
388
389 describe('Should seed the uploaded video', function () {
390 it('Should add the file 1 by asking pod 3', function (done) {
391 // Yes, this could be long
392 this.timeout(200000)
393
394 videosUtils.getVideosList(servers[2].url, function (err, res) {
395 if (err) throw err
396
397 const video = res.body.data[0]
398 toRemove.push(res.body.data[2])
399 toRemove.push(res.body.data[3])
400
401 webtorrent.add(video.files[0].magnetUri, function (torrent) {
402 expect(torrent.files).to.exist
403 expect(torrent.files.length).to.equal(1)
404 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
405
406 done()
407 })
408 })
409 })
410
411 it('Should add the file 2 by asking pod 1', function (done) {
412 // Yes, this could be long
413 this.timeout(200000)
414
415 videosUtils.getVideosList(servers[0].url, function (err, res) {
416 if (err) throw err
417
418 const video = res.body.data[1]
419
420 webtorrent.add(video.files[0].magnetUri, function (torrent) {
421 expect(torrent.files).to.exist
422 expect(torrent.files.length).to.equal(1)
423 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
424
425 done()
426 })
427 })
428 })
429
430 it('Should add the file 3 by asking pod 2', function (done) {
431 // Yes, this could be long
432 this.timeout(200000)
433
434 videosUtils.getVideosList(servers[1].url, function (err, res) {
435 if (err) throw err
436
437 const video = res.body.data[2]
438
439 webtorrent.add(video.files[0].magnetUri, function (torrent) {
440 expect(torrent.files).to.exist
441 expect(torrent.files.length).to.equal(1)
442 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
443
444 done()
445 })
446 })
447 })
448
449 it('Should add the file 3-2 by asking pod 1', function (done) {
450 // Yes, this could be long
451 this.timeout(200000)
452
453 videosUtils.getVideosList(servers[0].url, function (err, res) {
454 if (err) throw err
455
456 const video = res.body.data[3]
457
458 webtorrent.add(video.files[0].magnetUri, function (torrent) {
459 expect(torrent.files).to.exist
460 expect(torrent.files.length).to.equal(1)
461 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
462
463 done()
464 })
465 })
466 })
467 })
468
469 describe('Should update video views, likes and dislikes', function () {
470 let localVideosPod3 = []
471 let remoteVideosPod1 = []
472 let remoteVideosPod2 = []
473 let remoteVideosPod3 = []
474
475 before(function (done) {
476 parallel([
477 function (callback) {
478 videosUtils.getVideosList(servers[0].url, function (err, res) {
479 if (err) throw err
480
481 remoteVideosPod1 = res.body.data.filter(video => video.isLocal === false).map(video => video.id)
482
483 callback()
484 })
485 },
486
487 function (callback) {
488 videosUtils.getVideosList(servers[1].url, function (err, res) {
489 if (err) throw err
490
491 remoteVideosPod2 = res.body.data.filter(video => video.isLocal === false).map(video => video.id)
492
493 callback()
494 })
495 },
496
497 function (callback) {
498 videosUtils.getVideosList(servers[2].url, function (err, res) {
499 if (err) throw err
500
501 localVideosPod3 = res.body.data.filter(video => video.isLocal === true).map(video => video.id)
502 remoteVideosPod3 = res.body.data.filter(video => video.isLocal === false).map(video => video.id)
503
504 callback()
505 })
506 }
507 ], done)
508 })
509
510 it('Should view multiple videos on owned servers', function (done) {
511 this.timeout(30000)
512
513 parallel([
514 function (callback) {
515 videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
516 },
517
518 function (callback) {
519 videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
520 },
521
522 function (callback) {
523 videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
524 },
525
526 function (callback) {
527 videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
528 },
529
530 function (callback) {
531 setTimeout(callback, 22000)
532 }
533 ], function (err) {
534 if (err) throw err
535
536 eachSeries(servers, function (server, callback) {
537 videosUtils.getVideosList(server.url, function (err, res) {
538 if (err) throw err
539
540 const videos = res.body.data
541 expect(videos.find(video => video.views === 3)).to.exist
542 expect(videos.find(video => video.views === 1)).to.exist
543
544 callback()
545 })
546 }, done)
547 })
548 })
549
550 it('Should view multiple videos on each servers', function (done) {
551 this.timeout(30000)
552
553 parallel([
554 function (callback) {
555 videosUtils.getVideo(servers[0].url, remoteVideosPod1[0], callback)
556 },
557
558 function (callback) {
559 videosUtils.getVideo(servers[1].url, remoteVideosPod2[0], callback)
560 },
561
562 function (callback) {
563 videosUtils.getVideo(servers[1].url, remoteVideosPod2[0], callback)
564 },
565
566 function (callback) {
567 videosUtils.getVideo(servers[2].url, remoteVideosPod3[0], callback)
568 },
569
570 function (callback) {
571 videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback)
572 },
573
574 function (callback) {
575 videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback)
576 },
577
578 function (callback) {
579 videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback)
580 },
581
582 function (callback) {
583 videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
584 },
585
586 function (callback) {
587 videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
588 },
589
590 function (callback) {
591 videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
592 },
593
594 function (callback) {
595 setTimeout(callback, 22000)
596 }
597 ], function (err) {
598 if (err) throw err
599
600 let baseVideos = null
601 eachSeries(servers, function (server, callback) {
602 videosUtils.getVideosList(server.url, function (err, res) {
603 if (err) throw err
604
605 const videos = res.body.data
606
607 // Initialize base videos for future comparisons
608 if (baseVideos === null) {
609 baseVideos = videos
610 return callback()
611 }
612
613 baseVideos.forEach(baseVideo => {
614 const sameVideo = videos.find(video => video.name === baseVideo.name)
615 expect(baseVideo.views).to.equal(sameVideo.views)
616 })
617
618 callback()
619 })
620 }, done)
621 })
622 })
623
624 it('Should like and dislikes videos on different services', function (done) {
625 this.timeout(30000)
626
627 parallel([
628 function (callback) {
629 videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like', callback)
630 },
631
632 function (callback) {
633 videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'dislike', callback)
634 },
635
636 function (callback) {
637 videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like', callback)
638 },
639
640 function (callback) {
641 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'like', callback)
642 },
643
644 function (callback) {
645 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'dislike', callback)
646 },
647
648 function (callback) {
649 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[1], 'dislike', callback)
650 },
651
652 function (callback) {
653 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[0], 'like', callback)
654 },
655
656 function (callback) {
657 setTimeout(callback, 22000)
658 }
659 ], function (err) {
660 if (err) throw err
661
662 let baseVideos = null
663 eachSeries(servers, function (server, callback) {
664 videosUtils.getVideosList(server.url, function (err, res) {
665 if (err) throw err
666
667 const videos = res.body.data
668
669 // Initialize base videos for future comparisons
670 if (baseVideos === null) {
671 baseVideos = videos
672 return callback()
673 }
674
675 baseVideos.forEach(baseVideo => {
676 const sameVideo = videos.find(video => video.name === baseVideo.name)
677 expect(baseVideo.likes).to.equal(sameVideo.likes)
678 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
679 })
680
681 callback()
682 })
683 }, done)
684 })
685 })
686 })
687
688 describe('Should manipulate these videos', function () {
689 it('Should update the video 3 by asking pod 3', function (done) {
690 this.timeout(15000)
691
692 const attributes = {
693 name: 'my super video updated',
694 category: 10,
695 licence: 7,
696 language: 13,
697 nsfw: true,
698 description: 'my super description updated',
699 tags: [ 'tagup1', 'tagup2' ]
700 }
701 videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes, function (err) {
702 if (err) throw err
703
704 setTimeout(done, 11000)
705 })
706 })
707
708 it('Should have the video 3 updated on each pod', function (done) {
709 this.timeout(200000)
710
711 each(servers, function (server, callback) {
712 // Avoid "duplicate torrent" errors
713 const webtorrent = new WebTorrent()
714
715 videosUtils.getVideosList(server.url, function (err, res) {
716 if (err) throw err
717
718 const videos = res.body.data
719 const videoUpdated = videos.find(function (video) {
720 return video.name === 'my super video updated'
721 })
722
723 expect(!!videoUpdated).to.be.true
724 expect(videoUpdated.category).to.equal(10)
725 expect(videoUpdated.categoryLabel).to.equal('Entertainment')
726 expect(videoUpdated.licence).to.equal(7)
727 expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication')
728 expect(videoUpdated.language).to.equal(13)
729 expect(videoUpdated.languageLabel).to.equal('French')
730 expect(videoUpdated.nsfw).to.be.ok
731 expect(videoUpdated.description).to.equal('my super description updated')
732 expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
733 expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
734
735 const file = videoUpdated.files[0]
736 const magnetUri = file.magnetUri
737 expect(file.magnetUri).to.exist
738 expect(file.resolution).to.equal(0)
739 expect(file.resolutionLabel).to.equal('original')
740 expect(file.size).to.equal(292677)
741
742 videosUtils.testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath, function (err, test) {
743 if (err) throw err
744 expect(test).to.equal(true)
745
746 webtorrent.add(videoUpdated.files[0].magnetUri, function (torrent) {
747 expect(torrent.files).to.exist
748 expect(torrent.files.length).to.equal(1)
749 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
750
751 callback()
752 })
753 })
754 })
755 }, done)
756 })
757
758 it('Should remove the videos 3 and 3-2 by asking pod 3', function (done) {
759 this.timeout(15000)
760
761 series([
762 function (next) {
763 videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, next)
764 },
765 function (next) {
766 videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id, next)
767 }],
768 function (err) {
769 if (err) throw err
770 setTimeout(done, 11000)
771 }
772 )
773 })
774
775 it('Should have videos 1 and 3 on each pod', function (done) {
776 each(servers, function (server, callback) {
777 videosUtils.getVideosList(server.url, function (err, res) {
778 if (err) throw err
779
780 const videos = res.body.data
781 expect(videos).to.be.an('array')
782 expect(videos.length).to.equal(2)
783 expect(videos[0].name).not.to.equal(videos[1].name)
784 expect(videos[0].name).not.to.equal(toRemove[0].name)
785 expect(videos[1].name).not.to.equal(toRemove[0].name)
786 expect(videos[0].name).not.to.equal(toRemove[1].name)
787 expect(videos[1].name).not.to.equal(toRemove[1].name)
788
789 videoUUID = videos.find(video => video.name === 'my super name for pod 1').uuid
790
791 callback()
792 })
793 }, done)
794 })
795
796 it('Should get the same video by UUID on each pod', function (done) {
797 let baseVideo = null
798 each(servers, function (server, callback) {
799 videosUtils.getVideo(server.url, videoUUID, function (err, res) {
800 if (err) throw err
801
802 const video = res.body
803
804 if (baseVideo === null) {
805 baseVideo = video
806 return callback()
807 }
808
809 expect(baseVideo.name).to.equal(video.name)
810 expect(baseVideo.uuid).to.equal(video.uuid)
811 expect(baseVideo.category).to.equal(video.category)
812 expect(baseVideo.language).to.equal(video.language)
813 expect(baseVideo.licence).to.equal(video.licence)
814 expect(baseVideo.category).to.equal(video.category)
815 expect(baseVideo.nsfw).to.equal(video.nsfw)
816 expect(baseVideo.author).to.equal(video.author)
817 expect(baseVideo.tags).to.deep.equal(video.tags)
818
819 callback()
820 })
821 }, done)
822 })
823
824 it('Should get the preview from each pod', function (done) {
825 each(servers, function (server, callback) {
826 videosUtils.getVideo(server.url, videoUUID, function (err, res) {
827 if (err) throw err
828
829 const video = res.body
830
831 videosUtils.testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath, function (err, test) {
832 if (err) throw err
833 expect(test).to.equal(true)
834
835 callback()
836 })
837 })
838 }, done)
839 })
840 })
841
842 after(function (done) {
843 servers.forEach(function (server) {
844 process.kill(-server.app.pid)
845 })
846
847 // Keep the logs if the test failed
848 if (this.ok) {
849 serversUtils.flushTests(done)
850 } else {
851 done()
852 }
853 })
854 })