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