1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
8 flushAndRunMultipleServers,
16 setAccessTokensToServers,
27 import { createUser } from '../utils/users'
29 const expect = chai.expect
31 describe('Test multiple servers', function () {
32 let servers: ServerInfo[] = []
35 let videoChannelId: number
37 before(async function () {
40 servers = await flushAndRunMultipleServers(3)
42 // Get the access tokens
43 await setAccessTokensToServers(servers)
45 const videoChannel = {
47 description: 'super channel'
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
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])
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)
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 () {
74 const videoAttributes = {
75 name: 'my super name for server 1',
80 description: 'my super description for server 1',
81 tags: [ 'tag1p1', 'tag2p1' ],
82 channelId: videoChannelId,
83 fixture: 'video_short1.webm'
85 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
89 // All servers should have this video
90 for (const server of servers) {
93 const res = await getVideosList(server.url)
95 const videos = res.body.data
96 expect(videos).to.be.an('array')
97 expect(videos.length).to.equal(1)
98 const video = videos[0]
99 expect(video.name).to.equal('my super name for server 1')
100 expect(video.category).to.equal(5)
101 expect(video.categoryLabel).to.equal('Sports')
102 expect(video.licence).to.equal(4)
103 expect(video.licenceLabel).to.equal('Attribution - Non Commercial')
104 expect(video.language).to.equal(9)
105 expect(video.languageLabel).to.equal('Japanese')
106 expect(video.nsfw).to.be.ok
107 expect(video.description).to.equal('my super description for server 1')
108 expect(video.serverHost).to.equal('localhost:9001')
109 expect(video.duration).to.equal(10)
110 expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
111 expect(dateIsValid(video.createdAt)).to.be.true
112 expect(dateIsValid(video.updatedAt)).to.be.true
113 expect(video.account).to.equal('root')
115 const res2 = await getVideo(server.url, video.uuid)
116 const videoDetails = res2.body
118 expect(videoDetails.channel.name).to.equal('my channel')
119 expect(videoDetails.channel.description).to.equal('super channel')
120 expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true
121 expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true
122 expect(videoDetails.files).to.have.lengthOf(1)
124 const file = videoDetails.files[0]
125 const magnetUri = file.magnetUri
126 expect(file.magnetUri).to.have.lengthOf.above(2)
127 expect(file.torrentUrl).to
128 .equal(`http://${videoDetails.serverHost}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
129 expect(file.fileUrl).to.equal(`http://${videoDetails.serverHost}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)
130 expect(file.resolution).to.equal(720)
131 expect(file.resolutionLabel).to.equal('720p')
132 expect(file.size).to.equal(572456)
134 if (server.url !== 'http://localhost:9001') {
135 expect(video.isLocal).to.be.false
136 expect(videoDetails.channel.isLocal).to.be.false
138 expect(video.isLocal).to.be.true
139 expect(videoDetails.channel.isLocal).to.be.true
142 // All servers should have the same magnet Uri
143 if (baseMagnet === null) {
144 baseMagnet = magnetUri
146 expect(baseMagnet).to.equal(magnetUri)
149 const test = await testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath)
150 expect(test).to.equal(true)
154 it('Should upload the video on server 2 and propagate on each server', async function () {
159 password: 'super_password'
161 await createUser(servers[1].url, servers[1].accessToken, user.username, user.password)
162 const userAccessToken = await getUserAccessToken(servers[1], user)
164 const videoAttributes = {
165 name: 'my super name for server 2',
170 description: 'my super description for server 2',
171 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
172 fixture: 'video_short2.webm'
174 await uploadVideo(servers[1].url, userAccessToken, videoAttributes)
179 // All servers should have this video
180 for (const server of servers) {
183 const res = await getVideosList(server.url)
185 const videos = res.body.data
186 expect(videos).to.be.an('array')
187 expect(videos.length).to.equal(2)
188 const video = videos[1]
189 expect(video.name).to.equal('my super name for server 2')
190 expect(video.category).to.equal(4)
191 expect(video.categoryLabel).to.equal('Art')
192 expect(video.licence).to.equal(3)
193 expect(video.licenceLabel).to.equal('Attribution - No Derivatives')
194 expect(video.language).to.equal(11)
195 expect(video.languageLabel).to.equal('German')
196 expect(video.nsfw).to.be.true
197 expect(video.description).to.equal('my super description for server 2')
198 expect(video.serverHost).to.equal('localhost:9002')
199 expect(video.duration).to.equal(5)
200 expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
201 expect(dateIsValid(video.createdAt)).to.be.true
202 expect(dateIsValid(video.updatedAt)).to.be.true
203 expect(video.account).to.equal('user1')
205 if (server.url !== 'http://localhost:9002') {
206 expect(video.isLocal).to.be.false
208 expect(video.isLocal).to.be.true
211 const res2 = await getVideo(server.url, video.uuid)
212 const videoDetails = res2.body
214 expect(videoDetails.channel.name).to.equal('Default user1 channel')
215 expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true
216 expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true
218 expect(videoDetails.files).to.have.lengthOf(4)
220 // Check common attributes
221 for (const file of videoDetails.files) {
222 expect(file.magnetUri).to.have.lengthOf.above(2)
224 // All servers should have the same magnet Uri
225 if (baseMagnet[file.resolution] === undefined) {
226 baseMagnet[file.resolution] = file.magnet
228 expect(baseMagnet[file.resolution]).to.equal(file.magnet)
232 const file240p = videoDetails.files.find(f => f.resolution === 240)
233 expect(file240p).not.to.be.undefined
234 expect(file240p.resolutionLabel).to.equal('240p')
235 expect(file240p.size).to.be.above(180000).and.below(200000)
237 const file360p = videoDetails.files.find(f => f.resolution === 360)
238 expect(file360p).not.to.be.undefined
239 expect(file360p.resolutionLabel).to.equal('360p')
240 expect(file360p.size).to.be.above(270000).and.below(290000)
242 const file480p = videoDetails.files.find(f => f.resolution === 480)
243 expect(file480p).not.to.be.undefined
244 expect(file480p.resolutionLabel).to.equal('480p')
245 expect(file480p.size).to.be.above(380000).and.below(400000)
247 const file720p = videoDetails.files.find(f => f.resolution === 720)
248 expect(file720p).not.to.be.undefined
249 expect(file720p.resolutionLabel).to.equal('720p')
250 expect(file720p.size).to.be.above(700000).and.below(7200000)
252 const test = await testVideoImage(server.url, 'video_short2.webm', videoDetails.thumbnailPath)
253 expect(test).to.equal(true)
257 it('Should upload two videos on server 3 and propagate on each server', async function () {
260 const videoAttributes1 = {
261 name: 'my super name for server 3',
266 description: 'my super description for server 3',
268 fixture: 'video_short3.webm'
270 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1)
272 const videoAttributes2 = {
273 name: 'my super name for server 3-2',
278 description: 'my super description for server 3-2',
279 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
280 fixture: 'video_short.webm'
282 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2)
286 let baseMagnet = null
287 // All servers should have this video
288 for (const server of servers) {
289 const res = await getVideosList(server.url)
291 const videos = res.body.data
292 expect(videos).to.be.an('array')
293 expect(videos.length).to.equal(4)
295 // We not sure about the order of the two last uploads
298 if (videos[2].name === 'my super name for server 3') {
306 expect(video1.name).to.equal('my super name for server 3')
307 expect(video1.category).to.equal(6)
308 expect(video1.categoryLabel).to.equal('Travels')
309 expect(video1.licence).to.equal(5)
310 expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike')
311 expect(video1.language).to.equal(11)
312 expect(video1.languageLabel).to.equal('German')
313 expect(video1.nsfw).to.be.ok
314 expect(video1.description).to.equal('my super description for server 3')
315 expect(video1.serverHost).to.equal('localhost:9003')
316 expect(video1.duration).to.equal(5)
317 expect(video1.tags).to.deep.equal([ 'tag1p3' ])
318 expect(video1.account).to.equal('root')
319 expect(dateIsValid(video1.createdAt)).to.be.true
320 expect(dateIsValid(video1.updatedAt)).to.be.true
322 const res2 = await getVideo(server.url, video1.id)
323 const video1Details = res2.body
324 expect(video1Details.files).to.have.lengthOf(1)
326 const file1 = video1Details.files[0]
327 expect(file1.magnetUri).to.have.lengthOf.above(2)
328 expect(file1.resolution).to.equal(720)
329 expect(file1.resolutionLabel).to.equal('720p')
330 expect(file1.size).to.equal(292677)
332 expect(video2.name).to.equal('my super name for server 3-2')
333 expect(video2.category).to.equal(7)
334 expect(video2.categoryLabel).to.equal('Gaming')
335 expect(video2.licence).to.equal(6)
336 expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
337 expect(video2.language).to.equal(12)
338 expect(video2.languageLabel).to.equal('Korean')
339 expect(video2.nsfw).to.be.false
340 expect(video2.description).to.equal('my super description for server 3-2')
341 expect(video2.serverHost).to.equal('localhost:9003')
342 expect(video2.duration).to.equal(5)
343 expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
344 expect(video2.account).to.equal('root')
345 expect(dateIsValid(video2.createdAt)).to.be.true
346 expect(dateIsValid(video2.updatedAt)).to.be.true
348 const res3 = await getVideo(server.url, video2.id)
349 const video2Details = res3.body
351 expect(video2Details.files).to.have.lengthOf(1)
353 const file2 = video2Details.files[0]
354 const magnetUri2 = file2.magnetUri
355 expect(file2.magnetUri).to.have.lengthOf.above(2)
356 expect(file2.resolution).to.equal(720)
357 expect(file2.resolutionLabel).to.equal('720p')
358 expect(file2.size).to.equal(218910)
360 if (server.url !== 'http://localhost:9003') {
361 expect(video1.isLocal).to.be.false
362 expect(video2.isLocal).to.be.false
364 expect(video1.isLocal).to.be.true
365 expect(video2.isLocal).to.be.true
368 // All servers should have the same magnet Uri
369 if (baseMagnet === null) {
370 baseMagnet = magnetUri2
372 expect(baseMagnet).to.equal(magnetUri2)
375 const test1 = await testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath)
376 expect(test1).to.equal(true)
378 const test2 = await testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath)
379 expect(test2).to.equal(true)
384 describe('Should seed the uploaded video', function () {
385 it('Should add the file 1 by asking server 3', async function () {
388 const res = await getVideosList(servers[2].url)
390 const video = res.body.data[0]
391 toRemove.push(res.body.data[2])
392 toRemove.push(res.body.data[3])
394 const res2 = await getVideo(servers[2].url, video.id)
395 const videoDetails = res2.body
397 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
398 expect(torrent.files).to.be.an('array')
399 expect(torrent.files.length).to.equal(1)
400 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
403 it('Should add the file 2 by asking server 1', async function () {
406 const res = await getVideosList(servers[0].url)
408 const video = res.body.data[1]
409 const res2 = await getVideo(servers[0].url, video.id)
410 const videoDetails = res2.body
412 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
413 expect(torrent.files).to.be.an('array')
414 expect(torrent.files.length).to.equal(1)
415 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
418 it('Should add the file 3 by asking server 2', async function () {
421 const res = await getVideosList(servers[1].url)
423 const video = res.body.data[2]
424 const res2 = await getVideo(servers[1].url, video.id)
425 const videoDetails = res2.body
427 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
428 expect(torrent.files).to.be.an('array')
429 expect(torrent.files.length).to.equal(1)
430 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
433 it('Should add the file 3-2 by asking server 1', async function () {
436 const res = await getVideosList(servers[0].url)
438 const video = res.body.data[3]
439 const res2 = await getVideo(servers[0].url, video.id)
440 const videoDetails = res2.body
442 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
443 expect(torrent.files).to.be.an('array')
444 expect(torrent.files.length).to.equal(1)
445 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
448 it('Should add the file 2 in 360p by asking server 1', async function () {
451 const res = await getVideosList(servers[0].url)
453 const video = res.body.data.find(v => v.name === 'my super name for server 2')
454 const res2 = await getVideo(servers[0].url, video.id)
455 const videoDetails = res2.body
457 const file = videoDetails.files.find(f => f.resolution === 360)
458 expect(file).not.to.be.undefined
460 const torrent = await webtorrentAdd(file.magnetUri)
461 expect(torrent.files).to.be.an('array')
462 expect(torrent.files.length).to.equal(1)
463 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
467 describe('Should update video views, likes and dislikes', function () {
468 let localVideosServer3 = []
469 let remoteVideosServer1 = []
470 let remoteVideosServer2 = []
471 let remoteVideosServer3 = []
473 before(async function () {
474 const res1 = await getVideosList(servers[0].url)
475 remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
477 const res2 = await getVideosList(servers[1].url)
478 remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
480 const res3 = await getVideosList(servers[2].url)
481 localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid)
482 remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
485 it('Should view multiple videos on owned servers', async function () {
488 const tasks: Promise<any>[] = []
489 tasks.push(getVideo(servers[2].url, localVideosServer3[0]))
490 tasks.push(getVideo(servers[2].url, localVideosServer3[0]))
491 tasks.push(getVideo(servers[2].url, localVideosServer3[0]))
492 tasks.push(getVideo(servers[2].url, localVideosServer3[1]))
494 await Promise.all(tasks)
498 for (const server of servers) {
499 const res = await getVideosList(server.url)
501 const videos = res.body.data
502 const video0 = videos.find(v => v.uuid === localVideosServer3[0])
503 const video1 = videos.find(v => v.uuid === localVideosServer3[1])
505 expect(video0.views).to.equal(7)
506 expect(video1.views).to.equal(5)
510 it('Should view multiple videos on each servers', async function () {
513 const tasks: Promise<any>[] = []
514 tasks.push(getVideo(servers[0].url, remoteVideosServer1[0]))
515 tasks.push(getVideo(servers[1].url, remoteVideosServer2[0]))
516 tasks.push(getVideo(servers[1].url, remoteVideosServer2[0]))
517 tasks.push(getVideo(servers[2].url, remoteVideosServer3[0]))
518 tasks.push(getVideo(servers[2].url, remoteVideosServer3[1]))
519 tasks.push(getVideo(servers[2].url, remoteVideosServer3[1]))
520 tasks.push(getVideo(servers[2].url, remoteVideosServer3[1]))
521 tasks.push(getVideo(servers[2].url, localVideosServer3[1]))
522 tasks.push(getVideo(servers[2].url, localVideosServer3[1]))
523 tasks.push(getVideo(servers[2].url, localVideosServer3[1]))
525 await Promise.all(tasks)
529 let baseVideos = null
531 for (const server of servers) {
532 const res = await getVideosList(server.url)
534 const videos = res.body.data
536 // Initialize base videos for future comparisons
537 if (baseVideos === null) {
542 for (const baseVideo of baseVideos) {
543 const sameVideo = videos.find(video => video.name === baseVideo.name)
544 expect(baseVideo.views).to.equal(sameVideo.views)
549 it('Should like and dislikes videos on different services', async function () {
552 const tasks: Promise<any>[] = []
553 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like'))
554 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike'))
555 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like'))
556 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like'))
557 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike'))
558 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike'))
559 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like'))
561 await Promise.all(tasks)
565 let baseVideos = null
566 for (const server of servers) {
567 const res = await getVideosList(server.url)
569 const videos = res.body.data
571 // Initialize base videos for future comparisons
572 if (baseVideos === null) {
577 for (const baseVideo of baseVideos) {
578 const sameVideo = videos.find(video => video.name === baseVideo.name)
579 expect(baseVideo.likes).to.equal(sameVideo.likes)
580 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
586 describe('Should manipulate these videos', function () {
587 it('Should update the video 3 by asking server 3', async function () {
591 name: 'my super video updated',
596 description: 'my super description updated',
597 tags: [ 'tag_up_1', 'tag_up_2' ]
600 await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes)
605 it('Should have the video 3 updated on each server', async function () {
608 for (const server of servers) {
609 const res = await getVideosList(server.url)
611 const videos = res.body.data
612 const videoUpdated = videos.find(video => video.name === 'my super video updated')
614 expect(!!videoUpdated).to.be.true
615 expect(videoUpdated.category).to.equal(10)
616 expect(videoUpdated.categoryLabel).to.equal('Entertainment')
617 expect(videoUpdated.licence).to.equal(7)
618 expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication')
619 expect(videoUpdated.language).to.equal(13)
620 expect(videoUpdated.languageLabel).to.equal('French')
621 expect(videoUpdated.nsfw).to.be.ok
622 expect(videoUpdated.description).to.equal('my super description updated')
623 expect(videoUpdated.tags).to.deep.equal([ 'tag_up_1', 'tag_up_2' ])
624 expect(dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
626 const res2 = await getVideo(server.url, videoUpdated.uuid)
627 const videoUpdatedDetails = res2.body
629 const file = videoUpdatedDetails .files[0]
630 expect(file.magnetUri).to.have.lengthOf.above(2)
631 expect(file.resolution).to.equal(720)
632 expect(file.resolutionLabel).to.equal('720p')
633 expect(file.size).to.equal(292677)
635 const test = await testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath)
636 expect(test).to.equal(true)
638 // Avoid "duplicate torrent" errors
639 const refreshWebTorrent = true
640 const torrent = await webtorrentAdd(videoUpdatedDetails .files[0].magnetUri, refreshWebTorrent)
641 expect(torrent.files).to.be.an('array')
642 expect(torrent.files.length).to.equal(1)
643 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
647 it('Should remove the videos 3 and 3-2 by asking server 3', async function () {
650 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id)
651 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id)
656 it('Should have videos 1 and 3 on each server', async function () {
657 for (const server of servers) {
658 const res = await getVideosList(server.url)
660 const videos = res.body.data
661 expect(videos).to.be.an('array')
662 expect(videos.length).to.equal(2)
663 expect(videos[0].name).not.to.equal(videos[1].name)
664 expect(videos[0].name).not.to.equal(toRemove[0].name)
665 expect(videos[1].name).not.to.equal(toRemove[0].name)
666 expect(videos[0].name).not.to.equal(toRemove[1].name)
667 expect(videos[1].name).not.to.equal(toRemove[1].name)
669 videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid
673 it('Should get the same video by UUID on each server', async function () {
675 for (const server of servers) {
676 const res = await getVideo(server.url, videoUUID)
678 const video = res.body
680 if (baseVideo === null) {
685 expect(baseVideo.name).to.equal(video.name)
686 expect(baseVideo.uuid).to.equal(video.uuid)
687 expect(baseVideo.category).to.equal(video.category)
688 expect(baseVideo.language).to.equal(video.language)
689 expect(baseVideo.licence).to.equal(video.licence)
690 expect(baseVideo.category).to.equal(video.category)
691 expect(baseVideo.nsfw).to.equal(video.nsfw)
692 expect(baseVideo.account).to.equal(video.account)
693 expect(baseVideo.tags).to.deep.equal(video.tags)
697 it('Should get the preview from each server', async function () {
698 for (const server of servers) {
699 const res = await getVideo(server.url, videoUUID)
700 const video = res.body
702 const test = await testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath)
703 expect(test).to.equal(true)
708 after(async function () {
709 killallServers(servers)
711 // Keep the logs if the test failed