]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/multiple-pods.js
Begin user quota
[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 = []
0a6658fd 23 let videoUUID = ''
9f10b292
C
24
25 before(function (done) {
5fe7e898 26 this.timeout(120000)
9f10b292 27
1a42c9e2 28 series([
9f10b292
C
29 // Run servers
30 function (next) {
8d309058 31 serversUtils.flushAndRunMultipleServers(3, function (serversRun) {
bc503c2a 32 servers = serversRun
9f10b292
C
33 next()
34 })
35 },
0c1cbbfe
C
36 // Get the access tokens
37 function (next) {
1a42c9e2 38 each(servers, function (server, callbackEach) {
8d309058 39 loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
bc503c2a 40 if (err) return callbackEach(err)
0c1cbbfe 41
bc503c2a
C
42 server.accessToken = accessToken
43 callbackEach()
0c1cbbfe
C
44 })
45 }, next)
46 },
9f10b292
C
47 // The second pod make friend with the third
48 function (next) {
b3b92647 49 const server = servers[1]
8d309058 50 podsUtils.makeFriends(server.url, server.accessToken, next)
9f10b292
C
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) {
b3b92647 58 const server = servers[0]
8d309058 59 podsUtils.makeFriends(server.url, server.accessToken, next)
9f10b292
C
60 }
61 ], done)
62 })
8c308c2b 63
9f10b292 64 it('Should not have videos for all pods', function (done) {
1a42c9e2 65 each(servers, function (server, callback) {
8d309058 66 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292 67 if (err) throw err
8c308c2b 68
68ce3ae0
C
69 const videos = res.body.data
70 expect(videos).to.be.an('array')
71 expect(videos.length).to.equal(0)
8c308c2b 72
9f10b292
C
73 callback()
74 })
75 }, done)
76 })
8c308c2b 77
9f10b292
C
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) {
62326afb 80 // Pod 1 has video transcoding activated
9f10b292 81 this.timeout(15000)
8c308c2b 82
1a42c9e2 83 series([
ee66c593 84 function (next) {
b4c5ac97
C
85 const videoAttributes = {
86 name: 'my super name for pod 1',
6f0c39e2
C
87 category: 5,
88 licence: 4,
3092476e 89 language: 9,
31b59b47 90 nsfw: true,
b4c5ac97
C
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)
ee66c593 96 },
ee66c593 97 function (next) {
9f10b292
C
98 setTimeout(next, 11000)
99 }],
100 // All pods should have this video
101 function (err) {
102 if (err) throw err
103
1a42c9e2 104 each(servers, function (server, callback) {
bc503c2a 105 let baseMagnet = null
9f10b292 106
8d309058 107 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292
C
108 if (err) throw err
109
68ce3ae0 110 const videos = res.body.data
9f10b292
C
111 expect(videos).to.be.an('array')
112 expect(videos.length).to.equal(1)
f0f5567b 113 const video = videos[0]
9f10b292 114 expect(video.name).to.equal('my super name for pod 1')
6e07c3de
C
115 expect(video.category).to.equal(5)
116 expect(video.categoryLabel).to.equal('Sports')
6f0c39e2
C
117 expect(video.licence).to.equal(4)
118 expect(video.licenceLabel).to.equal('Attribution - Non Commercial')
3092476e
C
119 expect(video.language).to.equal(9)
120 expect(video.languageLabel).to.equal('Japanese')
69f22458 121 expect(video.nsfw).to.be.ok
9f10b292 122 expect(video.description).to.equal('my super description for pod 1')
a4254ea1 123 expect(video.podHost).to.equal('localhost:9001')
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
93e1258c
C
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
6d8ada5f
C
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
9f10b292 145 // All pods should have the same magnet Uri
bc503c2a 146 if (baseMagnet === null) {
93e1258c 147 baseMagnet = magnetUri
9f10b292 148 } else {
93e1258c 149 expect(baseMagnet).to.equal(magnetUri)
9f10b292
C
150 }
151
8d309058 152 videosUtils.testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath, function (err, test) {
9e5f3740
C
153 if (err) throw err
154 expect(test).to.equal(true)
155
156 callback()
157 })
9f10b292
C
158 })
159 }, done)
160 }
161 )
162 })
163
164 it('Should upload the video on pod 2 and propagate on each pod', function (done) {
945075ad 165 this.timeout(60000)
9f10b292 166
1a42c9e2 167 series([
ee66c593 168 function (next) {
b4c5ac97
C
169 const videoAttributes = {
170 name: 'my super name for pod 2',
171 category: 4,
6f0c39e2 172 licence: 3,
3092476e 173 language: 11,
31b59b47 174 nsfw: true,
b4c5ac97
C
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)
ee66c593
C
180 },
181 function (next) {
12028e7a
C
182 // Transcoding, so wait more that 22 seconds
183 setTimeout(next, 42000)
9f10b292
C
184 }],
185 // All pods should have this video
186 function (err) {
187 if (err) throw err
188
1a42c9e2 189 each(servers, function (server, callback) {
bc503c2a 190 let baseMagnet = null
9f10b292 191
8d309058 192 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292
C
193 if (err) throw err
194
68ce3ae0 195 const videos = res.body.data
9f10b292
C
196 expect(videos).to.be.an('array')
197 expect(videos.length).to.equal(2)
f0f5567b 198 const video = videos[1]
9f10b292 199 expect(video.name).to.equal('my super name for pod 2')
6e07c3de
C
200 expect(video.category).to.equal(4)
201 expect(video.categoryLabel).to.equal('Art')
6f0c39e2
C
202 expect(video.licence).to.equal(3)
203 expect(video.licenceLabel).to.equal('Attribution - No Derivatives')
3092476e
C
204 expect(video.language).to.equal(11)
205 expect(video.languageLabel).to.equal('German')
69f22458 206 expect(video.nsfw).to.be.true
9f10b292 207 expect(video.description).to.equal('my super description for pod 2')
a4254ea1 208 expect(video.podHost).to.equal('localhost:9002')
3a8a8b51 209 expect(video.duration).to.equal(5)
be587647 210 expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
feb4bdfd 211 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
79066fdf 212 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
528a9efa 213 expect(video.author).to.equal('root')
9f10b292 214
93e1258c
C
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
6d8ada5f
C
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
9f10b292 230 // All pods should have the same magnet Uri
bc503c2a 231 if (baseMagnet === null) {
93e1258c 232 baseMagnet = magnetUri
9f10b292 233 } else {
93e1258c 234 expect(baseMagnet).to.equal(magnetUri)
9f10b292
C
235 }
236
8d309058 237 videosUtils.testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath, function (err, test) {
9e5f3740
C
238 if (err) throw err
239 expect(test).to.equal(true)
240
241 callback()
242 })
9f10b292
C
243 })
244 }, done)
ee66c593 245 }
9f10b292 246 )
8c308c2b
C
247 })
248
9f10b292 249 it('Should upload two videos on pod 3 and propagate on each pod', function (done) {
5fe7e898 250 this.timeout(45000)
8c308c2b 251
1a42c9e2 252 series([
9f10b292 253 function (next) {
b4c5ac97
C
254 const videoAttributes = {
255 name: 'my super name for pod 3',
256 category: 6,
6f0c39e2 257 licence: 5,
3092476e 258 language: 11,
31b59b47 259 nsfw: true,
b4c5ac97
C
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)
9f10b292
C
265 },
266 function (next) {
b4c5ac97
C
267 const videoAttributes = {
268 name: 'my super name for pod 3-2',
269 category: 7,
6f0c39e2 270 licence: 6,
3092476e 271 language: 12,
31b59b47 272 nsfw: false,
b4c5ac97
C
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)
9f10b292
C
278 },
279 function (next) {
5fe7e898 280 setTimeout(next, 33000)
9f10b292
C
281 }],
282 function (err) {
283 if (err) throw err
8c308c2b 284
bc503c2a 285 let baseMagnet = null
9f10b292 286 // All pods should have this video
1a42c9e2 287 each(servers, function (server, callback) {
8d309058 288 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292
C
289 if (err) throw err
290
68ce3ae0 291 const videos = res.body.data
9f10b292
C
292 expect(videos).to.be.an('array')
293 expect(videos.length).to.equal(4)
3a8a8b51 294
cbe2f7c3
C
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
6d8ada5f 306 expect(video1.name).to.equal('my super name for pod 3')
6e07c3de
C
307 expect(video1.category).to.equal(6)
308 expect(video1.categoryLabel).to.equal('Travels')
6f0c39e2
C
309 expect(video1.licence).to.equal(5)
310 expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike')
3092476e
C
311 expect(video1.language).to.equal(11)
312 expect(video1.languageLabel).to.equal('German')
69f22458 313 expect(video1.nsfw).to.be.ok
6d8ada5f 314 expect(video1.description).to.equal('my super description for pod 3')
a4254ea1 315 expect(video1.podHost).to.equal('localhost:9003')
3a8a8b51 316 expect(video1.duration).to.equal(5)
be587647 317 expect(video1.tags).to.deep.equal([ 'tag1p3' ])
528a9efa 318 expect(video1.author).to.equal('root')
feb4bdfd 319 expect(miscsUtils.dateIsValid(video1.createdAt)).to.be.true
79066fdf 320 expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true
6d8ada5f 321
93e1258c
C
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
6d8ada5f 331 expect(video2.name).to.equal('my super name for pod 3-2')
6e07c3de
C
332 expect(video2.category).to.equal(7)
333 expect(video2.categoryLabel).to.equal('Gaming')
6f0c39e2
C
334 expect(video2.licence).to.equal(6)
335 expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
3092476e
C
336 expect(video2.language).to.equal(12)
337 expect(video2.languageLabel).to.equal('Korean')
69f22458 338 expect(video2.nsfw).to.be.false
6d8ada5f 339 expect(video2.description).to.equal('my super description for pod 3-2')
a4254ea1 340 expect(video2.podHost).to.equal('localhost:9003')
3a8a8b51 341 expect(video2.duration).to.equal(5)
be587647 342 expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
528a9efa 343 expect(video2.author).to.equal('root')
feb4bdfd 344 expect(miscsUtils.dateIsValid(video2.createdAt)).to.be.true
79066fdf 345 expect(miscsUtils.dateIsValid(video2.updatedAt)).to.be.true
6d8ada5f 346
93e1258c
C
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
6d8ada5f
C
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 }
9f10b292
C
363
364 // All pods should have the same magnet Uri
bc503c2a 365 if (baseMagnet === null) {
93e1258c 366 baseMagnet = magnetUri2
9f10b292 367 } else {
93e1258c 368 expect(baseMagnet).to.equal(magnetUri2)
9f10b292
C
369 }
370
8d309058 371 videosUtils.testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath, function (err, test) {
9e5f3740
C
372 if (err) throw err
373 expect(test).to.equal(true)
374
8d309058 375 videosUtils.testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath, function (err, test) {
9e5f3740
C
376 if (err) throw err
377 expect(test).to.equal(true)
378
379 callback()
380 })
381 })
9f10b292
C
382 })
383 }, done)
384 }
385 )
8c308c2b 386 })
9f10b292 387 })
8c308c2b 388
9f10b292
C
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)
8c308c2b 393
8d309058 394 videosUtils.getVideosList(servers[2].url, function (err, res) {
9f10b292 395 if (err) throw err
8c308c2b 396
68ce3ae0 397 const video = res.body.data[0]
3d118fb5
C
398 toRemove.push(res.body.data[2])
399 toRemove.push(res.body.data[3])
8c308c2b 400
93e1258c 401 webtorrent.add(video.files[0].magnetUri, function (torrent) {
9f10b292
C
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('')
8c308c2b 405
790e65fc 406 done()
9f10b292 407 })
8c308c2b
C
408 })
409 })
410
9f10b292
C
411 it('Should add the file 2 by asking pod 1', function (done) {
412 // Yes, this could be long
413 this.timeout(200000)
8c308c2b 414
8d309058 415 videosUtils.getVideosList(servers[0].url, function (err, res) {
9f10b292 416 if (err) throw err
8c308c2b 417
68ce3ae0 418 const video = res.body.data[1]
0b697522 419
93e1258c 420 webtorrent.add(video.files[0].magnetUri, function (torrent) {
9f10b292
C
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('')
8c308c2b 424
790e65fc 425 done()
8c308c2b
C
426 })
427 })
9f10b292 428 })
8c308c2b 429
9f10b292
C
430 it('Should add the file 3 by asking pod 2', function (done) {
431 // Yes, this could be long
432 this.timeout(200000)
8c308c2b 433
8d309058 434 videosUtils.getVideosList(servers[1].url, function (err, res) {
9f10b292 435 if (err) throw err
8c308c2b 436
68ce3ae0 437 const video = res.body.data[2]
8c308c2b 438
93e1258c 439 webtorrent.add(video.files[0].magnetUri, function (torrent) {
9f10b292
C
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('')
8c308c2b 443
790e65fc 444 done()
8c308c2b
C
445 })
446 })
9f10b292 447 })
8c308c2b 448
9f10b292
C
449 it('Should add the file 3-2 by asking pod 1', function (done) {
450 // Yes, this could be long
451 this.timeout(200000)
8c308c2b 452
8d309058 453 videosUtils.getVideosList(servers[0].url, function (err, res) {
9f10b292 454 if (err) throw err
8c308c2b 455
68ce3ae0 456 const video = res.body.data[3]
8c308c2b 457
93e1258c 458 webtorrent.add(video.files[0].magnetUri, function (torrent) {
9f10b292
C
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('')
8c308c2b 462
790e65fc 463 done()
8c308c2b
C
464 })
465 })
9f10b292 466 })
3d118fb5
C
467 })
468
d38b8281 469 describe('Should update video views, likes and dislikes', function () {
e4c87ec2
C
470 let localVideosPod3 = []
471 let remoteVideosPod1 = []
472 let remoteVideosPod2 = []
473 let remoteVideosPod3 = []
9e167724
C
474
475 before(function (done) {
e4c87ec2
C
476 parallel([
477 function (callback) {
478 videosUtils.getVideosList(servers[0].url, function (err, res) {
479 if (err) throw err
9e167724 480
e4c87ec2 481 remoteVideosPod1 = res.body.data.filter(video => video.isLocal === false).map(video => video.id)
9e167724 482
e4c87ec2
C
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)
9e167724
C
508 })
509
d38b8281 510 it('Should view multiple videos on owned servers', function (done) {
9e167724
C
511 this.timeout(30000)
512
513 parallel([
514 function (callback) {
e4c87ec2 515 videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
9e167724
C
516 },
517
518 function (callback) {
e4c87ec2 519 videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
9e167724
C
520 },
521
522 function (callback) {
e4c87ec2 523 videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
9e167724
C
524 },
525
526 function (callback) {
e4c87ec2
C
527 videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
528 },
529
530 function (callback) {
d38b8281 531 setTimeout(callback, 22000)
9e167724
C
532 }
533 ], function (err) {
534 if (err) throw err
535
d38b8281 536 eachSeries(servers, function (server, callback) {
e4c87ec2
C
537 videosUtils.getVideosList(server.url, function (err, res) {
538 if (err) throw err
539
540 const videos = res.body.data
d38b8281
C
541 expect(videos.find(video => video.views === 3)).to.exist
542 expect(videos.find(video => video.views === 1)).to.exist
e4c87ec2
C
543
544 callback()
545 })
546 }, done)
9e167724
C
547 })
548 })
549
d38b8281 550 it('Should view multiple videos on each servers', function (done) {
e4c87ec2 551 this.timeout(30000)
9e167724 552
e4c87ec2
C
553 parallel([
554 function (callback) {
555 videosUtils.getVideo(servers[0].url, remoteVideosPod1[0], callback)
556 },
9e167724 557
e4c87ec2
C
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) {
d38b8281 595 setTimeout(callback, 22000)
e4c87ec2
C
596 }
597 ], function (err) {
598 if (err) throw err
599
600 let baseVideos = null
d38b8281 601 eachSeries(servers, function (server, callback) {
e4c87ec2
C
602 videosUtils.getVideosList(server.url, function (err, res) {
603 if (err) throw err
604
d38b8281 605 const videos = res.body.data
e4c87ec2
C
606
607 // Initialize base videos for future comparisons
608 if (baseVideos === null) {
609 baseVideos = videos
610 return callback()
611 }
612
d38b8281
C
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()
e4c87ec2
C
673 }
674
d38b8281
C
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
e4c87ec2
C
681 callback()
682 })
683 }, done)
684 })
9e167724
C
685 })
686 })
e4c87ec2 687
3d118fb5
C
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
b4c5ac97
C
692 const attributes = {
693 name: 'my super video updated',
694 category: 10,
6f0c39e2 695 licence: 7,
3092476e 696 language: 13,
31b59b47 697 nsfw: true,
b4c5ac97
C
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) {
3d118fb5
C
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) {
7f4e7c36
C
709 this.timeout(200000)
710
3d118fb5 711 each(servers, function (server, callback) {
7f4e7c36
C
712 // Avoid "duplicate torrent" errors
713 const webtorrent = new WebTorrent()
714
3d118fb5
C
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
6e07c3de
C
724 expect(videoUpdated.category).to.equal(10)
725 expect(videoUpdated.categoryLabel).to.equal('Entertainment')
6f0c39e2
C
726 expect(videoUpdated.licence).to.equal(7)
727 expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication')
3092476e
C
728 expect(videoUpdated.language).to.equal(13)
729 expect(videoUpdated.languageLabel).to.equal('French')
69f22458 730 expect(videoUpdated.nsfw).to.be.ok
3d118fb5
C
731 expect(videoUpdated.description).to.equal('my super description updated')
732 expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
79066fdf 733 expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
3d118fb5 734
93e1258c
C
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
7f4e7c36
C
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
93e1258c 746 webtorrent.add(videoUpdated.files[0].magnetUri, function (torrent) {
7f4e7c36
C
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
790e65fc 751 callback()
7f4e7c36
C
752 })
753 })
3d118fb5
C
754 })
755 }, done)
756 })
8c308c2b 757
3d118fb5 758 it('Should remove the videos 3 and 3-2 by asking pod 3', function (done) {
9f10b292 759 this.timeout(15000)
0b697522 760
1a42c9e2 761 series([
9f10b292 762 function (next) {
3d118fb5 763 videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, next)
9f10b292
C
764 },
765 function (next) {
3d118fb5 766 videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id, next)
9f10b292
C
767 }],
768 function (err) {
0b697522 769 if (err) throw err
9f10b292
C
770 setTimeout(done, 11000)
771 }
772 )
773 })
0b697522 774
9f10b292 775 it('Should have videos 1 and 3 on each pod', function (done) {
1a42c9e2 776 each(servers, function (server, callback) {
8d309058 777 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292 778 if (err) throw err
0b697522 779
68ce3ae0 780 const videos = res.body.data
9f10b292
C
781 expect(videos).to.be.an('array')
782 expect(videos.length).to.equal(2)
3d118fb5
C
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)
0b697522 788
f981dae8 789 videoUUID = videos.find(video => video.name === 'my super name for pod 1').uuid
0a6658fd
C
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
9f10b292 819 callback()
0b697522 820 })
9f10b292 821 }, done)
8c308c2b 822 })
f981dae8
C
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 })
9f10b292 840 })
e4c87ec2 841
9f10b292 842 after(function (done) {
0c1cbbfe
C
843 servers.forEach(function (server) {
844 process.kill(-server.app.pid)
8c308c2b 845 })
9f10b292
C
846
847 // Keep the logs if the test failed
848 if (this.ok) {
8d309058 849 serversUtils.flushTests(done)
9f10b292
C
850 } else {
851 done()
852 }
8c308c2b 853 })
9f10b292 854})