]>
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 = [] |
0a6658fd | 23 | let videoUUID = '' |
9f10b292 C |
24 | |
25 | before(function (done) { | |
5fe7e898 | 26 | this.timeout(120000) |
9f10b292 | 27 | |
1a42c9e2 | 28 | series([ |
9f10b292 C |
29 | // Run servers |
30 | function (next) { | |
8d309058 | 31 | serversUtils.flushAndRunMultipleServers(3, function (serversRun) { |
bc503c2a | 32 | servers = serversRun |
9f10b292 C |
33 | next() |
34 | }) | |
35 | }, | |
0c1cbbfe C |
36 | // Get the access tokens |
37 | function (next) { | |
1a42c9e2 | 38 | each(servers, function (server, callbackEach) { |
8d309058 | 39 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { |
bc503c2a | 40 | if (err) return callbackEach(err) |
0c1cbbfe | 41 | |
bc503c2a C |
42 | server.accessToken = accessToken |
43 | callbackEach() | |
0c1cbbfe C |
44 | }) |
45 | }, next) | |
46 | }, | |
9f10b292 C |
47 | // The second pod make friend with the third |
48 | function (next) { | |
b3b92647 | 49 | const server = servers[1] |
8d309058 | 50 | podsUtils.makeFriends(server.url, server.accessToken, next) |
9f10b292 C |
51 | }, |
52 | // Wait for the request between pods | |
53 | function (next) { | |
54 | setTimeout(next, 10000) | |
55 | }, | |
56 | // Pod 1 make friends too | |
57 | function (next) { | |
b3b92647 | 58 | const server = servers[0] |
8d309058 | 59 | podsUtils.makeFriends(server.url, server.accessToken, next) |
9f10b292 C |
60 | } |
61 | ], done) | |
62 | }) | |
8c308c2b | 63 | |
9f10b292 | 64 | it('Should not have videos for all pods', function (done) { |
1a42c9e2 | 65 | each(servers, function (server, callback) { |
8d309058 | 66 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 | 67 | if (err) throw err |
8c308c2b | 68 | |
68ce3ae0 C |
69 | const videos = res.body.data |
70 | expect(videos).to.be.an('array') | |
71 | expect(videos.length).to.equal(0) | |
8c308c2b | 72 | |
9f10b292 C |
73 | callback() |
74 | }) | |
75 | }, done) | |
76 | }) | |
8c308c2b | 77 | |
9f10b292 C |
78 | describe('Should upload the video and propagate on each pod', function () { |
79 | it('Should upload the video on pod 1 and propagate on each pod', function (done) { | |
62326afb | 80 | // Pod 1 has video transcoding activated |
9f10b292 | 81 | this.timeout(15000) |
8c308c2b | 82 | |
1a42c9e2 | 83 | series([ |
ee66c593 | 84 | function (next) { |
b4c5ac97 C |
85 | const videoAttributes = { |
86 | name: 'my super name for pod 1', | |
6f0c39e2 C |
87 | category: 5, |
88 | licence: 4, | |
3092476e | 89 | language: 9, |
31b59b47 | 90 | nsfw: true, |
b4c5ac97 C |
91 | description: 'my super description for pod 1', |
92 | tags: [ 'tag1p1', 'tag2p1' ], | |
93 | fixture: 'video_short1.webm' | |
94 | } | |
95 | videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes, next) | |
ee66c593 | 96 | }, |
ee66c593 | 97 | function (next) { |
9f10b292 C |
98 | setTimeout(next, 11000) |
99 | }], | |
100 | // All pods should have this video | |
101 | function (err) { | |
102 | if (err) throw err | |
103 | ||
1a42c9e2 | 104 | each(servers, function (server, callback) { |
bc503c2a | 105 | let baseMagnet = null |
9f10b292 | 106 | |
8d309058 | 107 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 C |
108 | if (err) throw err |
109 | ||
68ce3ae0 | 110 | const videos = res.body.data |
9f10b292 C |
111 | expect(videos).to.be.an('array') |
112 | expect(videos.length).to.equal(1) | |
f0f5567b | 113 | const video = videos[0] |
9f10b292 | 114 | expect(video.name).to.equal('my super name for pod 1') |
6e07c3de C |
115 | expect(video.category).to.equal(5) |
116 | expect(video.categoryLabel).to.equal('Sports') | |
6f0c39e2 C |
117 | expect(video.licence).to.equal(4) |
118 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial') | |
3092476e C |
119 | expect(video.language).to.equal(9) |
120 | expect(video.languageLabel).to.equal('Japanese') | |
31b59b47 | 121 | expect(video.nsfw).to.be.truthy |
9f10b292 | 122 | expect(video.description).to.equal('my super description for pod 1') |
a4254ea1 | 123 | expect(video.podHost).to.equal('localhost:9001') |
9f10b292 | 124 | expect(video.magnetUri).to.exist |
3a8a8b51 | 125 | expect(video.duration).to.equal(10) |
be587647 | 126 | expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) |
feb4bdfd | 127 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
79066fdf | 128 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
528a9efa | 129 | expect(video.author).to.equal('root') |
9f10b292 | 130 | |
6d8ada5f C |
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 | ||
9f10b292 | 137 | // All pods should have the same magnet Uri |
bc503c2a C |
138 | if (baseMagnet === null) { |
139 | baseMagnet = video.magnetUri | |
9f10b292 C |
140 | } else { |
141 | expect(video.magnetUri).to.equal.magnetUri | |
142 | } | |
143 | ||
8d309058 | 144 | videosUtils.testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
145 | if (err) throw err |
146 | expect(test).to.equal(true) | |
147 | ||
148 | callback() | |
149 | }) | |
9f10b292 C |
150 | }) |
151 | }, done) | |
152 | } | |
153 | ) | |
154 | }) | |
155 | ||
156 | it('Should upload the video on pod 2 and propagate on each pod', function (done) { | |
945075ad | 157 | this.timeout(60000) |
9f10b292 | 158 | |
1a42c9e2 | 159 | series([ |
ee66c593 | 160 | function (next) { |
b4c5ac97 C |
161 | const videoAttributes = { |
162 | name: 'my super name for pod 2', | |
163 | category: 4, | |
6f0c39e2 | 164 | licence: 3, |
3092476e | 165 | language: 11, |
31b59b47 | 166 | nsfw: true, |
b4c5ac97 C |
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) | |
ee66c593 C |
172 | }, |
173 | function (next) { | |
12028e7a C |
174 | // Transcoding, so wait more that 22 seconds |
175 | setTimeout(next, 42000) | |
9f10b292 C |
176 | }], |
177 | // All pods should have this video | |
178 | function (err) { | |
179 | if (err) throw err | |
180 | ||
1a42c9e2 | 181 | each(servers, function (server, callback) { |
bc503c2a | 182 | let baseMagnet = null |
9f10b292 | 183 | |
8d309058 | 184 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 C |
185 | if (err) throw err |
186 | ||
68ce3ae0 | 187 | const videos = res.body.data |
9f10b292 C |
188 | expect(videos).to.be.an('array') |
189 | expect(videos.length).to.equal(2) | |
f0f5567b | 190 | const video = videos[1] |
9f10b292 | 191 | expect(video.name).to.equal('my super name for pod 2') |
6e07c3de C |
192 | expect(video.category).to.equal(4) |
193 | expect(video.categoryLabel).to.equal('Art') | |
6f0c39e2 C |
194 | expect(video.licence).to.equal(3) |
195 | expect(video.licenceLabel).to.equal('Attribution - No Derivatives') | |
3092476e C |
196 | expect(video.language).to.equal(11) |
197 | expect(video.languageLabel).to.equal('German') | |
31b59b47 | 198 | expect(video.nsfw).to.be.falsy |
9f10b292 | 199 | expect(video.description).to.equal('my super description for pod 2') |
a4254ea1 | 200 | expect(video.podHost).to.equal('localhost:9002') |
9f10b292 | 201 | expect(video.magnetUri).to.exist |
3a8a8b51 | 202 | expect(video.duration).to.equal(5) |
be587647 | 203 | expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) |
feb4bdfd | 204 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
79066fdf | 205 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
528a9efa | 206 | expect(video.author).to.equal('root') |
9f10b292 | 207 | |
6d8ada5f C |
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 | ||
9f10b292 | 214 | // All pods should have the same magnet Uri |
bc503c2a C |
215 | if (baseMagnet === null) { |
216 | baseMagnet = video.magnetUri | |
9f10b292 C |
217 | } else { |
218 | expect(video.magnetUri).to.equal.magnetUri | |
219 | } | |
220 | ||
8d309058 | 221 | videosUtils.testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
222 | if (err) throw err |
223 | expect(test).to.equal(true) | |
224 | ||
225 | callback() | |
226 | }) | |
9f10b292 C |
227 | }) |
228 | }, done) | |
ee66c593 | 229 | } |
9f10b292 | 230 | ) |
8c308c2b C |
231 | }) |
232 | ||
9f10b292 | 233 | it('Should upload two videos on pod 3 and propagate on each pod', function (done) { |
5fe7e898 | 234 | this.timeout(45000) |
8c308c2b | 235 | |
1a42c9e2 | 236 | series([ |
9f10b292 | 237 | function (next) { |
b4c5ac97 C |
238 | const videoAttributes = { |
239 | name: 'my super name for pod 3', | |
240 | category: 6, | |
6f0c39e2 | 241 | licence: 5, |
3092476e | 242 | language: 11, |
31b59b47 | 243 | nsfw: true, |
b4c5ac97 C |
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) | |
9f10b292 C |
249 | }, |
250 | function (next) { | |
b4c5ac97 C |
251 | const videoAttributes = { |
252 | name: 'my super name for pod 3-2', | |
253 | category: 7, | |
6f0c39e2 | 254 | licence: 6, |
3092476e | 255 | language: 12, |
31b59b47 | 256 | nsfw: false, |
b4c5ac97 C |
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) | |
9f10b292 C |
262 | }, |
263 | function (next) { | |
5fe7e898 | 264 | setTimeout(next, 33000) |
9f10b292 C |
265 | }], |
266 | function (err) { | |
267 | if (err) throw err | |
8c308c2b | 268 | |
bc503c2a | 269 | let baseMagnet = null |
9f10b292 | 270 | // All pods should have this video |
1a42c9e2 | 271 | each(servers, function (server, callback) { |
8d309058 | 272 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 C |
273 | if (err) throw err |
274 | ||
68ce3ae0 | 275 | const videos = res.body.data |
9f10b292 C |
276 | expect(videos).to.be.an('array') |
277 | expect(videos.length).to.equal(4) | |
3a8a8b51 | 278 | |
cbe2f7c3 C |
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 | ||
6d8ada5f | 290 | expect(video1.name).to.equal('my super name for pod 3') |
6e07c3de C |
291 | expect(video1.category).to.equal(6) |
292 | expect(video1.categoryLabel).to.equal('Travels') | |
6f0c39e2 C |
293 | expect(video1.licence).to.equal(5) |
294 | expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike') | |
3092476e C |
295 | expect(video1.language).to.equal(11) |
296 | expect(video1.languageLabel).to.equal('German') | |
31b59b47 | 297 | expect(video1.nsfw).to.be.truthy |
6d8ada5f | 298 | expect(video1.description).to.equal('my super description for pod 3') |
a4254ea1 | 299 | expect(video1.podHost).to.equal('localhost:9003') |
6d8ada5f | 300 | expect(video1.magnetUri).to.exist |
3a8a8b51 | 301 | expect(video1.duration).to.equal(5) |
be587647 | 302 | expect(video1.tags).to.deep.equal([ 'tag1p3' ]) |
528a9efa | 303 | expect(video1.author).to.equal('root') |
feb4bdfd | 304 | expect(miscsUtils.dateIsValid(video1.createdAt)).to.be.true |
79066fdf | 305 | expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true |
6d8ada5f | 306 | |
6d8ada5f | 307 | expect(video2.name).to.equal('my super name for pod 3-2') |
6e07c3de C |
308 | expect(video2.category).to.equal(7) |
309 | expect(video2.categoryLabel).to.equal('Gaming') | |
6f0c39e2 C |
310 | expect(video2.licence).to.equal(6) |
311 | expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | |
3092476e C |
312 | expect(video2.language).to.equal(12) |
313 | expect(video2.languageLabel).to.equal('Korean') | |
31b59b47 | 314 | expect(video2.nsfw).to.be.falsy |
6d8ada5f | 315 | expect(video2.description).to.equal('my super description for pod 3-2') |
a4254ea1 | 316 | expect(video2.podHost).to.equal('localhost:9003') |
6d8ada5f | 317 | expect(video2.magnetUri).to.exist |
3a8a8b51 | 318 | expect(video2.duration).to.equal(5) |
be587647 | 319 | expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) |
528a9efa | 320 | expect(video2.author).to.equal('root') |
feb4bdfd | 321 | expect(miscsUtils.dateIsValid(video2.createdAt)).to.be.true |
79066fdf | 322 | expect(miscsUtils.dateIsValid(video2.updatedAt)).to.be.true |
6d8ada5f C |
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 | } | |
9f10b292 C |
331 | |
332 | // All pods should have the same magnet Uri | |
bc503c2a C |
333 | if (baseMagnet === null) { |
334 | baseMagnet = video2.magnetUri | |
9f10b292 | 335 | } else { |
6d8ada5f | 336 | expect(video2.magnetUri).to.equal.magnetUri |
9f10b292 C |
337 | } |
338 | ||
8d309058 | 339 | videosUtils.testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath, function (err, test) { |
9e5f3740 C |
340 | if (err) throw err |
341 | expect(test).to.equal(true) | |
342 | ||
8d309058 | 343 | videosUtils.testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath, function (err, test) { |
9e5f3740 C |
344 | if (err) throw err |
345 | expect(test).to.equal(true) | |
346 | ||
347 | callback() | |
348 | }) | |
349 | }) | |
9f10b292 C |
350 | }) |
351 | }, done) | |
352 | } | |
353 | ) | |
8c308c2b | 354 | }) |
9f10b292 | 355 | }) |
8c308c2b | 356 | |
9f10b292 C |
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) | |
8c308c2b | 361 | |
8d309058 | 362 | videosUtils.getVideosList(servers[2].url, function (err, res) { |
9f10b292 | 363 | if (err) throw err |
8c308c2b | 364 | |
68ce3ae0 | 365 | const video = res.body.data[0] |
3d118fb5 C |
366 | toRemove.push(res.body.data[2]) |
367 | toRemove.push(res.body.data[3]) | |
8c308c2b | 368 | |
9f10b292 C |
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('') | |
8c308c2b | 373 | |
790e65fc | 374 | done() |
9f10b292 | 375 | }) |
8c308c2b C |
376 | }) |
377 | }) | |
378 | ||
9f10b292 C |
379 | it('Should add the file 2 by asking pod 1', function (done) { |
380 | // Yes, this could be long | |
381 | this.timeout(200000) | |
8c308c2b | 382 | |
8d309058 | 383 | videosUtils.getVideosList(servers[0].url, function (err, res) { |
9f10b292 | 384 | if (err) throw err |
8c308c2b | 385 | |
68ce3ae0 | 386 | const video = res.body.data[1] |
0b697522 | 387 | |
9f10b292 C |
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('') | |
8c308c2b | 392 | |
790e65fc | 393 | done() |
8c308c2b C |
394 | }) |
395 | }) | |
9f10b292 | 396 | }) |
8c308c2b | 397 | |
9f10b292 C |
398 | it('Should add the file 3 by asking pod 2', function (done) { |
399 | // Yes, this could be long | |
400 | this.timeout(200000) | |
8c308c2b | 401 | |
8d309058 | 402 | videosUtils.getVideosList(servers[1].url, function (err, res) { |
9f10b292 | 403 | if (err) throw err |
8c308c2b | 404 | |
68ce3ae0 | 405 | const video = res.body.data[2] |
8c308c2b | 406 | |
9f10b292 C |
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('') | |
8c308c2b | 411 | |
790e65fc | 412 | done() |
8c308c2b C |
413 | }) |
414 | }) | |
9f10b292 | 415 | }) |
8c308c2b | 416 | |
9f10b292 C |
417 | it('Should add the file 3-2 by asking pod 1', function (done) { |
418 | // Yes, this could be long | |
419 | this.timeout(200000) | |
8c308c2b | 420 | |
8d309058 | 421 | videosUtils.getVideosList(servers[0].url, function (err, res) { |
9f10b292 | 422 | if (err) throw err |
8c308c2b | 423 | |
68ce3ae0 | 424 | const video = res.body.data[3] |
8c308c2b | 425 | |
9f10b292 C |
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('') | |
8c308c2b | 430 | |
790e65fc | 431 | done() |
8c308c2b C |
432 | }) |
433 | }) | |
9f10b292 | 434 | }) |
3d118fb5 C |
435 | }) |
436 | ||
d38b8281 | 437 | describe('Should update video views, likes and dislikes', function () { |
e4c87ec2 C |
438 | let localVideosPod3 = [] |
439 | let remoteVideosPod1 = [] | |
440 | let remoteVideosPod2 = [] | |
441 | let remoteVideosPod3 = [] | |
9e167724 C |
442 | |
443 | before(function (done) { | |
e4c87ec2 C |
444 | parallel([ |
445 | function (callback) { | |
446 | videosUtils.getVideosList(servers[0].url, function (err, res) { | |
447 | if (err) throw err | |
9e167724 | 448 | |
e4c87ec2 | 449 | remoteVideosPod1 = res.body.data.filter(video => video.isLocal === false).map(video => video.id) |
9e167724 | 450 | |
e4c87ec2 C |
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) | |
9e167724 C |
476 | }) |
477 | ||
d38b8281 | 478 | it('Should view multiple videos on owned servers', function (done) { |
9e167724 C |
479 | this.timeout(30000) |
480 | ||
481 | parallel([ | |
482 | function (callback) { | |
e4c87ec2 | 483 | videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback) |
9e167724 C |
484 | }, |
485 | ||
486 | function (callback) { | |
e4c87ec2 | 487 | videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback) |
9e167724 C |
488 | }, |
489 | ||
490 | function (callback) { | |
e4c87ec2 | 491 | videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback) |
9e167724 C |
492 | }, |
493 | ||
494 | function (callback) { | |
e4c87ec2 C |
495 | videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback) |
496 | }, | |
497 | ||
498 | function (callback) { | |
d38b8281 | 499 | setTimeout(callback, 22000) |
9e167724 C |
500 | } |
501 | ], function (err) { | |
502 | if (err) throw err | |
503 | ||
d38b8281 | 504 | eachSeries(servers, function (server, callback) { |
e4c87ec2 C |
505 | videosUtils.getVideosList(server.url, function (err, res) { |
506 | if (err) throw err | |
507 | ||
508 | const videos = res.body.data | |
d38b8281 C |
509 | expect(videos.find(video => video.views === 3)).to.exist |
510 | expect(videos.find(video => video.views === 1)).to.exist | |
e4c87ec2 C |
511 | |
512 | callback() | |
513 | }) | |
514 | }, done) | |
9e167724 C |
515 | }) |
516 | }) | |
517 | ||
d38b8281 | 518 | it('Should view multiple videos on each servers', function (done) { |
e4c87ec2 | 519 | this.timeout(30000) |
9e167724 | 520 | |
e4c87ec2 C |
521 | parallel([ |
522 | function (callback) { | |
523 | videosUtils.getVideo(servers[0].url, remoteVideosPod1[0], callback) | |
524 | }, | |
9e167724 | 525 | |
e4c87ec2 C |
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) { | |
d38b8281 | 563 | setTimeout(callback, 22000) |
e4c87ec2 C |
564 | } |
565 | ], function (err) { | |
566 | if (err) throw err | |
567 | ||
568 | let baseVideos = null | |
d38b8281 | 569 | eachSeries(servers, function (server, callback) { |
e4c87ec2 C |
570 | videosUtils.getVideosList(server.url, function (err, res) { |
571 | if (err) throw err | |
572 | ||
d38b8281 | 573 | const videos = res.body.data |
e4c87ec2 C |
574 | |
575 | // Initialize base videos for future comparisons | |
576 | if (baseVideos === null) { | |
577 | baseVideos = videos | |
578 | return callback() | |
579 | } | |
580 | ||
d38b8281 C |
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() | |
e4c87ec2 C |
641 | } |
642 | ||
d38b8281 C |
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 | ||
e4c87ec2 C |
649 | callback() |
650 | }) | |
651 | }, done) | |
652 | }) | |
9e167724 C |
653 | }) |
654 | }) | |
e4c87ec2 | 655 | |
3d118fb5 C |
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 | ||
b4c5ac97 C |
660 | const attributes = { |
661 | name: 'my super video updated', | |
662 | category: 10, | |
6f0c39e2 | 663 | licence: 7, |
3092476e | 664 | language: 13, |
31b59b47 | 665 | nsfw: true, |
b4c5ac97 C |
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) { | |
3d118fb5 C |
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) { | |
7f4e7c36 C |
677 | this.timeout(200000) |
678 | ||
3d118fb5 | 679 | each(servers, function (server, callback) { |
7f4e7c36 C |
680 | // Avoid "duplicate torrent" errors |
681 | const webtorrent = new WebTorrent() | |
682 | ||
3d118fb5 C |
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 | |
6e07c3de C |
692 | expect(videoUpdated.category).to.equal(10) |
693 | expect(videoUpdated.categoryLabel).to.equal('Entertainment') | |
6f0c39e2 C |
694 | expect(videoUpdated.licence).to.equal(7) |
695 | expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication') | |
3092476e C |
696 | expect(videoUpdated.language).to.equal(13) |
697 | expect(videoUpdated.languageLabel).to.equal('French') | |
31b59b47 | 698 | expect(videoUpdated.nsfw).to.be.truthy |
3d118fb5 C |
699 | expect(videoUpdated.description).to.equal('my super description updated') |
700 | expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) | |
79066fdf | 701 | expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true |
3d118fb5 | 702 | |
7f4e7c36 C |
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 | ||
790e65fc | 712 | callback() |
7f4e7c36 C |
713 | }) |
714 | }) | |
3d118fb5 C |
715 | }) |
716 | }, done) | |
717 | }) | |
8c308c2b | 718 | |
3d118fb5 | 719 | it('Should remove the videos 3 and 3-2 by asking pod 3', function (done) { |
9f10b292 | 720 | this.timeout(15000) |
0b697522 | 721 | |
1a42c9e2 | 722 | series([ |
9f10b292 | 723 | function (next) { |
3d118fb5 | 724 | videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, next) |
9f10b292 C |
725 | }, |
726 | function (next) { | |
3d118fb5 | 727 | videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id, next) |
9f10b292 C |
728 | }], |
729 | function (err) { | |
0b697522 | 730 | if (err) throw err |
9f10b292 C |
731 | setTimeout(done, 11000) |
732 | } | |
733 | ) | |
734 | }) | |
0b697522 | 735 | |
9f10b292 | 736 | it('Should have videos 1 and 3 on each pod', function (done) { |
1a42c9e2 | 737 | each(servers, function (server, callback) { |
8d309058 | 738 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 | 739 | if (err) throw err |
0b697522 | 740 | |
68ce3ae0 | 741 | const videos = res.body.data |
9f10b292 C |
742 | expect(videos).to.be.an('array') |
743 | expect(videos.length).to.equal(2) | |
3d118fb5 C |
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) | |
0b697522 | 749 | |
0a6658fd C |
750 | videoUUID = videos[0].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 | ||
9f10b292 | 780 | callback() |
0b697522 | 781 | }) |
9f10b292 | 782 | }, done) |
8c308c2b | 783 | }) |
9f10b292 | 784 | }) |
e4c87ec2 | 785 | |
9f10b292 | 786 | after(function (done) { |
0c1cbbfe C |
787 | servers.forEach(function (server) { |
788 | process.kill(-server.app.pid) | |
8c308c2b | 789 | }) |
9f10b292 C |
790 | |
791 | // Keep the logs if the test failed | |
792 | if (this.ok) { | |
8d309058 | 793 | serversUtils.flushTests(done) |
9f10b292 C |
794 | } else { |
795 | done() | |
796 | } | |
8c308c2b | 797 | }) |
9f10b292 | 798 | }) |