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