1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
8 flushAndRunMultipleServers,
17 setAccessTokensToServers,
25 const expect = chai.expect
27 describe('Test multiple pods', function () {
28 let servers: ServerInfo[] = []
32 before(async function () {
35 servers = await flushAndRunMultipleServers(3)
37 // Get the access tokens
38 await setAccessTokensToServers(servers)
40 // The second pod make friend with the third
41 await makeFriends(servers[1].url, servers[1].accessToken)
43 // Wait for the request between pods
46 // Pod 1 make friends too
47 await makeFriends(servers[0].url, servers[0].accessToken)
50 it('Should not have videos for all pods', async function () {
51 for (const server of servers) {
52 const res = await getVideosList(server.url)
53 const videos = res.body.data
54 expect(videos).to.be.an('array')
55 expect(videos.length).to.equal(0)
59 describe('Should upload the video and propagate on each pod', function () {
60 it('Should upload the video on pod 1 and propagate on each pod', async function () {
61 // Pod 1 has video transcoding activated
64 const videoAttributes = {
65 name: 'my super name for pod 1',
70 description: 'my super description for pod 1',
71 tags: [ 'tag1p1', 'tag2p1' ],
72 fixture: 'video_short1.webm'
74 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
78 // All pods should have this video
79 for (const server of servers) {
82 const res = await getVideosList(server.url)
84 const videos = res.body.data
85 expect(videos).to.be.an('array')
86 expect(videos.length).to.equal(1)
87 const video = videos[0]
88 expect(video.name).to.equal('my super name for pod 1')
89 expect(video.category).to.equal(5)
90 expect(video.categoryLabel).to.equal('Sports')
91 expect(video.licence).to.equal(4)
92 expect(video.licenceLabel).to.equal('Attribution - Non Commercial')
93 expect(video.language).to.equal(9)
94 expect(video.languageLabel).to.equal('Japanese')
95 expect(video.nsfw).to.be.ok
96 expect(video.description).to.equal('my super description for pod 1')
97 expect(video.podHost).to.equal('localhost:9001')
98 expect(video.duration).to.equal(10)
99 expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
100 expect(dateIsValid(video.createdAt)).to.be.true
101 expect(dateIsValid(video.updatedAt)).to.be.true
102 expect(video.author).to.equal('root')
104 expect(video.files).to.have.lengthOf(1)
106 const file = video.files[0]
107 const magnetUri = file.magnetUri
108 expect(file.magnetUri).to.have.lengthOf.above(2)
109 expect(file.resolution).to.equal(0)
110 expect(file.resolutionLabel).to.equal('original')
111 expect(file.size).to.equal(572456)
113 if (server.url !== 'http://localhost:9001') {
114 expect(video.isLocal).to.be.false
116 expect(video.isLocal).to.be.true
119 // All pods should have the same magnet Uri
120 if (baseMagnet === null) {
121 baseMagnet = magnetUri
123 expect(baseMagnet).to.equal(magnetUri)
126 const test = await testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath)
127 expect(test).to.equal(true)
131 it('Should upload the video on pod 2 and propagate on each pod', async function () {
134 const videoAttributes = {
135 name: 'my super name for pod 2',
140 description: 'my super description for pod 2',
141 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
142 fixture: 'video_short2.webm'
144 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
146 // Transcoding, so wait more that 22 seconds
149 // All pods should have this video
150 for (const server of servers) {
151 let baseMagnet = null
153 const res = await getVideosList(server.url)
155 const videos = res.body.data
156 expect(videos).to.be.an('array')
157 expect(videos.length).to.equal(2)
158 const video = videos[1]
159 expect(video.name).to.equal('my super name for pod 2')
160 expect(video.category).to.equal(4)
161 expect(video.categoryLabel).to.equal('Art')
162 expect(video.licence).to.equal(3)
163 expect(video.licenceLabel).to.equal('Attribution - No Derivatives')
164 expect(video.language).to.equal(11)
165 expect(video.languageLabel).to.equal('German')
166 expect(video.nsfw).to.be.true
167 expect(video.description).to.equal('my super description for pod 2')
168 expect(video.podHost).to.equal('localhost:9002')
169 expect(video.duration).to.equal(5)
170 expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
171 expect(dateIsValid(video.createdAt)).to.be.true
172 expect(dateIsValid(video.updatedAt)).to.be.true
173 expect(video.author).to.equal('root')
175 expect(video.files).to.have.lengthOf(1)
177 const file = video.files[0]
178 const magnetUri = file.magnetUri
179 expect(file.magnetUri).to.have.lengthOf.above(2)
180 expect(file.resolution).to.equal(0)
181 expect(file.resolutionLabel).to.equal('original')
182 expect(file.size).to.equal(942961)
184 if (server.url !== 'http://localhost:9002') {
185 expect(video.isLocal).to.be.false
187 expect(video.isLocal).to.be.true
190 // All pods should have the same magnet Uri
191 if (baseMagnet === null) {
192 baseMagnet = magnetUri
194 expect(baseMagnet).to.equal(magnetUri)
197 const test = await testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath)
198 expect(test).to.equal(true)
202 it('Should upload two videos on pod 3 and propagate on each pod', async function () {
205 const videoAttributes1 = {
206 name: 'my super name for pod 3',
211 description: 'my super description for pod 3',
213 fixture: 'video_short3.webm'
215 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1)
217 const videoAttributes2 = {
218 name: 'my super name for pod 3-2',
223 description: 'my super description for pod 3-2',
224 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
225 fixture: 'video_short.webm'
227 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2)
231 let baseMagnet = null
232 // All pods should have this video
233 for (const server of servers) {
234 const res = await getVideosList(server.url)
236 const videos = res.body.data
237 expect(videos).to.be.an('array')
238 expect(videos.length).to.equal(4)
240 // We not sure about the order of the two last uploads
243 if (videos[2].name === 'my super name for pod 3') {
251 expect(video1.name).to.equal('my super name for pod 3')
252 expect(video1.category).to.equal(6)
253 expect(video1.categoryLabel).to.equal('Travels')
254 expect(video1.licence).to.equal(5)
255 expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike')
256 expect(video1.language).to.equal(11)
257 expect(video1.languageLabel).to.equal('German')
258 expect(video1.nsfw).to.be.ok
259 expect(video1.description).to.equal('my super description for pod 3')
260 expect(video1.podHost).to.equal('localhost:9003')
261 expect(video1.duration).to.equal(5)
262 expect(video1.tags).to.deep.equal([ 'tag1p3' ])
263 expect(video1.author).to.equal('root')
264 expect(dateIsValid(video1.createdAt)).to.be.true
265 expect(dateIsValid(video1.updatedAt)).to.be.true
267 expect(video1.files).to.have.lengthOf(1)
269 const file1 = video1.files[0]
270 expect(file1.magnetUri).to.have.lengthOf.above(2)
271 expect(file1.resolution).to.equal(0)
272 expect(file1.resolutionLabel).to.equal('original')
273 expect(file1.size).to.equal(292677)
275 expect(video2.name).to.equal('my super name for pod 3-2')
276 expect(video2.category).to.equal(7)
277 expect(video2.categoryLabel).to.equal('Gaming')
278 expect(video2.licence).to.equal(6)
279 expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
280 expect(video2.language).to.equal(12)
281 expect(video2.languageLabel).to.equal('Korean')
282 expect(video2.nsfw).to.be.false
283 expect(video2.description).to.equal('my super description for pod 3-2')
284 expect(video2.podHost).to.equal('localhost:9003')
285 expect(video2.duration).to.equal(5)
286 expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
287 expect(video2.author).to.equal('root')
288 expect(dateIsValid(video2.createdAt)).to.be.true
289 expect(dateIsValid(video2.updatedAt)).to.be.true
291 expect(video2.files).to.have.lengthOf(1)
293 const file2 = video2.files[0]
294 const magnetUri2 = file2.magnetUri
295 expect(file2.magnetUri).to.have.lengthOf.above(2)
296 expect(file2.resolution).to.equal(0)
297 expect(file2.resolutionLabel).to.equal('original')
298 expect(file2.size).to.equal(218910)
300 if (server.url !== 'http://localhost:9003') {
301 expect(video1.isLocal).to.be.false
302 expect(video2.isLocal).to.be.false
304 expect(video1.isLocal).to.be.true
305 expect(video2.isLocal).to.be.true
308 // All pods should have the same magnet Uri
309 if (baseMagnet === null) {
310 baseMagnet = magnetUri2
312 expect(baseMagnet).to.equal(magnetUri2)
315 const test1 = await testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath)
316 expect(test1).to.equal(true)
318 const test2 = await testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath)
319 expect(test2).to.equal(true)
324 describe('Should seed the uploaded video', function () {
325 it('Should add the file 1 by asking pod 3', async function () {
326 // Yes, this could be long
329 const res = await getVideosList(servers[2].url)
331 const video = res.body.data[0]
332 toRemove.push(res.body.data[2])
333 toRemove.push(res.body.data[3])
335 const torrent = await webtorrentAdd(video.files[0].magnetUri)
336 expect(torrent.files).to.be.an('array')
337 expect(torrent.files.length).to.equal(1)
338 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
341 it('Should add the file 2 by asking pod 1', async function () {
342 // Yes, this could be long
345 const res = await getVideosList(servers[0].url)
347 const video = res.body.data[1]
349 const torrent = await webtorrentAdd(video.files[0].magnetUri)
350 expect(torrent.files).to.be.an('array')
351 expect(torrent.files.length).to.equal(1)
352 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
355 it('Should add the file 3 by asking pod 2', async function () {
356 // Yes, this could be long
359 const res = await getVideosList(servers[1].url)
361 const video = res.body.data[2]
363 const torrent = await webtorrentAdd(video.files[0].magnetUri)
364 expect(torrent.files).to.be.an('array')
365 expect(torrent.files.length).to.equal(1)
366 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
369 it('Should add the file 3-2 by asking pod 1', async function () {
370 // Yes, this could be long
373 const res = await getVideosList(servers[0].url)
375 const video = res.body.data[3]
377 const torrent = await webtorrentAdd(video.files[0].magnetUri)
378 expect(torrent.files).to.be.an('array')
379 expect(torrent.files.length).to.equal(1)
380 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
384 describe('Should update video views, likes and dislikes', function () {
385 let localVideosPod3 = []
386 let remoteVideosPod1 = []
387 let remoteVideosPod2 = []
388 let remoteVideosPod3 = []
390 before(async function () {
391 const res1 = await getVideosList(servers[0].url)
392 remoteVideosPod1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.id)
394 const res2 = await getVideosList(servers[1].url)
395 remoteVideosPod2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.id)
397 const res3 = await getVideosList(servers[2].url)
398 localVideosPod3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.id)
399 remoteVideosPod3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.id)
402 it('Should view multiple videos on owned servers', async function () {
405 const tasks: Promise<any>[] = []
406 tasks.push(getVideo(servers[2].url, localVideosPod3[0]))
407 tasks.push(getVideo(servers[2].url, localVideosPod3[0]))
408 tasks.push(getVideo(servers[2].url, localVideosPod3[0]))
409 tasks.push(getVideo(servers[2].url, localVideosPod3[1]))
411 await Promise.all(tasks)
415 for (const server of servers) {
416 const res = await getVideosList(server.url)
418 const videos = res.body.data
419 expect(videos.find(video => video.views === 3)).to.be.an('object')
420 expect(videos.find(video => video.views === 1)).to.be.an('object')
424 it('Should view multiple videos on each servers', async function () {
427 const tasks: Promise<any>[] = []
428 tasks.push(getVideo(servers[0].url, remoteVideosPod1[0]))
429 tasks.push(getVideo(servers[1].url, remoteVideosPod2[0]))
430 tasks.push(getVideo(servers[1].url, remoteVideosPod2[0]))
431 tasks.push(getVideo(servers[2].url, remoteVideosPod3[0]))
432 tasks.push(getVideo(servers[2].url, remoteVideosPod3[1]))
433 tasks.push(getVideo(servers[2].url, remoteVideosPod3[1]))
434 tasks.push(getVideo(servers[2].url, remoteVideosPod3[1]))
435 tasks.push(getVideo(servers[2].url, localVideosPod3[1]))
436 tasks.push(getVideo(servers[2].url, localVideosPod3[1]))
437 tasks.push(getVideo(servers[2].url, localVideosPod3[1]))
439 await Promise.all(tasks)
443 let baseVideos = null
445 for (const server of servers) {
446 const res = await getVideosList(server.url)
448 const videos = res.body.data
450 // Initialize base videos for future comparisons
451 if (baseVideos === null) {
456 for (const baseVideo of baseVideos) {
457 const sameVideo = videos.find(video => video.name === baseVideo.name)
458 expect(baseVideo.views).to.equal(sameVideo.views)
463 it('Should like and dislikes videos on different services', async function () {
466 const tasks: Promise<any>[] = []
467 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like'))
468 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'dislike'))
469 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like'))
470 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'like'))
471 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'dislike'))
472 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[1], 'dislike'))
473 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[0], 'like'))
475 await Promise.all(tasks)
479 let baseVideos = null
480 for (const server of servers) {
481 const res = await getVideosList(server.url)
483 const videos = res.body.data
485 // Initialize base videos for future comparisons
486 if (baseVideos === null) {
491 baseVideos.forEach(baseVideo => {
492 const sameVideo = videos.find(video => video.name === baseVideo.name)
493 expect(baseVideo.likes).to.equal(sameVideo.likes)
494 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
500 describe('Should manipulate these videos', function () {
501 it('Should update the video 3 by asking pod 3', async function () {
505 name: 'my super video updated',
510 description: 'my super description updated',
511 tags: [ 'tag_up_1', 'tag_up_2' ]
514 await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes)
519 it('Should have the video 3 updated on each pod', async function () {
522 for (const server of servers) {
523 const res = await getVideosList(server.url)
525 const videos = res.body.data
526 const videoUpdated = videos.find(video => video.name === 'my super video updated')
528 expect(!!videoUpdated).to.be.true
529 expect(videoUpdated.category).to.equal(10)
530 expect(videoUpdated.categoryLabel).to.equal('Entertainment')
531 expect(videoUpdated.licence).to.equal(7)
532 expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication')
533 expect(videoUpdated.language).to.equal(13)
534 expect(videoUpdated.languageLabel).to.equal('French')
535 expect(videoUpdated.nsfw).to.be.ok
536 expect(videoUpdated.description).to.equal('my super description updated')
537 expect(videoUpdated.tags).to.deep.equal([ 'tag_up_1', 'tag_up_2' ])
538 expect(dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
540 const file = videoUpdated.files[0]
541 expect(file.magnetUri).to.have.lengthOf.above(2)
542 expect(file.resolution).to.equal(0)
543 expect(file.resolutionLabel).to.equal('original')
544 expect(file.size).to.equal(292677)
546 const test = await testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath)
547 expect(test).to.equal(true)
549 // Avoid "duplicate torrent" errors
550 const refreshWebTorrent = true
551 const torrent = await webtorrentAdd(videoUpdated.files[0].magnetUri, refreshWebTorrent)
552 expect(torrent.files).to.be.an('array')
553 expect(torrent.files.length).to.equal(1)
554 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
558 it('Should remove the videos 3 and 3-2 by asking pod 3', async function () {
561 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id)
562 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id)
567 it('Should have videos 1 and 3 on each pod', async function () {
568 for (const server of servers) {
569 const res = await getVideosList(server.url)
571 const videos = res.body.data
572 expect(videos).to.be.an('array')
573 expect(videos.length).to.equal(2)
574 expect(videos[0].name).not.to.equal(videos[1].name)
575 expect(videos[0].name).not.to.equal(toRemove[0].name)
576 expect(videos[1].name).not.to.equal(toRemove[0].name)
577 expect(videos[0].name).not.to.equal(toRemove[1].name)
578 expect(videos[1].name).not.to.equal(toRemove[1].name)
580 videoUUID = videos.find(video => video.name === 'my super name for pod 1').uuid
584 it('Should get the same video by UUID on each pod', async function () {
586 for (const server of servers) {
587 const res = await getVideo(server.url, videoUUID)
589 const video = res.body
591 if (baseVideo === null) {
596 expect(baseVideo.name).to.equal(video.name)
597 expect(baseVideo.uuid).to.equal(video.uuid)
598 expect(baseVideo.category).to.equal(video.category)
599 expect(baseVideo.language).to.equal(video.language)
600 expect(baseVideo.licence).to.equal(video.licence)
601 expect(baseVideo.category).to.equal(video.category)
602 expect(baseVideo.nsfw).to.equal(video.nsfw)
603 expect(baseVideo.author).to.equal(video.author)
604 expect(baseVideo.tags).to.deep.equal(video.tags)
608 it('Should get the preview from each pod', async function () {
609 for (const server of servers) {
610 const res = await getVideo(server.url, videoUUID)
611 const video = res.body
613 const test = await testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath)
614 expect(test).to.equal(true)
619 after(async function () {
620 killallServers(servers)
622 // Keep the logs if the test failed