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