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