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