]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/multiple-pods.js
Client: fix prod compilation
[github/Chocobozzz/PeerTube.git] / server / tests / api / multiple-pods.js
CommitLineData
72329aaa
C
1/* eslint-disable no-unused-expressions */
2
9f10b292
C
3'use strict'
4
f0f5567b 5const chai = require('chai')
1a42c9e2 6const each = require('async/each')
d38b8281 7const eachSeries = require('async/eachSeries')
f0f5567b 8const expect = chai.expect
9e167724 9const parallel = require('async/parallel')
1a42c9e2 10const series = require('async/series')
7f4e7c36
C
11const WebTorrent = require('webtorrent')
12const webtorrent = new WebTorrent()
9f10b292 13
8d309058
C
14const loginUtils = require('../utils/login')
15const miscsUtils = require('../utils/miscs')
16const podsUtils = require('../utils/pods')
17const serversUtils = require('../utils/servers')
18const videosUtils = require('../utils/videos')
9f10b292
C
19
20describe('Test multiple pods', function () {
0c1cbbfe 21 let servers = []
bc503c2a 22 const toRemove = []
9f10b292
C
23
24 before(function (done) {
25 this.timeout(30000)
26
1a42c9e2 27 series([
9f10b292
C
28 // Run servers
29 function (next) {
8d309058 30 serversUtils.flushAndRunMultipleServers(3, function (serversRun) {
bc503c2a 31 servers = serversRun
9f10b292
C
32 next()
33 })
34 },
0c1cbbfe
C
35 // Get the access tokens
36 function (next) {
1a42c9e2 37 each(servers, function (server, callbackEach) {
8d309058 38 loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
bc503c2a 39 if (err) return callbackEach(err)
0c1cbbfe 40
bc503c2a
C
41 server.accessToken = accessToken
42 callbackEach()
0c1cbbfe
C
43 })
44 }, next)
45 },
9f10b292
C
46 // The second pod make friend with the third
47 function (next) {
b3b92647 48 const server = servers[1]
8d309058 49 podsUtils.makeFriends(server.url, server.accessToken, next)
9f10b292
C
50 },
51 // Wait for the request between pods
52 function (next) {
53 setTimeout(next, 10000)
54 },
55 // Pod 1 make friends too
56 function (next) {
b3b92647 57 const server = servers[0]
8d309058 58 podsUtils.makeFriends(server.url, server.accessToken, next)
9f10b292
C
59 }
60 ], done)
61 })
8c308c2b 62
9f10b292 63 it('Should not have videos for all pods', function (done) {
1a42c9e2 64 each(servers, function (server, callback) {
8d309058 65 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292 66 if (err) throw err
8c308c2b 67
68ce3ae0
C
68 const videos = res.body.data
69 expect(videos).to.be.an('array')
70 expect(videos.length).to.equal(0)
8c308c2b 71
9f10b292
C
72 callback()
73 })
74 }, done)
75 })
8c308c2b 76
9f10b292
C
77 describe('Should upload the video and propagate on each pod', function () {
78 it('Should upload the video on pod 1 and propagate on each pod', function (done) {
79 this.timeout(15000)
8c308c2b 80
1a42c9e2 81 series([
ee66c593 82 function (next) {
be587647
C
83 const name = 'my super name for pod 1'
84 const description = 'my super description for pod 1'
85 const tags = [ 'tag1p1', 'tag2p1' ]
86 const file = 'video_short1.webm'
8d309058 87 videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next)
ee66c593 88 },
ee66c593 89 function (next) {
9f10b292
C
90 setTimeout(next, 11000)
91 }],
92 // All pods should have this video
93 function (err) {
94 if (err) throw err
95
1a42c9e2 96 each(servers, function (server, callback) {
bc503c2a 97 let baseMagnet = null
9f10b292 98
8d309058 99 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292
C
100 if (err) throw err
101
68ce3ae0 102 const videos = res.body.data
9f10b292
C
103 expect(videos).to.be.an('array')
104 expect(videos.length).to.equal(1)
f0f5567b 105 const video = videos[0]
9f10b292
C
106 expect(video.name).to.equal('my super name for pod 1')
107 expect(video.description).to.equal('my super description for pod 1')
a4254ea1 108 expect(video.podHost).to.equal('localhost:9001')
9f10b292 109 expect(video.magnetUri).to.exist
3a8a8b51 110 expect(video.duration).to.equal(10)
be587647 111 expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
feb4bdfd 112 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
79066fdf 113 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
528a9efa 114 expect(video.author).to.equal('root')
9f10b292 115
6d8ada5f
C
116 if (server.url !== 'http://localhost:9001') {
117 expect(video.isLocal).to.be.false
118 } else {
119 expect(video.isLocal).to.be.true
120 }
121
9f10b292 122 // All pods should have the same magnet Uri
bc503c2a
C
123 if (baseMagnet === null) {
124 baseMagnet = video.magnetUri
9f10b292
C
125 } else {
126 expect(video.magnetUri).to.equal.magnetUri
127 }
128
8d309058 129 videosUtils.testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath, function (err, test) {
9e5f3740
C
130 if (err) throw err
131 expect(test).to.equal(true)
132
133 callback()
134 })
9f10b292
C
135 })
136 }, done)
137 }
138 )
139 })
140
141 it('Should upload the video on pod 2 and propagate on each pod', function (done) {
142 this.timeout(15000)
143
1a42c9e2 144 series([
ee66c593 145 function (next) {
be587647
C
146 const name = 'my super name for pod 2'
147 const description = 'my super description for pod 2'
148 const tags = [ 'tag1p2', 'tag2p2', 'tag3p2' ]
149 const file = 'video_short2.webm'
8d309058 150 videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next)
ee66c593
C
151 },
152 function (next) {
9f10b292
C
153 setTimeout(next, 11000)
154 }],
155 // All pods should have this video
156 function (err) {
157 if (err) throw err
158
1a42c9e2 159 each(servers, function (server, callback) {
bc503c2a 160 let baseMagnet = null
9f10b292 161
8d309058 162 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292
C
163 if (err) throw err
164
68ce3ae0 165 const videos = res.body.data
9f10b292
C
166 expect(videos).to.be.an('array')
167 expect(videos.length).to.equal(2)
f0f5567b 168 const video = videos[1]
9f10b292
C
169 expect(video.name).to.equal('my super name for pod 2')
170 expect(video.description).to.equal('my super description for pod 2')
a4254ea1 171 expect(video.podHost).to.equal('localhost:9002')
9f10b292 172 expect(video.magnetUri).to.exist
3a8a8b51 173 expect(video.duration).to.equal(5)
be587647 174 expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
feb4bdfd 175 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
79066fdf 176 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
528a9efa 177 expect(video.author).to.equal('root')
9f10b292 178
6d8ada5f
C
179 if (server.url !== 'http://localhost:9002') {
180 expect(video.isLocal).to.be.false
181 } else {
182 expect(video.isLocal).to.be.true
183 }
184
9f10b292 185 // All pods should have the same magnet Uri
bc503c2a
C
186 if (baseMagnet === null) {
187 baseMagnet = video.magnetUri
9f10b292
C
188 } else {
189 expect(video.magnetUri).to.equal.magnetUri
190 }
191
8d309058 192 videosUtils.testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath, function (err, test) {
9e5f3740
C
193 if (err) throw err
194 expect(test).to.equal(true)
195
196 callback()
197 })
9f10b292
C
198 })
199 }, done)
ee66c593 200 }
9f10b292 201 )
8c308c2b
C
202 })
203
9f10b292
C
204 it('Should upload two videos on pod 3 and propagate on each pod', function (done) {
205 this.timeout(30000)
8c308c2b 206
1a42c9e2 207 series([
9f10b292 208 function (next) {
be587647
C
209 const name = 'my super name for pod 3'
210 const description = 'my super description for pod 3'
211 const tags = [ 'tag1p3' ]
212 const file = 'video_short3.webm'
8d309058 213 videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next)
9f10b292
C
214 },
215 function (next) {
be587647
C
216 const name = 'my super name for pod 3-2'
217 const description = 'my super description for pod 3-2'
218 const tags = [ 'tag2p3', 'tag3p3', 'tag4p3' ]
219 const file = 'video_short.webm'
8d309058 220 videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next)
9f10b292
C
221 },
222 function (next) {
223 setTimeout(next, 22000)
224 }],
225 function (err) {
226 if (err) throw err
8c308c2b 227
bc503c2a 228 let baseMagnet = null
9f10b292 229 // All pods should have this video
1a42c9e2 230 each(servers, function (server, callback) {
8d309058 231 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292
C
232 if (err) throw err
233
68ce3ae0 234 const videos = res.body.data
9f10b292
C
235 expect(videos).to.be.an('array')
236 expect(videos.length).to.equal(4)
3a8a8b51 237
cbe2f7c3
C
238 // We not sure about the order of the two last uploads
239 let video1 = null
240 let video2 = null
241 if (videos[2].name === 'my super name for pod 3') {
242 video1 = videos[2]
243 video2 = videos[3]
244 } else {
245 video1 = videos[3]
246 video2 = videos[2]
247 }
248
6d8ada5f
C
249 expect(video1.name).to.equal('my super name for pod 3')
250 expect(video1.description).to.equal('my super description for pod 3')
a4254ea1 251 expect(video1.podHost).to.equal('localhost:9003')
6d8ada5f 252 expect(video1.magnetUri).to.exist
3a8a8b51 253 expect(video1.duration).to.equal(5)
be587647 254 expect(video1.tags).to.deep.equal([ 'tag1p3' ])
528a9efa 255 expect(video1.author).to.equal('root')
feb4bdfd 256 expect(miscsUtils.dateIsValid(video1.createdAt)).to.be.true
79066fdf 257 expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true
6d8ada5f 258
6d8ada5f
C
259 expect(video2.name).to.equal('my super name for pod 3-2')
260 expect(video2.description).to.equal('my super description for pod 3-2')
a4254ea1 261 expect(video2.podHost).to.equal('localhost:9003')
6d8ada5f 262 expect(video2.magnetUri).to.exist
3a8a8b51 263 expect(video2.duration).to.equal(5)
be587647 264 expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
528a9efa 265 expect(video2.author).to.equal('root')
feb4bdfd 266 expect(miscsUtils.dateIsValid(video2.createdAt)).to.be.true
79066fdf 267 expect(miscsUtils.dateIsValid(video2.updatedAt)).to.be.true
6d8ada5f
C
268
269 if (server.url !== 'http://localhost:9003') {
270 expect(video1.isLocal).to.be.false
271 expect(video2.isLocal).to.be.false
272 } else {
273 expect(video1.isLocal).to.be.true
274 expect(video2.isLocal).to.be.true
275 }
9f10b292
C
276
277 // All pods should have the same magnet Uri
bc503c2a
C
278 if (baseMagnet === null) {
279 baseMagnet = video2.magnetUri
9f10b292 280 } else {
6d8ada5f 281 expect(video2.magnetUri).to.equal.magnetUri
9f10b292
C
282 }
283
8d309058 284 videosUtils.testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath, function (err, test) {
9e5f3740
C
285 if (err) throw err
286 expect(test).to.equal(true)
287
8d309058 288 videosUtils.testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath, function (err, test) {
9e5f3740
C
289 if (err) throw err
290 expect(test).to.equal(true)
291
292 callback()
293 })
294 })
9f10b292
C
295 })
296 }, done)
297 }
298 )
8c308c2b 299 })
9f10b292 300 })
8c308c2b 301
9f10b292
C
302 describe('Should seed the uploaded video', function () {
303 it('Should add the file 1 by asking pod 3', function (done) {
304 // Yes, this could be long
305 this.timeout(200000)
8c308c2b 306
8d309058 307 videosUtils.getVideosList(servers[2].url, function (err, res) {
9f10b292 308 if (err) throw err
8c308c2b 309
68ce3ae0 310 const video = res.body.data[0]
3d118fb5
C
311 toRemove.push(res.body.data[2])
312 toRemove.push(res.body.data[3])
8c308c2b 313
9f10b292
C
314 webtorrent.add(video.magnetUri, function (torrent) {
315 expect(torrent.files).to.exist
316 expect(torrent.files.length).to.equal(1)
317 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 318
790e65fc 319 done()
9f10b292 320 })
8c308c2b
C
321 })
322 })
323
9f10b292
C
324 it('Should add the file 2 by asking pod 1', function (done) {
325 // Yes, this could be long
326 this.timeout(200000)
8c308c2b 327
8d309058 328 videosUtils.getVideosList(servers[0].url, function (err, res) {
9f10b292 329 if (err) throw err
8c308c2b 330
68ce3ae0 331 const video = res.body.data[1]
0b697522 332
9f10b292
C
333 webtorrent.add(video.magnetUri, function (torrent) {
334 expect(torrent.files).to.exist
335 expect(torrent.files.length).to.equal(1)
336 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 337
790e65fc 338 done()
8c308c2b
C
339 })
340 })
9f10b292 341 })
8c308c2b 342
9f10b292
C
343 it('Should add the file 3 by asking pod 2', function (done) {
344 // Yes, this could be long
345 this.timeout(200000)
8c308c2b 346
8d309058 347 videosUtils.getVideosList(servers[1].url, function (err, res) {
9f10b292 348 if (err) throw err
8c308c2b 349
68ce3ae0 350 const video = res.body.data[2]
8c308c2b 351
9f10b292
C
352 webtorrent.add(video.magnetUri, function (torrent) {
353 expect(torrent.files).to.exist
354 expect(torrent.files.length).to.equal(1)
355 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 356
790e65fc 357 done()
8c308c2b
C
358 })
359 })
9f10b292 360 })
8c308c2b 361
9f10b292
C
362 it('Should add the file 3-2 by asking pod 1', function (done) {
363 // Yes, this could be long
364 this.timeout(200000)
8c308c2b 365
8d309058 366 videosUtils.getVideosList(servers[0].url, function (err, res) {
9f10b292 367 if (err) throw err
8c308c2b 368
68ce3ae0 369 const video = res.body.data[3]
8c308c2b 370
9f10b292
C
371 webtorrent.add(video.magnetUri, function (torrent) {
372 expect(torrent.files).to.exist
373 expect(torrent.files.length).to.equal(1)
374 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 375
790e65fc 376 done()
8c308c2b
C
377 })
378 })
9f10b292 379 })
3d118fb5
C
380 })
381
d38b8281 382 describe('Should update video views, likes and dislikes', function () {
e4c87ec2
C
383 let localVideosPod3 = []
384 let remoteVideosPod1 = []
385 let remoteVideosPod2 = []
386 let remoteVideosPod3 = []
9e167724
C
387
388 before(function (done) {
e4c87ec2
C
389 parallel([
390 function (callback) {
391 videosUtils.getVideosList(servers[0].url, function (err, res) {
392 if (err) throw err
9e167724 393
e4c87ec2 394 remoteVideosPod1 = res.body.data.filter(video => video.isLocal === false).map(video => video.id)
9e167724 395
e4c87ec2
C
396 callback()
397 })
398 },
399
400 function (callback) {
401 videosUtils.getVideosList(servers[1].url, function (err, res) {
402 if (err) throw err
403
404 remoteVideosPod2 = res.body.data.filter(video => video.isLocal === false).map(video => video.id)
405
406 callback()
407 })
408 },
409
410 function (callback) {
411 videosUtils.getVideosList(servers[2].url, function (err, res) {
412 if (err) throw err
413
414 localVideosPod3 = res.body.data.filter(video => video.isLocal === true).map(video => video.id)
415 remoteVideosPod3 = res.body.data.filter(video => video.isLocal === false).map(video => video.id)
416
417 callback()
418 })
419 }
420 ], done)
9e167724
C
421 })
422
d38b8281 423 it('Should view multiple videos on owned servers', function (done) {
9e167724
C
424 this.timeout(30000)
425
426 parallel([
427 function (callback) {
e4c87ec2 428 videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
9e167724
C
429 },
430
431 function (callback) {
e4c87ec2 432 videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
9e167724
C
433 },
434
435 function (callback) {
e4c87ec2 436 videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
9e167724
C
437 },
438
439 function (callback) {
e4c87ec2
C
440 videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
441 },
442
443 function (callback) {
d38b8281 444 setTimeout(callback, 22000)
9e167724
C
445 }
446 ], function (err) {
447 if (err) throw err
448
d38b8281 449 eachSeries(servers, function (server, callback) {
e4c87ec2
C
450 videosUtils.getVideosList(server.url, function (err, res) {
451 if (err) throw err
452
453 const videos = res.body.data
d38b8281
C
454 expect(videos.find(video => video.views === 3)).to.exist
455 expect(videos.find(video => video.views === 1)).to.exist
e4c87ec2
C
456
457 callback()
458 })
459 }, done)
9e167724
C
460 })
461 })
462
d38b8281 463 it('Should view multiple videos on each servers', function (done) {
e4c87ec2 464 this.timeout(30000)
9e167724 465
e4c87ec2
C
466 parallel([
467 function (callback) {
468 videosUtils.getVideo(servers[0].url, remoteVideosPod1[0], callback)
469 },
9e167724 470
e4c87ec2
C
471 function (callback) {
472 videosUtils.getVideo(servers[1].url, remoteVideosPod2[0], callback)
473 },
474
475 function (callback) {
476 videosUtils.getVideo(servers[1].url, remoteVideosPod2[0], callback)
477 },
478
479 function (callback) {
480 videosUtils.getVideo(servers[2].url, remoteVideosPod3[0], callback)
481 },
482
483 function (callback) {
484 videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback)
485 },
486
487 function (callback) {
488 videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback)
489 },
490
491 function (callback) {
492 videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback)
493 },
494
495 function (callback) {
496 videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
497 },
498
499 function (callback) {
500 videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
501 },
502
503 function (callback) {
504 videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
505 },
506
507 function (callback) {
d38b8281 508 setTimeout(callback, 22000)
e4c87ec2
C
509 }
510 ], function (err) {
511 if (err) throw err
512
513 let baseVideos = null
d38b8281 514 eachSeries(servers, function (server, callback) {
e4c87ec2
C
515 videosUtils.getVideosList(server.url, function (err, res) {
516 if (err) throw err
517
d38b8281 518 const videos = res.body.data
e4c87ec2
C
519
520 // Initialize base videos for future comparisons
521 if (baseVideos === null) {
522 baseVideos = videos
523 return callback()
524 }
525
d38b8281
C
526 baseVideos.forEach(baseVideo => {
527 const sameVideo = videos.find(video => video.name === baseVideo.name)
528 expect(baseVideo.views).to.equal(sameVideo.views)
529 })
530
531 callback()
532 })
533 }, done)
534 })
535 })
536
537 it('Should like and dislikes videos on different services', function (done) {
538 this.timeout(30000)
539
540 parallel([
541 function (callback) {
542 videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like', callback)
543 },
544
545 function (callback) {
546 videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'dislike', callback)
547 },
548
549 function (callback) {
550 videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like', callback)
551 },
552
553 function (callback) {
554 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'like', callback)
555 },
556
557 function (callback) {
558 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'dislike', callback)
559 },
560
561 function (callback) {
562 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[1], 'dislike', callback)
563 },
564
565 function (callback) {
566 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[0], 'like', callback)
567 },
568
569 function (callback) {
570 setTimeout(callback, 22000)
571 }
572 ], function (err) {
573 if (err) throw err
574
575 let baseVideos = null
576 eachSeries(servers, function (server, callback) {
577 videosUtils.getVideosList(server.url, function (err, res) {
578 if (err) throw err
579
580 const videos = res.body.data
581
582 // Initialize base videos for future comparisons
583 if (baseVideos === null) {
584 baseVideos = videos
585 return callback()
e4c87ec2
C
586 }
587
d38b8281
C
588 baseVideos.forEach(baseVideo => {
589 const sameVideo = videos.find(video => video.name === baseVideo.name)
590 expect(baseVideo.likes).to.equal(sameVideo.likes)
591 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
592 })
593
e4c87ec2
C
594 callback()
595 })
596 }, done)
597 })
9e167724
C
598 })
599 })
e4c87ec2 600
3d118fb5
C
601 describe('Should manipulate these videos', function () {
602 it('Should update the video 3 by asking pod 3', function (done) {
603 this.timeout(15000)
604
605 const name = 'my super video updated'
606 const description = 'my super description updated'
607 const tags = [ 'tagup1', 'tagup2' ]
608
609 videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, name, description, tags, function (err) {
610 if (err) throw err
611
612 setTimeout(done, 11000)
613 })
614 })
615
616 it('Should have the video 3 updated on each pod', function (done) {
7f4e7c36
C
617 this.timeout(200000)
618
3d118fb5 619 each(servers, function (server, callback) {
7f4e7c36
C
620 // Avoid "duplicate torrent" errors
621 const webtorrent = new WebTorrent()
622
3d118fb5
C
623 videosUtils.getVideosList(server.url, function (err, res) {
624 if (err) throw err
625
626 const videos = res.body.data
627 const videoUpdated = videos.find(function (video) {
628 return video.name === 'my super video updated'
629 })
630
631 expect(!!videoUpdated).to.be.true
632 expect(videoUpdated.description).to.equal('my super description updated')
633 expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
79066fdf 634 expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
3d118fb5 635
7f4e7c36
C
636 videosUtils.testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath, function (err, test) {
637 if (err) throw err
638 expect(test).to.equal(true)
639
640 webtorrent.add(videoUpdated.magnetUri, function (torrent) {
641 expect(torrent.files).to.exist
642 expect(torrent.files.length).to.equal(1)
643 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
644
790e65fc 645 callback()
7f4e7c36
C
646 })
647 })
3d118fb5
C
648 })
649 }, done)
650 })
8c308c2b 651
3d118fb5 652 it('Should remove the videos 3 and 3-2 by asking pod 3', function (done) {
9f10b292 653 this.timeout(15000)
0b697522 654
1a42c9e2 655 series([
9f10b292 656 function (next) {
3d118fb5 657 videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, next)
9f10b292
C
658 },
659 function (next) {
3d118fb5 660 videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id, next)
9f10b292
C
661 }],
662 function (err) {
0b697522 663 if (err) throw err
9f10b292
C
664 setTimeout(done, 11000)
665 }
666 )
667 })
0b697522 668
9f10b292 669 it('Should have videos 1 and 3 on each pod', function (done) {
1a42c9e2 670 each(servers, function (server, callback) {
8d309058 671 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292 672 if (err) throw err
0b697522 673
68ce3ae0 674 const videos = res.body.data
9f10b292
C
675 expect(videos).to.be.an('array')
676 expect(videos.length).to.equal(2)
3d118fb5
C
677 expect(videos[0].name).not.to.equal(videos[1].name)
678 expect(videos[0].name).not.to.equal(toRemove[0].name)
679 expect(videos[1].name).not.to.equal(toRemove[0].name)
680 expect(videos[0].name).not.to.equal(toRemove[1].name)
681 expect(videos[1].name).not.to.equal(toRemove[1].name)
0b697522 682
9f10b292 683 callback()
0b697522 684 })
9f10b292 685 }, done)
8c308c2b 686 })
9f10b292 687 })
e4c87ec2 688
9f10b292 689 after(function (done) {
0c1cbbfe
C
690 servers.forEach(function (server) {
691 process.kill(-server.app.pid)
8c308c2b 692 })
9f10b292
C
693
694 // Keep the logs if the test failed
695 if (this.ok) {
8d309058 696 serversUtils.flushTests(done)
9f10b292
C
697 } else {
698 done()
699 }
8c308c2b 700 })
9f10b292 701})