diff options
Diffstat (limited to 'server/tests/api/multiple-servers.ts')
-rw-r--r-- | server/tests/api/multiple-servers.ts | 722 |
1 files changed, 722 insertions, 0 deletions
diff --git a/server/tests/api/multiple-servers.ts b/server/tests/api/multiple-servers.ts new file mode 100644 index 000000000..737770992 --- /dev/null +++ b/server/tests/api/multiple-servers.ts | |||
@@ -0,0 +1,722 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | |||
6 | import { | ||
7 | dateIsValid, | ||
8 | flushAndRunMultipleServers, | ||
9 | flushTests, | ||
10 | getVideo, | ||
11 | getVideosList, | ||
12 | killallServers, | ||
13 | rateVideo, | ||
14 | removeVideo, | ||
15 | ServerInfo, | ||
16 | setAccessTokensToServers, | ||
17 | testVideoImage, | ||
18 | updateVideo, | ||
19 | uploadVideo, | ||
20 | wait, | ||
21 | webtorrentAdd, | ||
22 | addVideoChannel, | ||
23 | getVideoChannelsList, | ||
24 | getUserAccessToken, | ||
25 | doubleFollow | ||
26 | } from '../utils' | ||
27 | import { createUser } from '../utils/users' | ||
28 | |||
29 | const expect = chai.expect | ||
30 | |||
31 | describe('Test multiple servers', function () { | ||
32 | let servers: ServerInfo[] = [] | ||
33 | const toRemove = [] | ||
34 | let videoUUID = '' | ||
35 | let videoChannelId: number | ||
36 | |||
37 | before(async function () { | ||
38 | this.timeout(120000) | ||
39 | |||
40 | servers = await flushAndRunMultipleServers(3) | ||
41 | |||
42 | // Get the access tokens | ||
43 | await setAccessTokensToServers(servers) | ||
44 | |||
45 | const videoChannel = { | ||
46 | name: 'my channel', | ||
47 | description: 'super channel' | ||
48 | } | ||
49 | await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) | ||
50 | const channelRes = await getVideoChannelsList(servers[0].url, 0, 1) | ||
51 | videoChannelId = channelRes.body.data[0].id | ||
52 | |||
53 | // Server 1 and server 2 follow each other | ||
54 | await doubleFollow(servers[0], servers[1]) | ||
55 | // Server 1 and server 3 follow each other | ||
56 | await doubleFollow(servers[0], servers[2]) | ||
57 | // Server 2 and server 3 follow each other | ||
58 | await doubleFollow(servers[1], servers[2]) | ||
59 | }) | ||
60 | |||
61 | it('Should not have videos for all servers', async function () { | ||
62 | for (const server of servers) { | ||
63 | const res = await getVideosList(server.url) | ||
64 | const videos = res.body.data | ||
65 | expect(videos).to.be.an('array') | ||
66 | expect(videos.length).to.equal(0) | ||
67 | } | ||
68 | }) | ||
69 | |||
70 | describe('Should upload the video and propagate on each server', function () { | ||
71 | it('Should upload the video on server 1 and propagate on each server', async function () { | ||
72 | // Server 1 has video transcoding activated | ||
73 | this.timeout(15000) | ||
74 | |||
75 | const videoAttributes = { | ||
76 | name: 'my super name for server 1', | ||
77 | category: 5, | ||
78 | licence: 4, | ||
79 | language: 9, | ||
80 | nsfw: true, | ||
81 | description: 'my super description for server 1', | ||
82 | tags: [ 'tag1p1', 'tag2p1' ], | ||
83 | channelId: videoChannelId, | ||
84 | fixture: 'video_short1.webm' | ||
85 | } | ||
86 | await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | ||
87 | |||
88 | await wait(11000) | ||
89 | |||
90 | // All servers should have this video | ||
91 | for (const server of servers) { | ||
92 | let baseMagnet = null | ||
93 | |||
94 | const res = await getVideosList(server.url) | ||
95 | |||
96 | const videos = res.body.data | ||
97 | expect(videos).to.be.an('array') | ||
98 | expect(videos.length).to.equal(1) | ||
99 | const video = videos[0] | ||
100 | expect(video.name).to.equal('my super name for server 1') | ||
101 | expect(video.category).to.equal(5) | ||
102 | expect(video.categoryLabel).to.equal('Sports') | ||
103 | expect(video.licence).to.equal(4) | ||
104 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial') | ||
105 | expect(video.language).to.equal(9) | ||
106 | expect(video.languageLabel).to.equal('Japanese') | ||
107 | expect(video.nsfw).to.be.ok | ||
108 | expect(video.description).to.equal('my super description for server 1') | ||
109 | expect(video.serverHost).to.equal('localhost:9001') | ||
110 | expect(video.duration).to.equal(10) | ||
111 | expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) | ||
112 | expect(dateIsValid(video.createdAt)).to.be.true | ||
113 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
114 | expect(video.account).to.equal('root') | ||
115 | |||
116 | const res2 = await getVideo(server.url, video.uuid) | ||
117 | const videoDetails = res2.body | ||
118 | |||
119 | expect(videoDetails.channel.name).to.equal('my channel') | ||
120 | expect(videoDetails.channel.description).to.equal('super channel') | ||
121 | expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true | ||
122 | expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true | ||
123 | expect(videoDetails.files).to.have.lengthOf(1) | ||
124 | |||
125 | const file = videoDetails.files[0] | ||
126 | const magnetUri = file.magnetUri | ||
127 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
128 | expect(file.torrentUrl).to | ||
129 | .equal(`http://${videoDetails.serverHost}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`) | ||
130 | expect(file.fileUrl).to.equal(`http://${videoDetails.serverHost}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`) | ||
131 | expect(file.resolution).to.equal(720) | ||
132 | expect(file.resolutionLabel).to.equal('720p') | ||
133 | expect(file.size).to.equal(572456) | ||
134 | |||
135 | if (server.url !== 'http://localhost:9001') { | ||
136 | expect(video.isLocal).to.be.false | ||
137 | expect(videoDetails.channel.isLocal).to.be.false | ||
138 | } else { | ||
139 | expect(video.isLocal).to.be.true | ||
140 | expect(videoDetails.channel.isLocal).to.be.true | ||
141 | } | ||
142 | |||
143 | // All servers should have the same magnet Uri | ||
144 | if (baseMagnet === null) { | ||
145 | baseMagnet = magnetUri | ||
146 | } else { | ||
147 | expect(baseMagnet).to.equal(magnetUri) | ||
148 | } | ||
149 | |||
150 | const test = await testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath) | ||
151 | expect(test).to.equal(true) | ||
152 | } | ||
153 | }) | ||
154 | |||
155 | it('Should upload the video on server 2 and propagate on each server', async function () { | ||
156 | this.timeout(120000) | ||
157 | |||
158 | const user = { | ||
159 | username: 'user1', | ||
160 | password: 'super_password' | ||
161 | } | ||
162 | await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) | ||
163 | const userAccessToken = await getUserAccessToken(servers[1], user) | ||
164 | |||
165 | const videoAttributes = { | ||
166 | name: 'my super name for server 2', | ||
167 | category: 4, | ||
168 | licence: 3, | ||
169 | language: 11, | ||
170 | nsfw: true, | ||
171 | description: 'my super description for server 2', | ||
172 | tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], | ||
173 | fixture: 'video_short2.webm' | ||
174 | } | ||
175 | await uploadVideo(servers[1].url, userAccessToken, videoAttributes) | ||
176 | |||
177 | // Transcoding, so wait more than 22000 | ||
178 | await wait(60000) | ||
179 | |||
180 | // All servers should have this video | ||
181 | for (const server of servers) { | ||
182 | let baseMagnet = {} | ||
183 | |||
184 | const res = await getVideosList(server.url) | ||
185 | |||
186 | const videos = res.body.data | ||
187 | expect(videos).to.be.an('array') | ||
188 | expect(videos.length).to.equal(2) | ||
189 | const video = videos[1] | ||
190 | expect(video.name).to.equal('my super name for server 2') | ||
191 | expect(video.category).to.equal(4) | ||
192 | expect(video.categoryLabel).to.equal('Art') | ||
193 | expect(video.licence).to.equal(3) | ||
194 | expect(video.licenceLabel).to.equal('Attribution - No Derivatives') | ||
195 | expect(video.language).to.equal(11) | ||
196 | expect(video.languageLabel).to.equal('German') | ||
197 | expect(video.nsfw).to.be.true | ||
198 | expect(video.description).to.equal('my super description for server 2') | ||
199 | expect(video.serverHost).to.equal('localhost:9002') | ||
200 | expect(video.duration).to.equal(5) | ||
201 | expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) | ||
202 | expect(dateIsValid(video.createdAt)).to.be.true | ||
203 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
204 | expect(video.account).to.equal('user1') | ||
205 | |||
206 | if (server.url !== 'http://localhost:9002') { | ||
207 | expect(video.isLocal).to.be.false | ||
208 | } else { | ||
209 | expect(video.isLocal).to.be.true | ||
210 | } | ||
211 | |||
212 | const res2 = await getVideo(server.url, video.uuid) | ||
213 | const videoDetails = res2.body | ||
214 | |||
215 | expect(videoDetails.channel.name).to.equal('Default user1 channel') | ||
216 | expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true | ||
217 | expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true | ||
218 | |||
219 | expect(videoDetails.files).to.have.lengthOf(4) | ||
220 | |||
221 | // Check common attributes | ||
222 | for (const file of videoDetails.files) { | ||
223 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
224 | |||
225 | // All servers should have the same magnet Uri | ||
226 | if (baseMagnet[file.resolution] === undefined) { | ||
227 | baseMagnet[file.resolution] = file.magnet | ||
228 | } else { | ||
229 | expect(baseMagnet[file.resolution]).to.equal(file.magnet) | ||
230 | } | ||
231 | } | ||
232 | |||
233 | const file240p = videoDetails.files.find(f => f.resolution === 240) | ||
234 | expect(file240p).not.to.be.undefined | ||
235 | expect(file240p.resolutionLabel).to.equal('240p') | ||
236 | expect(file240p.size).to.be.above(180000).and.below(200000) | ||
237 | |||
238 | const file360p = videoDetails.files.find(f => f.resolution === 360) | ||
239 | expect(file360p).not.to.be.undefined | ||
240 | expect(file360p.resolutionLabel).to.equal('360p') | ||
241 | expect(file360p.size).to.be.above(270000).and.below(290000) | ||
242 | |||
243 | const file480p = videoDetails.files.find(f => f.resolution === 480) | ||
244 | expect(file480p).not.to.be.undefined | ||
245 | expect(file480p.resolutionLabel).to.equal('480p') | ||
246 | expect(file480p.size).to.be.above(380000).and.below(400000) | ||
247 | |||
248 | const file720p = videoDetails.files.find(f => f.resolution === 720) | ||
249 | expect(file720p).not.to.be.undefined | ||
250 | expect(file720p.resolutionLabel).to.equal('720p') | ||
251 | expect(file720p.size).to.be.above(700000).and.below(7200000) | ||
252 | |||
253 | const test = await testVideoImage(server.url, 'video_short2.webm', videoDetails.thumbnailPath) | ||
254 | expect(test).to.equal(true) | ||
255 | } | ||
256 | }) | ||
257 | |||
258 | it('Should upload two videos on server 3 and propagate on each server', async function () { | ||
259 | this.timeout(45000) | ||
260 | |||
261 | const videoAttributes1 = { | ||
262 | name: 'my super name for server 3', | ||
263 | category: 6, | ||
264 | licence: 5, | ||
265 | language: 11, | ||
266 | nsfw: true, | ||
267 | description: 'my super description for server 3', | ||
268 | tags: [ 'tag1p3' ], | ||
269 | fixture: 'video_short3.webm' | ||
270 | } | ||
271 | await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1) | ||
272 | |||
273 | const videoAttributes2 = { | ||
274 | name: 'my super name for server 3-2', | ||
275 | category: 7, | ||
276 | licence: 6, | ||
277 | language: 12, | ||
278 | nsfw: false, | ||
279 | description: 'my super description for server 3-2', | ||
280 | tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], | ||
281 | fixture: 'video_short.webm' | ||
282 | } | ||
283 | await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2) | ||
284 | |||
285 | await wait(33000) | ||
286 | |||
287 | let baseMagnet = null | ||
288 | // All servers should have this video | ||
289 | for (const server of servers) { | ||
290 | const res = await getVideosList(server.url) | ||
291 | |||
292 | const videos = res.body.data | ||
293 | expect(videos).to.be.an('array') | ||
294 | expect(videos.length).to.equal(4) | ||
295 | |||
296 | // We not sure about the order of the two last uploads | ||
297 | let video1 = null | ||
298 | let video2 = null | ||
299 | if (videos[2].name === 'my super name for server 3') { | ||
300 | video1 = videos[2] | ||
301 | video2 = videos[3] | ||
302 | } else { | ||
303 | video1 = videos[3] | ||
304 | video2 = videos[2] | ||
305 | } | ||
306 | |||
307 | expect(video1.name).to.equal('my super name for server 3') | ||
308 | expect(video1.category).to.equal(6) | ||
309 | expect(video1.categoryLabel).to.equal('Travels') | ||
310 | expect(video1.licence).to.equal(5) | ||
311 | expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike') | ||
312 | expect(video1.language).to.equal(11) | ||
313 | expect(video1.languageLabel).to.equal('German') | ||
314 | expect(video1.nsfw).to.be.ok | ||
315 | expect(video1.description).to.equal('my super description for server 3') | ||
316 | expect(video1.serverHost).to.equal('localhost:9003') | ||
317 | expect(video1.duration).to.equal(5) | ||
318 | expect(video1.tags).to.deep.equal([ 'tag1p3' ]) | ||
319 | expect(video1.author).to.equal('root') | ||
320 | expect(dateIsValid(video1.createdAt)).to.be.true | ||
321 | expect(dateIsValid(video1.updatedAt)).to.be.true | ||
322 | |||
323 | const res2 = await getVideo(server.url, video1.id) | ||
324 | const video1Details = res2.body | ||
325 | expect(video1Details.files).to.have.lengthOf(1) | ||
326 | |||
327 | const file1 = video1Details.files[0] | ||
328 | expect(file1.magnetUri).to.have.lengthOf.above(2) | ||
329 | expect(file1.resolution).to.equal(720) | ||
330 | expect(file1.resolutionLabel).to.equal('720p') | ||
331 | expect(file1.size).to.equal(292677) | ||
332 | |||
333 | expect(video2.name).to.equal('my super name for server 3-2') | ||
334 | expect(video2.category).to.equal(7) | ||
335 | expect(video2.categoryLabel).to.equal('Gaming') | ||
336 | expect(video2.licence).to.equal(6) | ||
337 | expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
338 | expect(video2.language).to.equal(12) | ||
339 | expect(video2.languageLabel).to.equal('Korean') | ||
340 | expect(video2.nsfw).to.be.false | ||
341 | expect(video2.description).to.equal('my super description for server 3-2') | ||
342 | expect(video2.serverHost).to.equal('localhost:9003') | ||
343 | expect(video2.duration).to.equal(5) | ||
344 | expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) | ||
345 | expect(video2.author).to.equal('root') | ||
346 | expect(dateIsValid(video2.createdAt)).to.be.true | ||
347 | expect(dateIsValid(video2.updatedAt)).to.be.true | ||
348 | |||
349 | const res3 = await getVideo(server.url, video2.id) | ||
350 | const video2Details = res3.body | ||
351 | |||
352 | expect(video2Details.files).to.have.lengthOf(1) | ||
353 | |||
354 | const file2 = video2Details.files[0] | ||
355 | const magnetUri2 = file2.magnetUri | ||
356 | expect(file2.magnetUri).to.have.lengthOf.above(2) | ||
357 | expect(file2.resolution).to.equal(720) | ||
358 | expect(file2.resolutionLabel).to.equal('720p') | ||
359 | expect(file2.size).to.equal(218910) | ||
360 | |||
361 | if (server.url !== 'http://localhost:9003') { | ||
362 | expect(video1.isLocal).to.be.false | ||
363 | expect(video2.isLocal).to.be.false | ||
364 | } else { | ||
365 | expect(video1.isLocal).to.be.true | ||
366 | expect(video2.isLocal).to.be.true | ||
367 | } | ||
368 | |||
369 | // All servers should have the same magnet Uri | ||
370 | if (baseMagnet === null) { | ||
371 | baseMagnet = magnetUri2 | ||
372 | } else { | ||
373 | expect(baseMagnet).to.equal(magnetUri2) | ||
374 | } | ||
375 | |||
376 | const test1 = await testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath) | ||
377 | expect(test1).to.equal(true) | ||
378 | |||
379 | const test2 = await testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath) | ||
380 | expect(test2).to.equal(true) | ||
381 | } | ||
382 | }) | ||
383 | }) | ||
384 | |||
385 | describe('Should seed the uploaded video', function () { | ||
386 | it('Should add the file 1 by asking server 3', async function () { | ||
387 | // Yes, this could be long | ||
388 | this.timeout(200000) | ||
389 | |||
390 | const res = await getVideosList(servers[2].url) | ||
391 | |||
392 | const video = res.body.data[0] | ||
393 | toRemove.push(res.body.data[2]) | ||
394 | toRemove.push(res.body.data[3]) | ||
395 | |||
396 | const res2 = await getVideo(servers[2].url, video.id) | ||
397 | const videoDetails = res2.body | ||
398 | |||
399 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) | ||
400 | expect(torrent.files).to.be.an('array') | ||
401 | expect(torrent.files.length).to.equal(1) | ||
402 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
403 | }) | ||
404 | |||
405 | it('Should add the file 2 by asking server 1', async function () { | ||
406 | // Yes, this could be long | ||
407 | this.timeout(200000) | ||
408 | |||
409 | const res = await getVideosList(servers[0].url) | ||
410 | |||
411 | const video = res.body.data[1] | ||
412 | const res2 = await getVideo(servers[0].url, video.id) | ||
413 | const videoDetails = res2.body | ||
414 | |||
415 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) | ||
416 | expect(torrent.files).to.be.an('array') | ||
417 | expect(torrent.files.length).to.equal(1) | ||
418 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
419 | }) | ||
420 | |||
421 | it('Should add the file 3 by asking server 2', async function () { | ||
422 | // Yes, this could be long | ||
423 | this.timeout(200000) | ||
424 | |||
425 | const res = await getVideosList(servers[1].url) | ||
426 | |||
427 | const video = res.body.data[2] | ||
428 | const res2 = await getVideo(servers[1].url, video.id) | ||
429 | const videoDetails = res2.body | ||
430 | |||
431 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) | ||
432 | expect(torrent.files).to.be.an('array') | ||
433 | expect(torrent.files.length).to.equal(1) | ||
434 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
435 | }) | ||
436 | |||
437 | it('Should add the file 3-2 by asking server 1', async function () { | ||
438 | // Yes, this could be long | ||
439 | this.timeout(200000) | ||
440 | |||
441 | const res = await getVideosList(servers[0].url) | ||
442 | |||
443 | const video = res.body.data[3] | ||
444 | const res2 = await getVideo(servers[0].url, video.id) | ||
445 | const videoDetails = res2.body | ||
446 | |||
447 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) | ||
448 | expect(torrent.files).to.be.an('array') | ||
449 | expect(torrent.files.length).to.equal(1) | ||
450 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
451 | }) | ||
452 | |||
453 | it('Should add the file 2 in 360p by asking server 1', async function () { | ||
454 | // Yes, this could be long | ||
455 | this.timeout(200000) | ||
456 | |||
457 | const res = await getVideosList(servers[0].url) | ||
458 | |||
459 | const video = res.body.data.find(v => v.name === 'my super name for server 2') | ||
460 | const res2 = await getVideo(servers[0].url, video.id) | ||
461 | const videoDetails = res2.body | ||
462 | |||
463 | const file = videoDetails.files.find(f => f.resolution === 360) | ||
464 | expect(file).not.to.be.undefined | ||
465 | |||
466 | const torrent = await webtorrentAdd(file.magnetUri) | ||
467 | expect(torrent.files).to.be.an('array') | ||
468 | expect(torrent.files.length).to.equal(1) | ||
469 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
470 | }) | ||
471 | }) | ||
472 | |||
473 | describe('Should update video views, likes and dislikes', function () { | ||
474 | let localVideosServer3 = [] | ||
475 | let remoteVideosServer1 = [] | ||
476 | let remoteVideosServer2 = [] | ||
477 | let remoteVideosServer3 = [] | ||
478 | |||
479 | before(async function () { | ||
480 | const res1 = await getVideosList(servers[0].url) | ||
481 | remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid) | ||
482 | |||
483 | const res2 = await getVideosList(servers[1].url) | ||
484 | remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid) | ||
485 | |||
486 | const res3 = await getVideosList(servers[2].url) | ||
487 | localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid) | ||
488 | remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid) | ||
489 | }) | ||
490 | |||
491 | it('Should view multiple videos on owned servers', async function () { | ||
492 | this.timeout(30000) | ||
493 | |||
494 | const tasks: Promise<any>[] = [] | ||
495 | tasks.push(getVideo(servers[2].url, localVideosServer3[0])) | ||
496 | tasks.push(getVideo(servers[2].url, localVideosServer3[0])) | ||
497 | tasks.push(getVideo(servers[2].url, localVideosServer3[0])) | ||
498 | tasks.push(getVideo(servers[2].url, localVideosServer3[1])) | ||
499 | |||
500 | await Promise.all(tasks) | ||
501 | |||
502 | await wait(22000) | ||
503 | |||
504 | for (const server of servers) { | ||
505 | const res = await getVideosList(server.url) | ||
506 | |||
507 | const videos = res.body.data | ||
508 | const video0 = videos.find(v => v.uuid === localVideosServer3[0]) | ||
509 | const video1 = videos.find(v => v.uuid === localVideosServer3[1]) | ||
510 | |||
511 | expect(video0.views).to.equal(7) | ||
512 | expect(video1.views).to.equal(5) | ||
513 | } | ||
514 | }) | ||
515 | |||
516 | it('Should view multiple videos on each servers', async function () { | ||
517 | this.timeout(30000) | ||
518 | |||
519 | const tasks: Promise<any>[] = [] | ||
520 | tasks.push(getVideo(servers[0].url, remoteVideosServer1[0])) | ||
521 | tasks.push(getVideo(servers[1].url, remoteVideosServer2[0])) | ||
522 | tasks.push(getVideo(servers[1].url, remoteVideosServer2[0])) | ||
523 | tasks.push(getVideo(servers[2].url, remoteVideosServer3[0])) | ||
524 | tasks.push(getVideo(servers[2].url, remoteVideosServer3[1])) | ||
525 | tasks.push(getVideo(servers[2].url, remoteVideosServer3[1])) | ||
526 | tasks.push(getVideo(servers[2].url, remoteVideosServer3[1])) | ||
527 | tasks.push(getVideo(servers[2].url, localVideosServer3[1])) | ||
528 | tasks.push(getVideo(servers[2].url, localVideosServer3[1])) | ||
529 | tasks.push(getVideo(servers[2].url, localVideosServer3[1])) | ||
530 | |||
531 | await Promise.all(tasks) | ||
532 | |||
533 | await wait(22000) | ||
534 | |||
535 | let baseVideos = null | ||
536 | |||
537 | for (const server of servers) { | ||
538 | const res = await getVideosList(server.url) | ||
539 | |||
540 | const videos = res.body.data | ||
541 | |||
542 | // Initialize base videos for future comparisons | ||
543 | if (baseVideos === null) { | ||
544 | baseVideos = videos | ||
545 | return | ||
546 | } | ||
547 | |||
548 | for (const baseVideo of baseVideos) { | ||
549 | const sameVideo = videos.find(video => video.name === baseVideo.name) | ||
550 | expect(baseVideo.views).to.equal(sameVideo.views) | ||
551 | } | ||
552 | } | ||
553 | }) | ||
554 | |||
555 | it('Should like and dislikes videos on different services', async function () { | ||
556 | this.timeout(30000) | ||
557 | |||
558 | const tasks: Promise<any>[] = [] | ||
559 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')) | ||
560 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike')) | ||
561 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')) | ||
562 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like')) | ||
563 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike')) | ||
564 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike')) | ||
565 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like')) | ||
566 | |||
567 | await Promise.all(tasks) | ||
568 | |||
569 | await wait(22000) | ||
570 | |||
571 | let baseVideos = null | ||
572 | for (const server of servers) { | ||
573 | const res = await getVideosList(server.url) | ||
574 | |||
575 | const videos = res.body.data | ||
576 | |||
577 | // Initialize base videos for future comparisons | ||
578 | if (baseVideos === null) { | ||
579 | baseVideos = videos | ||
580 | return | ||
581 | } | ||
582 | |||
583 | baseVideos.forEach(baseVideo => { | ||
584 | const sameVideo = videos.find(video => video.name === baseVideo.name) | ||
585 | expect(baseVideo.likes).to.equal(sameVideo.likes) | ||
586 | expect(baseVideo.dislikes).to.equal(sameVideo.dislikes) | ||
587 | }) | ||
588 | } | ||
589 | }) | ||
590 | }) | ||
591 | |||
592 | describe('Should manipulate these videos', function () { | ||
593 | it('Should update the video 3 by asking server 3', async function () { | ||
594 | this.timeout(15000) | ||
595 | |||
596 | const attributes = { | ||
597 | name: 'my super video updated', | ||
598 | category: 10, | ||
599 | licence: 7, | ||
600 | language: 13, | ||
601 | nsfw: true, | ||
602 | description: 'my super description updated', | ||
603 | tags: [ 'tag_up_1', 'tag_up_2' ] | ||
604 | } | ||
605 | |||
606 | await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) | ||
607 | |||
608 | await wait(11000) | ||
609 | }) | ||
610 | |||
611 | it('Should have the video 3 updated on each server', async function () { | ||
612 | this.timeout(200000) | ||
613 | |||
614 | for (const server of servers) { | ||
615 | const res = await getVideosList(server.url) | ||
616 | |||
617 | const videos = res.body.data | ||
618 | const videoUpdated = videos.find(video => video.name === 'my super video updated') | ||
619 | |||
620 | expect(!!videoUpdated).to.be.true | ||
621 | expect(videoUpdated.category).to.equal(10) | ||
622 | expect(videoUpdated.categoryLabel).to.equal('Entertainment') | ||
623 | expect(videoUpdated.licence).to.equal(7) | ||
624 | expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication') | ||
625 | expect(videoUpdated.language).to.equal(13) | ||
626 | expect(videoUpdated.languageLabel).to.equal('French') | ||
627 | expect(videoUpdated.nsfw).to.be.ok | ||
628 | expect(videoUpdated.description).to.equal('my super description updated') | ||
629 | expect(videoUpdated.tags).to.deep.equal([ 'tag_up_1', 'tag_up_2' ]) | ||
630 | expect(dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true | ||
631 | |||
632 | const res2 = await getVideo(server.url, videoUpdated.uuid) | ||
633 | const videoUpdatedDetails = res2.body | ||
634 | |||
635 | const file = videoUpdatedDetails .files[0] | ||
636 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
637 | expect(file.resolution).to.equal(720) | ||
638 | expect(file.resolutionLabel).to.equal('720p') | ||
639 | expect(file.size).to.equal(292677) | ||
640 | |||
641 | const test = await testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath) | ||
642 | expect(test).to.equal(true) | ||
643 | |||
644 | // Avoid "duplicate torrent" errors | ||
645 | const refreshWebTorrent = true | ||
646 | const torrent = await webtorrentAdd(videoUpdatedDetails .files[0].magnetUri, refreshWebTorrent) | ||
647 | expect(torrent.files).to.be.an('array') | ||
648 | expect(torrent.files.length).to.equal(1) | ||
649 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
650 | } | ||
651 | }) | ||
652 | |||
653 | it('Should remove the videos 3 and 3-2 by asking server 3', async function () { | ||
654 | this.timeout(15000) | ||
655 | |||
656 | await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id) | ||
657 | await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id) | ||
658 | |||
659 | await wait(11000) | ||
660 | }) | ||
661 | |||
662 | it('Should have videos 1 and 3 on each server', async function () { | ||
663 | for (const server of servers) { | ||
664 | const res = await getVideosList(server.url) | ||
665 | |||
666 | const videos = res.body.data | ||
667 | expect(videos).to.be.an('array') | ||
668 | expect(videos.length).to.equal(2) | ||
669 | expect(videos[0].name).not.to.equal(videos[1].name) | ||
670 | expect(videos[0].name).not.to.equal(toRemove[0].name) | ||
671 | expect(videos[1].name).not.to.equal(toRemove[0].name) | ||
672 | expect(videos[0].name).not.to.equal(toRemove[1].name) | ||
673 | expect(videos[1].name).not.to.equal(toRemove[1].name) | ||
674 | |||
675 | videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid | ||
676 | } | ||
677 | }) | ||
678 | |||
679 | it('Should get the same video by UUID on each server', async function () { | ||
680 | let baseVideo = null | ||
681 | for (const server of servers) { | ||
682 | const res = await getVideo(server.url, videoUUID) | ||
683 | |||
684 | const video = res.body | ||
685 | |||
686 | if (baseVideo === null) { | ||
687 | baseVideo = video | ||
688 | return | ||
689 | } | ||
690 | |||
691 | expect(baseVideo.name).to.equal(video.name) | ||
692 | expect(baseVideo.uuid).to.equal(video.uuid) | ||
693 | expect(baseVideo.category).to.equal(video.category) | ||
694 | expect(baseVideo.language).to.equal(video.language) | ||
695 | expect(baseVideo.licence).to.equal(video.licence) | ||
696 | expect(baseVideo.category).to.equal(video.category) | ||
697 | expect(baseVideo.nsfw).to.equal(video.nsfw) | ||
698 | expect(baseVideo.author).to.equal(video.account) | ||
699 | expect(baseVideo.tags).to.deep.equal(video.tags) | ||
700 | } | ||
701 | }) | ||
702 | |||
703 | it('Should get the preview from each server', async function () { | ||
704 | for (const server of servers) { | ||
705 | const res = await getVideo(server.url, videoUUID) | ||
706 | const video = res.body | ||
707 | |||
708 | const test = await testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath) | ||
709 | expect(test).to.equal(true) | ||
710 | } | ||
711 | }) | ||
712 | }) | ||
713 | |||
714 | after(async function () { | ||
715 | killallServers(servers) | ||
716 | |||
717 | // Keep the logs if the test failed | ||
718 | if (this['ok']) { | ||
719 | await flushTests() | ||
720 | } | ||
721 | }) | ||
722 | }) | ||