]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/multiple-pods.js
Server: add tests to video transcoder
[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) {
b4c5ac97
C
83 const videoAttributes = {
84 name: 'my super name for pod 1',
6f0c39e2
C
85 category: 5,
86 licence: 4,
3092476e 87 language: 9,
31b59b47 88 nsfw: true,
b4c5ac97
C
89 description: 'my super description for pod 1',
90 tags: [ 'tag1p1', 'tag2p1' ],
91 fixture: 'video_short1.webm'
92 }
93 videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes, next)
ee66c593 94 },
ee66c593 95 function (next) {
9f10b292
C
96 setTimeout(next, 11000)
97 }],
98 // All pods should have this video
99 function (err) {
100 if (err) throw err
101
1a42c9e2 102 each(servers, function (server, callback) {
bc503c2a 103 let baseMagnet = null
9f10b292 104
8d309058 105 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292
C
106 if (err) throw err
107
68ce3ae0 108 const videos = res.body.data
9f10b292
C
109 expect(videos).to.be.an('array')
110 expect(videos.length).to.equal(1)
f0f5567b 111 const video = videos[0]
9f10b292 112 expect(video.name).to.equal('my super name for pod 1')
6e07c3de
C
113 expect(video.category).to.equal(5)
114 expect(video.categoryLabel).to.equal('Sports')
6f0c39e2
C
115 expect(video.licence).to.equal(4)
116 expect(video.licenceLabel).to.equal('Attribution - Non Commercial')
3092476e
C
117 expect(video.language).to.equal(9)
118 expect(video.languageLabel).to.equal('Japanese')
31b59b47 119 expect(video.nsfw).to.be.truthy
9f10b292 120 expect(video.description).to.equal('my super description for pod 1')
a4254ea1 121 expect(video.podHost).to.equal('localhost:9001')
9f10b292 122 expect(video.magnetUri).to.exist
3a8a8b51 123 expect(video.duration).to.equal(10)
be587647 124 expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
feb4bdfd 125 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
79066fdf 126 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
528a9efa 127 expect(video.author).to.equal('root')
9f10b292 128
6d8ada5f
C
129 if (server.url !== 'http://localhost:9001') {
130 expect(video.isLocal).to.be.false
131 } else {
132 expect(video.isLocal).to.be.true
133 }
134
9f10b292 135 // All pods should have the same magnet Uri
bc503c2a
C
136 if (baseMagnet === null) {
137 baseMagnet = video.magnetUri
9f10b292
C
138 } else {
139 expect(video.magnetUri).to.equal.magnetUri
140 }
141
8d309058 142 videosUtils.testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath, function (err, test) {
9e5f3740
C
143 if (err) throw err
144 expect(test).to.equal(true)
145
146 callback()
147 })
9f10b292
C
148 })
149 }, done)
150 }
151 )
152 })
153
154 it('Should upload the video on pod 2 and propagate on each pod', function (done) {
155 this.timeout(15000)
156
1a42c9e2 157 series([
ee66c593 158 function (next) {
b4c5ac97
C
159 const videoAttributes = {
160 name: 'my super name for pod 2',
161 category: 4,
6f0c39e2 162 licence: 3,
3092476e 163 language: 11,
31b59b47 164 nsfw: true,
b4c5ac97
C
165 description: 'my super description for pod 2',
166 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
167 fixture: 'video_short2.webm'
168 }
169 videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next)
ee66c593
C
170 },
171 function (next) {
9f10b292
C
172 setTimeout(next, 11000)
173 }],
174 // All pods should have this video
175 function (err) {
176 if (err) throw err
177
1a42c9e2 178 each(servers, function (server, callback) {
bc503c2a 179 let baseMagnet = null
9f10b292 180
8d309058 181 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292
C
182 if (err) throw err
183
68ce3ae0 184 const videos = res.body.data
9f10b292
C
185 expect(videos).to.be.an('array')
186 expect(videos.length).to.equal(2)
f0f5567b 187 const video = videos[1]
9f10b292 188 expect(video.name).to.equal('my super name for pod 2')
6e07c3de
C
189 expect(video.category).to.equal(4)
190 expect(video.categoryLabel).to.equal('Art')
6f0c39e2
C
191 expect(video.licence).to.equal(3)
192 expect(video.licenceLabel).to.equal('Attribution - No Derivatives')
3092476e
C
193 expect(video.language).to.equal(11)
194 expect(video.languageLabel).to.equal('German')
31b59b47 195 expect(video.nsfw).to.be.falsy
9f10b292 196 expect(video.description).to.equal('my super description for pod 2')
a4254ea1 197 expect(video.podHost).to.equal('localhost:9002')
9f10b292 198 expect(video.magnetUri).to.exist
3a8a8b51 199 expect(video.duration).to.equal(5)
be587647 200 expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
feb4bdfd 201 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
79066fdf 202 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
528a9efa 203 expect(video.author).to.equal('root')
9f10b292 204
6d8ada5f
C
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
9f10b292 211 // All pods should have the same magnet Uri
bc503c2a
C
212 if (baseMagnet === null) {
213 baseMagnet = video.magnetUri
9f10b292
C
214 } else {
215 expect(video.magnetUri).to.equal.magnetUri
216 }
217
8d309058 218 videosUtils.testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath, function (err, test) {
9e5f3740
C
219 if (err) throw err
220 expect(test).to.equal(true)
221
222 callback()
223 })
9f10b292
C
224 })
225 }, done)
ee66c593 226 }
9f10b292 227 )
8c308c2b
C
228 })
229
9f10b292
C
230 it('Should upload two videos on pod 3 and propagate on each pod', function (done) {
231 this.timeout(30000)
8c308c2b 232
1a42c9e2 233 series([
9f10b292 234 function (next) {
b4c5ac97
C
235 const videoAttributes = {
236 name: 'my super name for pod 3',
237 category: 6,
6f0c39e2 238 licence: 5,
3092476e 239 language: 11,
31b59b47 240 nsfw: true,
b4c5ac97
C
241 description: 'my super description for pod 3',
242 tags: [ 'tag1p3' ],
243 fixture: 'video_short3.webm'
244 }
245 videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes, next)
9f10b292
C
246 },
247 function (next) {
b4c5ac97
C
248 const videoAttributes = {
249 name: 'my super name for pod 3-2',
250 category: 7,
6f0c39e2 251 licence: 6,
3092476e 252 language: 12,
31b59b47 253 nsfw: false,
b4c5ac97
C
254 description: 'my super description for pod 3-2',
255 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
256 fixture: 'video_short.webm'
257 }
258 videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes, next)
9f10b292
C
259 },
260 function (next) {
261 setTimeout(next, 22000)
262 }],
263 function (err) {
264 if (err) throw err
8c308c2b 265
bc503c2a 266 let baseMagnet = null
9f10b292 267 // All pods should have this video
1a42c9e2 268 each(servers, function (server, callback) {
8d309058 269 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292
C
270 if (err) throw err
271
68ce3ae0 272 const videos = res.body.data
9f10b292
C
273 expect(videos).to.be.an('array')
274 expect(videos.length).to.equal(4)
3a8a8b51 275
cbe2f7c3
C
276 // We not sure about the order of the two last uploads
277 let video1 = null
278 let video2 = null
279 if (videos[2].name === 'my super name for pod 3') {
280 video1 = videos[2]
281 video2 = videos[3]
282 } else {
283 video1 = videos[3]
284 video2 = videos[2]
285 }
286
6d8ada5f 287 expect(video1.name).to.equal('my super name for pod 3')
6e07c3de
C
288 expect(video1.category).to.equal(6)
289 expect(video1.categoryLabel).to.equal('Travels')
6f0c39e2
C
290 expect(video1.licence).to.equal(5)
291 expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike')
3092476e
C
292 expect(video1.language).to.equal(11)
293 expect(video1.languageLabel).to.equal('German')
31b59b47 294 expect(video1.nsfw).to.be.truthy
6d8ada5f 295 expect(video1.description).to.equal('my super description for pod 3')
a4254ea1 296 expect(video1.podHost).to.equal('localhost:9003')
6d8ada5f 297 expect(video1.magnetUri).to.exist
3a8a8b51 298 expect(video1.duration).to.equal(5)
be587647 299 expect(video1.tags).to.deep.equal([ 'tag1p3' ])
528a9efa 300 expect(video1.author).to.equal('root')
feb4bdfd 301 expect(miscsUtils.dateIsValid(video1.createdAt)).to.be.true
79066fdf 302 expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true
6d8ada5f 303
6d8ada5f 304 expect(video2.name).to.equal('my super name for pod 3-2')
6e07c3de
C
305 expect(video2.category).to.equal(7)
306 expect(video2.categoryLabel).to.equal('Gaming')
6f0c39e2
C
307 expect(video2.licence).to.equal(6)
308 expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
3092476e
C
309 expect(video2.language).to.equal(12)
310 expect(video2.languageLabel).to.equal('Korean')
31b59b47 311 expect(video2.nsfw).to.be.falsy
6d8ada5f 312 expect(video2.description).to.equal('my super description for pod 3-2')
a4254ea1 313 expect(video2.podHost).to.equal('localhost:9003')
6d8ada5f 314 expect(video2.magnetUri).to.exist
3a8a8b51 315 expect(video2.duration).to.equal(5)
be587647 316 expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
528a9efa 317 expect(video2.author).to.equal('root')
feb4bdfd 318 expect(miscsUtils.dateIsValid(video2.createdAt)).to.be.true
79066fdf 319 expect(miscsUtils.dateIsValid(video2.updatedAt)).to.be.true
6d8ada5f
C
320
321 if (server.url !== 'http://localhost:9003') {
322 expect(video1.isLocal).to.be.false
323 expect(video2.isLocal).to.be.false
324 } else {
325 expect(video1.isLocal).to.be.true
326 expect(video2.isLocal).to.be.true
327 }
9f10b292
C
328
329 // All pods should have the same magnet Uri
bc503c2a
C
330 if (baseMagnet === null) {
331 baseMagnet = video2.magnetUri
9f10b292 332 } else {
6d8ada5f 333 expect(video2.magnetUri).to.equal.magnetUri
9f10b292
C
334 }
335
8d309058 336 videosUtils.testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath, function (err, test) {
9e5f3740
C
337 if (err) throw err
338 expect(test).to.equal(true)
339
8d309058 340 videosUtils.testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath, function (err, test) {
9e5f3740
C
341 if (err) throw err
342 expect(test).to.equal(true)
343
344 callback()
345 })
346 })
9f10b292
C
347 })
348 }, done)
349 }
350 )
8c308c2b 351 })
9f10b292 352 })
8c308c2b 353
9f10b292
C
354 describe('Should seed the uploaded video', function () {
355 it('Should add the file 1 by asking pod 3', function (done) {
356 // Yes, this could be long
357 this.timeout(200000)
8c308c2b 358
8d309058 359 videosUtils.getVideosList(servers[2].url, function (err, res) {
9f10b292 360 if (err) throw err
8c308c2b 361
68ce3ae0 362 const video = res.body.data[0]
3d118fb5
C
363 toRemove.push(res.body.data[2])
364 toRemove.push(res.body.data[3])
8c308c2b 365
9f10b292
C
366 webtorrent.add(video.magnetUri, function (torrent) {
367 expect(torrent.files).to.exist
368 expect(torrent.files.length).to.equal(1)
369 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 370
790e65fc 371 done()
9f10b292 372 })
8c308c2b
C
373 })
374 })
375
9f10b292
C
376 it('Should add the file 2 by asking pod 1', function (done) {
377 // Yes, this could be long
378 this.timeout(200000)
8c308c2b 379
8d309058 380 videosUtils.getVideosList(servers[0].url, function (err, res) {
9f10b292 381 if (err) throw err
8c308c2b 382
68ce3ae0 383 const video = res.body.data[1]
0b697522 384
9f10b292
C
385 webtorrent.add(video.magnetUri, function (torrent) {
386 expect(torrent.files).to.exist
387 expect(torrent.files.length).to.equal(1)
388 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 389
790e65fc 390 done()
8c308c2b
C
391 })
392 })
9f10b292 393 })
8c308c2b 394
9f10b292
C
395 it('Should add the file 3 by asking pod 2', function (done) {
396 // Yes, this could be long
397 this.timeout(200000)
8c308c2b 398
8d309058 399 videosUtils.getVideosList(servers[1].url, function (err, res) {
9f10b292 400 if (err) throw err
8c308c2b 401
68ce3ae0 402 const video = res.body.data[2]
8c308c2b 403
9f10b292
C
404 webtorrent.add(video.magnetUri, function (torrent) {
405 expect(torrent.files).to.exist
406 expect(torrent.files.length).to.equal(1)
407 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 408
790e65fc 409 done()
8c308c2b
C
410 })
411 })
9f10b292 412 })
8c308c2b 413
9f10b292
C
414 it('Should add the file 3-2 by asking pod 1', function (done) {
415 // Yes, this could be long
416 this.timeout(200000)
8c308c2b 417
8d309058 418 videosUtils.getVideosList(servers[0].url, function (err, res) {
9f10b292 419 if (err) throw err
8c308c2b 420
68ce3ae0 421 const video = res.body.data[3]
8c308c2b 422
9f10b292
C
423 webtorrent.add(video.magnetUri, function (torrent) {
424 expect(torrent.files).to.exist
425 expect(torrent.files.length).to.equal(1)
426 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
8c308c2b 427
790e65fc 428 done()
8c308c2b
C
429 })
430 })
9f10b292 431 })
3d118fb5
C
432 })
433
d38b8281 434 describe('Should update video views, likes and dislikes', function () {
e4c87ec2
C
435 let localVideosPod3 = []
436 let remoteVideosPod1 = []
437 let remoteVideosPod2 = []
438 let remoteVideosPod3 = []
9e167724
C
439
440 before(function (done) {
e4c87ec2
C
441 parallel([
442 function (callback) {
443 videosUtils.getVideosList(servers[0].url, function (err, res) {
444 if (err) throw err
9e167724 445
e4c87ec2 446 remoteVideosPod1 = res.body.data.filter(video => video.isLocal === false).map(video => video.id)
9e167724 447
e4c87ec2
C
448 callback()
449 })
450 },
451
452 function (callback) {
453 videosUtils.getVideosList(servers[1].url, function (err, res) {
454 if (err) throw err
455
456 remoteVideosPod2 = res.body.data.filter(video => video.isLocal === false).map(video => video.id)
457
458 callback()
459 })
460 },
461
462 function (callback) {
463 videosUtils.getVideosList(servers[2].url, function (err, res) {
464 if (err) throw err
465
466 localVideosPod3 = res.body.data.filter(video => video.isLocal === true).map(video => video.id)
467 remoteVideosPod3 = res.body.data.filter(video => video.isLocal === false).map(video => video.id)
468
469 callback()
470 })
471 }
472 ], done)
9e167724
C
473 })
474
d38b8281 475 it('Should view multiple videos on owned servers', function (done) {
9e167724
C
476 this.timeout(30000)
477
478 parallel([
479 function (callback) {
e4c87ec2 480 videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
9e167724
C
481 },
482
483 function (callback) {
e4c87ec2 484 videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
9e167724
C
485 },
486
487 function (callback) {
e4c87ec2 488 videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
9e167724
C
489 },
490
491 function (callback) {
e4c87ec2
C
492 videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
493 },
494
495 function (callback) {
d38b8281 496 setTimeout(callback, 22000)
9e167724
C
497 }
498 ], function (err) {
499 if (err) throw err
500
d38b8281 501 eachSeries(servers, function (server, callback) {
e4c87ec2
C
502 videosUtils.getVideosList(server.url, function (err, res) {
503 if (err) throw err
504
505 const videos = res.body.data
d38b8281
C
506 expect(videos.find(video => video.views === 3)).to.exist
507 expect(videos.find(video => video.views === 1)).to.exist
e4c87ec2
C
508
509 callback()
510 })
511 }, done)
9e167724
C
512 })
513 })
514
d38b8281 515 it('Should view multiple videos on each servers', function (done) {
e4c87ec2 516 this.timeout(30000)
9e167724 517
e4c87ec2
C
518 parallel([
519 function (callback) {
520 videosUtils.getVideo(servers[0].url, remoteVideosPod1[0], callback)
521 },
9e167724 522
e4c87ec2
C
523 function (callback) {
524 videosUtils.getVideo(servers[1].url, remoteVideosPod2[0], callback)
525 },
526
527 function (callback) {
528 videosUtils.getVideo(servers[1].url, remoteVideosPod2[0], callback)
529 },
530
531 function (callback) {
532 videosUtils.getVideo(servers[2].url, remoteVideosPod3[0], callback)
533 },
534
535 function (callback) {
536 videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback)
537 },
538
539 function (callback) {
540 videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback)
541 },
542
543 function (callback) {
544 videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback)
545 },
546
547 function (callback) {
548 videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
549 },
550
551 function (callback) {
552 videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
553 },
554
555 function (callback) {
556 videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
557 },
558
559 function (callback) {
d38b8281 560 setTimeout(callback, 22000)
e4c87ec2
C
561 }
562 ], function (err) {
563 if (err) throw err
564
565 let baseVideos = null
d38b8281 566 eachSeries(servers, function (server, callback) {
e4c87ec2
C
567 videosUtils.getVideosList(server.url, function (err, res) {
568 if (err) throw err
569
d38b8281 570 const videos = res.body.data
e4c87ec2
C
571
572 // Initialize base videos for future comparisons
573 if (baseVideos === null) {
574 baseVideos = videos
575 return callback()
576 }
577
d38b8281
C
578 baseVideos.forEach(baseVideo => {
579 const sameVideo = videos.find(video => video.name === baseVideo.name)
580 expect(baseVideo.views).to.equal(sameVideo.views)
581 })
582
583 callback()
584 })
585 }, done)
586 })
587 })
588
589 it('Should like and dislikes videos on different services', function (done) {
590 this.timeout(30000)
591
592 parallel([
593 function (callback) {
594 videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like', callback)
595 },
596
597 function (callback) {
598 videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'dislike', callback)
599 },
600
601 function (callback) {
602 videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like', callback)
603 },
604
605 function (callback) {
606 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'like', callback)
607 },
608
609 function (callback) {
610 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'dislike', callback)
611 },
612
613 function (callback) {
614 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[1], 'dislike', callback)
615 },
616
617 function (callback) {
618 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[0], 'like', callback)
619 },
620
621 function (callback) {
622 setTimeout(callback, 22000)
623 }
624 ], function (err) {
625 if (err) throw err
626
627 let baseVideos = null
628 eachSeries(servers, function (server, callback) {
629 videosUtils.getVideosList(server.url, function (err, res) {
630 if (err) throw err
631
632 const videos = res.body.data
633
634 // Initialize base videos for future comparisons
635 if (baseVideos === null) {
636 baseVideos = videos
637 return callback()
e4c87ec2
C
638 }
639
d38b8281
C
640 baseVideos.forEach(baseVideo => {
641 const sameVideo = videos.find(video => video.name === baseVideo.name)
642 expect(baseVideo.likes).to.equal(sameVideo.likes)
643 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
644 })
645
e4c87ec2
C
646 callback()
647 })
648 }, done)
649 })
9e167724
C
650 })
651 })
e4c87ec2 652
3d118fb5
C
653 describe('Should manipulate these videos', function () {
654 it('Should update the video 3 by asking pod 3', function (done) {
655 this.timeout(15000)
656
b4c5ac97
C
657 const attributes = {
658 name: 'my super video updated',
659 category: 10,
6f0c39e2 660 licence: 7,
3092476e 661 language: 13,
31b59b47 662 nsfw: true,
b4c5ac97
C
663 description: 'my super description updated',
664 tags: [ 'tagup1', 'tagup2' ]
665 }
666 videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes, function (err) {
3d118fb5
C
667 if (err) throw err
668
669 setTimeout(done, 11000)
670 })
671 })
672
673 it('Should have the video 3 updated on each pod', function (done) {
7f4e7c36
C
674 this.timeout(200000)
675
3d118fb5 676 each(servers, function (server, callback) {
7f4e7c36
C
677 // Avoid "duplicate torrent" errors
678 const webtorrent = new WebTorrent()
679
3d118fb5
C
680 videosUtils.getVideosList(server.url, function (err, res) {
681 if (err) throw err
682
683 const videos = res.body.data
684 const videoUpdated = videos.find(function (video) {
685 return video.name === 'my super video updated'
686 })
687
688 expect(!!videoUpdated).to.be.true
6e07c3de
C
689 expect(videoUpdated.category).to.equal(10)
690 expect(videoUpdated.categoryLabel).to.equal('Entertainment')
6f0c39e2
C
691 expect(videoUpdated.licence).to.equal(7)
692 expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication')
3092476e
C
693 expect(videoUpdated.language).to.equal(13)
694 expect(videoUpdated.languageLabel).to.equal('French')
31b59b47 695 expect(videoUpdated.nsfw).to.be.truthy
3d118fb5
C
696 expect(videoUpdated.description).to.equal('my super description updated')
697 expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
79066fdf 698 expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
3d118fb5 699
7f4e7c36
C
700 videosUtils.testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath, function (err, test) {
701 if (err) throw err
702 expect(test).to.equal(true)
703
704 webtorrent.add(videoUpdated.magnetUri, function (torrent) {
705 expect(torrent.files).to.exist
706 expect(torrent.files.length).to.equal(1)
707 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
708
790e65fc 709 callback()
7f4e7c36
C
710 })
711 })
3d118fb5
C
712 })
713 }, done)
714 })
8c308c2b 715
3d118fb5 716 it('Should remove the videos 3 and 3-2 by asking pod 3', function (done) {
9f10b292 717 this.timeout(15000)
0b697522 718
1a42c9e2 719 series([
9f10b292 720 function (next) {
3d118fb5 721 videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, next)
9f10b292
C
722 },
723 function (next) {
3d118fb5 724 videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id, next)
9f10b292
C
725 }],
726 function (err) {
0b697522 727 if (err) throw err
9f10b292
C
728 setTimeout(done, 11000)
729 }
730 )
731 })
0b697522 732
9f10b292 733 it('Should have videos 1 and 3 on each pod', function (done) {
1a42c9e2 734 each(servers, function (server, callback) {
8d309058 735 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292 736 if (err) throw err
0b697522 737
68ce3ae0 738 const videos = res.body.data
9f10b292
C
739 expect(videos).to.be.an('array')
740 expect(videos.length).to.equal(2)
3d118fb5
C
741 expect(videos[0].name).not.to.equal(videos[1].name)
742 expect(videos[0].name).not.to.equal(toRemove[0].name)
743 expect(videos[1].name).not.to.equal(toRemove[0].name)
744 expect(videos[0].name).not.to.equal(toRemove[1].name)
745 expect(videos[1].name).not.to.equal(toRemove[1].name)
0b697522 746
9f10b292 747 callback()
0b697522 748 })
9f10b292 749 }, done)
8c308c2b 750 })
9f10b292 751 })
e4c87ec2 752
9f10b292 753 after(function (done) {
0c1cbbfe
C
754 servers.forEach(function (server) {
755 process.kill(-server.app.pid)
8c308c2b 756 })
9f10b292
C
757
758 // Keep the logs if the test failed
759 if (this.ok) {
8d309058 760 serversUtils.flushTests(done)
9f10b292
C
761 } else {
762 done()
763 }
8c308c2b 764 })
9f10b292 765})