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 than 22000
149 // All pods should have this video
150 for (const server of servers) {
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(5)
177 // Check common attributes
178 for (const file of video.files) {
179 expect(file.magnetUri).to.have.lengthOf.above(2)
181 if (server.url !== 'http://localhost:9002') {
182 expect(video.isLocal).to.be.false
184 expect(video.isLocal).to.be.true
187 // All pods should have the same magnet Uri
188 if (baseMagnet[file.resolution] === undefined) {
189 baseMagnet[file.resolution] = file.magnet
191 expect(baseMagnet[file.resolution]).to.equal(file.magnet)
195 const originalFile = video.files.find(f => f.resolution === 0)
196 expect(originalFile).not.to.be.undefined
197 expect(originalFile.resolutionLabel).to.equal('original')
198 expect(originalFile.size).to.be.above(700000).and.below(720000)
200 const file240p = video.files.find(f => f.resolution === 240)
201 expect(file240p).not.to.be.undefined
202 expect(file240p.resolutionLabel).to.equal('240p')
203 expect(file240p.size).to.be.above(130000).and.below(150000)
205 const file360p = video.files.find(f => f.resolution === 360)
206 expect(file360p).not.to.be.undefined
207 expect(file360p.resolutionLabel).to.equal('360p')
208 expect(file360p.size).to.be.above(160000).and.below(180000)
210 const file480p = video.files.find(f => f.resolution === 480)
211 expect(file480p).not.to.be.undefined
212 expect(file480p.resolutionLabel).to.equal('480p')
213 expect(file480p.size).to.be.above(200000).and.below(220000)
215 const file720p = video.files.find(f => f.resolution === 720)
216 expect(file720p).not.to.be.undefined
217 expect(file720p.resolutionLabel).to.equal('720p')
218 expect(file720p.size).to.be.above(310000).and.below(320000)
220 const test = await testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath)
221 expect(test).to.equal(true)
225 it('Should upload two videos on pod 3 and propagate on each pod', async function () {
228 const videoAttributes1 = {
229 name: 'my super name for pod 3',
234 description: 'my super description for pod 3',
236 fixture: 'video_short3.webm'
238 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1)
240 const videoAttributes2 = {
241 name: 'my super name for pod 3-2',
246 description: 'my super description for pod 3-2',
247 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
248 fixture: 'video_short.webm'
250 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2)
254 let baseMagnet = null
255 // All pods should have this video
256 for (const server of servers) {
257 const res = await getVideosList(server.url)
259 const videos = res.body.data
260 expect(videos).to.be.an('array')
261 expect(videos.length).to.equal(4)
263 // We not sure about the order of the two last uploads
266 if (videos[2].name === 'my super name for pod 3') {
274 expect(video1.name).to.equal('my super name for pod 3')
275 expect(video1.category).to.equal(6)
276 expect(video1.categoryLabel).to.equal('Travels')
277 expect(video1.licence).to.equal(5)
278 expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike')
279 expect(video1.language).to.equal(11)
280 expect(video1.languageLabel).to.equal('German')
281 expect(video1.nsfw).to.be.ok
282 expect(video1.description).to.equal('my super description for pod 3')
283 expect(video1.podHost).to.equal('localhost:9003')
284 expect(video1.duration).to.equal(5)
285 expect(video1.tags).to.deep.equal([ 'tag1p3' ])
286 expect(video1.author).to.equal('root')
287 expect(dateIsValid(video1.createdAt)).to.be.true
288 expect(dateIsValid(video1.updatedAt)).to.be.true
290 expect(video1.files).to.have.lengthOf(1)
292 const file1 = video1.files[0]
293 expect(file1.magnetUri).to.have.lengthOf.above(2)
294 expect(file1.resolution).to.equal(0)
295 expect(file1.resolutionLabel).to.equal('original')
296 expect(file1.size).to.equal(292677)
298 expect(video2.name).to.equal('my super name for pod 3-2')
299 expect(video2.category).to.equal(7)
300 expect(video2.categoryLabel).to.equal('Gaming')
301 expect(video2.licence).to.equal(6)
302 expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
303 expect(video2.language).to.equal(12)
304 expect(video2.languageLabel).to.equal('Korean')
305 expect(video2.nsfw).to.be.false
306 expect(video2.description).to.equal('my super description for pod 3-2')
307 expect(video2.podHost).to.equal('localhost:9003')
308 expect(video2.duration).to.equal(5)
309 expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
310 expect(video2.author).to.equal('root')
311 expect(dateIsValid(video2.createdAt)).to.be.true
312 expect(dateIsValid(video2.updatedAt)).to.be.true
314 expect(video2.files).to.have.lengthOf(1)
316 const file2 = video2.files[0]
317 const magnetUri2 = file2.magnetUri
318 expect(file2.magnetUri).to.have.lengthOf.above(2)
319 expect(file2.resolution).to.equal(0)
320 expect(file2.resolutionLabel).to.equal('original')
321 expect(file2.size).to.equal(218910)
323 if (server.url !== 'http://localhost:9003') {
324 expect(video1.isLocal).to.be.false
325 expect(video2.isLocal).to.be.false
327 expect(video1.isLocal).to.be.true
328 expect(video2.isLocal).to.be.true
331 // All pods should have the same magnet Uri
332 if (baseMagnet === null) {
333 baseMagnet = magnetUri2
335 expect(baseMagnet).to.equal(magnetUri2)
338 const test1 = await testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath)
339 expect(test1).to.equal(true)
341 const test2 = await testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath)
342 expect(test2).to.equal(true)
347 describe('Should seed the uploaded video', function () {
348 it('Should add the file 1 by asking pod 3', async function () {
349 // Yes, this could be long
352 const res = await getVideosList(servers[2].url)
354 const video = res.body.data[0]
355 toRemove.push(res.body.data[2])
356 toRemove.push(res.body.data[3])
358 const torrent = await webtorrentAdd(video.files[0].magnetUri)
359 expect(torrent.files).to.be.an('array')
360 expect(torrent.files.length).to.equal(1)
361 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
364 it('Should add the file 2 by asking pod 1', async function () {
365 // Yes, this could be long
368 const res = await getVideosList(servers[0].url)
370 const video = res.body.data[1]
372 const torrent = await webtorrentAdd(video.files[0].magnetUri)
373 expect(torrent.files).to.be.an('array')
374 expect(torrent.files.length).to.equal(1)
375 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
378 it('Should add the file 3 by asking pod 2', async function () {
379 // Yes, this could be long
382 const res = await getVideosList(servers[1].url)
384 const video = res.body.data[2]
386 const torrent = await webtorrentAdd(video.files[0].magnetUri)
387 expect(torrent.files).to.be.an('array')
388 expect(torrent.files.length).to.equal(1)
389 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
392 it('Should add the file 3-2 by asking pod 1', async function () {
393 // Yes, this could be long
396 const res = await getVideosList(servers[0].url)
398 const video = res.body.data[3]
400 const torrent = await webtorrentAdd(video.files[0].magnetUri)
401 expect(torrent.files).to.be.an('array')
402 expect(torrent.files.length).to.equal(1)
403 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
407 describe('Should update video views, likes and dislikes', function () {
408 let localVideosPod3 = []
409 let remoteVideosPod1 = []
410 let remoteVideosPod2 = []
411 let remoteVideosPod3 = []
413 before(async function () {
414 const res1 = await getVideosList(servers[0].url)
415 remoteVideosPod1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.id)
417 const res2 = await getVideosList(servers[1].url)
418 remoteVideosPod2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.id)
420 const res3 = await getVideosList(servers[2].url)
421 localVideosPod3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.id)
422 remoteVideosPod3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.id)
425 it('Should view multiple videos on owned servers', async function () {
428 const tasks: Promise<any>[] = []
429 tasks.push(getVideo(servers[2].url, localVideosPod3[0]))
430 tasks.push(getVideo(servers[2].url, localVideosPod3[0]))
431 tasks.push(getVideo(servers[2].url, localVideosPod3[0]))
432 tasks.push(getVideo(servers[2].url, localVideosPod3[1]))
434 await Promise.all(tasks)
438 for (const server of servers) {
439 const res = await getVideosList(server.url)
441 const videos = res.body.data
442 expect(videos.find(video => video.views === 3)).to.be.an('object')
443 expect(videos.find(video => video.views === 1)).to.be.an('object')
447 it('Should view multiple videos on each servers', async function () {
450 const tasks: Promise<any>[] = []
451 tasks.push(getVideo(servers[0].url, remoteVideosPod1[0]))
452 tasks.push(getVideo(servers[1].url, remoteVideosPod2[0]))
453 tasks.push(getVideo(servers[1].url, remoteVideosPod2[0]))
454 tasks.push(getVideo(servers[2].url, remoteVideosPod3[0]))
455 tasks.push(getVideo(servers[2].url, remoteVideosPod3[1]))
456 tasks.push(getVideo(servers[2].url, remoteVideosPod3[1]))
457 tasks.push(getVideo(servers[2].url, remoteVideosPod3[1]))
458 tasks.push(getVideo(servers[2].url, localVideosPod3[1]))
459 tasks.push(getVideo(servers[2].url, localVideosPod3[1]))
460 tasks.push(getVideo(servers[2].url, localVideosPod3[1]))
462 await Promise.all(tasks)
466 let baseVideos = null
468 for (const server of servers) {
469 const res = await getVideosList(server.url)
471 const videos = res.body.data
473 // Initialize base videos for future comparisons
474 if (baseVideos === null) {
479 for (const baseVideo of baseVideos) {
480 const sameVideo = videos.find(video => video.name === baseVideo.name)
481 expect(baseVideo.views).to.equal(sameVideo.views)
486 it('Should like and dislikes videos on different services', async function () {
489 const tasks: Promise<any>[] = []
490 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like'))
491 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'dislike'))
492 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like'))
493 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'like'))
494 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'dislike'))
495 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[1], 'dislike'))
496 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[0], 'like'))
498 await Promise.all(tasks)
502 let baseVideos = null
503 for (const server of servers) {
504 const res = await getVideosList(server.url)
506 const videos = res.body.data
508 // Initialize base videos for future comparisons
509 if (baseVideos === null) {
514 baseVideos.forEach(baseVideo => {
515 const sameVideo = videos.find(video => video.name === baseVideo.name)
516 expect(baseVideo.likes).to.equal(sameVideo.likes)
517 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
523 describe('Should manipulate these videos', function () {
524 it('Should update the video 3 by asking pod 3', async function () {
528 name: 'my super video updated',
533 description: 'my super description updated',
534 tags: [ 'tag_up_1', 'tag_up_2' ]
537 await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes)
542 it('Should have the video 3 updated on each pod', async function () {
545 for (const server of servers) {
546 const res = await getVideosList(server.url)
548 const videos = res.body.data
549 const videoUpdated = videos.find(video => video.name === 'my super video updated')
551 expect(!!videoUpdated).to.be.true
552 expect(videoUpdated.category).to.equal(10)
553 expect(videoUpdated.categoryLabel).to.equal('Entertainment')
554 expect(videoUpdated.licence).to.equal(7)
555 expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication')
556 expect(videoUpdated.language).to.equal(13)
557 expect(videoUpdated.languageLabel).to.equal('French')
558 expect(videoUpdated.nsfw).to.be.ok
559 expect(videoUpdated.description).to.equal('my super description updated')
560 expect(videoUpdated.tags).to.deep.equal([ 'tag_up_1', 'tag_up_2' ])
561 expect(dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
563 const file = videoUpdated.files[0]
564 expect(file.magnetUri).to.have.lengthOf.above(2)
565 expect(file.resolution).to.equal(0)
566 expect(file.resolutionLabel).to.equal('original')
567 expect(file.size).to.equal(292677)
569 const test = await testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath)
570 expect(test).to.equal(true)
572 // Avoid "duplicate torrent" errors
573 const refreshWebTorrent = true
574 const torrent = await webtorrentAdd(videoUpdated.files[0].magnetUri, refreshWebTorrent)
575 expect(torrent.files).to.be.an('array')
576 expect(torrent.files.length).to.equal(1)
577 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
581 it('Should remove the videos 3 and 3-2 by asking pod 3', async function () {
584 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id)
585 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id)
590 it('Should have videos 1 and 3 on each pod', async function () {
591 for (const server of servers) {
592 const res = await getVideosList(server.url)
594 const videos = res.body.data
595 expect(videos).to.be.an('array')
596 expect(videos.length).to.equal(2)
597 expect(videos[0].name).not.to.equal(videos[1].name)
598 expect(videos[0].name).not.to.equal(toRemove[0].name)
599 expect(videos[1].name).not.to.equal(toRemove[0].name)
600 expect(videos[0].name).not.to.equal(toRemove[1].name)
601 expect(videos[1].name).not.to.equal(toRemove[1].name)
603 videoUUID = videos.find(video => video.name === 'my super name for pod 1').uuid
607 it('Should get the same video by UUID on each pod', async function () {
609 for (const server of servers) {
610 const res = await getVideo(server.url, videoUUID)
612 const video = res.body
614 if (baseVideo === null) {
619 expect(baseVideo.name).to.equal(video.name)
620 expect(baseVideo.uuid).to.equal(video.uuid)
621 expect(baseVideo.category).to.equal(video.category)
622 expect(baseVideo.language).to.equal(video.language)
623 expect(baseVideo.licence).to.equal(video.licence)
624 expect(baseVideo.category).to.equal(video.category)
625 expect(baseVideo.nsfw).to.equal(video.nsfw)
626 expect(baseVideo.author).to.equal(video.author)
627 expect(baseVideo.tags).to.deep.equal(video.tags)
631 it('Should get the preview from each pod', async function () {
632 for (const server of servers) {
633 const res = await getVideo(server.url, videoUUID)
634 const video = res.body
636 const test = await testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath)
637 expect(test).to.equal(true)
642 after(async function () {
643 killallServers(servers)
645 // Keep the logs if the test failed