1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
8 flushAndRunMultipleServers,
16 setAccessTokensToServers,
27 import { createUser } from '../utils/users'
28 import { viewVideo } from '../utils/videos'
30 const expect = chai.expect
32 describe('Test multiple servers', function () {
33 let servers: ServerInfo[] = []
36 let videoChannelId: number
38 before(async function () {
41 servers = await flushAndRunMultipleServers(3)
43 // Get the access tokens
44 await setAccessTokensToServers(servers)
46 const videoChannel = {
48 description: 'super channel'
50 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
51 const channelRes = await getVideoChannelsList(servers[0].url, 0, 1)
52 videoChannelId = channelRes.body.data[0].id
54 // Server 1 and server 2 follow each other
55 await doubleFollow(servers[0], servers[1])
56 // Server 1 and server 3 follow each other
57 await doubleFollow(servers[0], servers[2])
58 // Server 2 and server 3 follow each other
59 await doubleFollow(servers[1], servers[2])
62 it('Should not have videos for all servers', async function () {
63 for (const server of servers) {
64 const res = await getVideosList(server.url)
65 const videos = res.body.data
66 expect(videos).to.be.an('array')
67 expect(videos.length).to.equal(0)
71 describe('Should upload the video and propagate on each server', function () {
72 it('Should upload the video on server 1 and propagate on each server', async function () {
75 const videoAttributes = {
76 name: 'my super name for server 1',
81 description: 'my super description for server 1',
82 tags: [ 'tag1p1', 'tag2p1' ],
83 channelId: videoChannelId,
84 fixture: 'video_short1.webm'
86 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
90 // All servers should have this video
91 for (const server of servers) {
94 const res = await getVideosList(server.url)
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.accountName).to.equal('root')
116 const res2 = await getVideo(server.url, video.uuid)
117 const videoDetails = res2.body
119 expect(videoDetails.channel.name).to.equal('my channel')
120 expect(videoDetails.channel.description).to.equal('super channel')
121 expect(videoDetails.account.name).to.equal('root')
122 expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true
123 expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true
124 expect(videoDetails.files).to.have.lengthOf(1)
126 const file = videoDetails.files[0]
127 const magnetUri = file.magnetUri
128 expect(file.magnetUri).to.have.lengthOf.above(2)
129 expect(file.torrentUrl).to
130 .equal(`http://${videoDetails.serverHost}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
131 expect(file.fileUrl).to.equal(`http://${videoDetails.serverHost}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)
132 expect(file.resolution).to.equal(720)
133 expect(file.resolutionLabel).to.equal('720p')
134 expect(file.size).to.equal(572456)
136 if (server.url !== 'http://localhost:9001') {
137 expect(video.isLocal).to.be.false
138 expect(videoDetails.channel.isLocal).to.be.false
140 expect(video.isLocal).to.be.true
141 expect(videoDetails.channel.isLocal).to.be.true
144 // All servers should have the same magnet Uri
145 if (baseMagnet === null) {
146 baseMagnet = magnetUri
148 expect(baseMagnet).to.equal(magnetUri)
151 const test = await testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath)
152 expect(test).to.equal(true)
156 it('Should upload the video on server 2 and propagate on each server', async function () {
161 password: 'super_password'
163 await createUser(servers[1].url, servers[1].accessToken, user.username, user.password)
164 const userAccessToken = await getUserAccessToken(servers[1], user)
166 const videoAttributes = {
167 name: 'my super name for server 2',
172 description: 'my super description for server 2',
173 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
174 fixture: 'video_short2.webm'
176 await uploadVideo(servers[1].url, userAccessToken, videoAttributes)
181 // All servers should have this video
182 for (const server of servers) {
185 const res = await getVideosList(server.url)
187 const videos = res.body.data
188 expect(videos).to.be.an('array')
189 expect(videos.length).to.equal(2)
190 const video = videos[1]
191 expect(video.name).to.equal('my super name for server 2')
192 expect(video.category).to.equal(4)
193 expect(video.categoryLabel).to.equal('Art')
194 expect(video.licence).to.equal(3)
195 expect(video.licenceLabel).to.equal('Attribution - No Derivatives')
196 expect(video.language).to.equal(11)
197 expect(video.languageLabel).to.equal('German')
198 expect(video.nsfw).to.be.true
199 expect(video.description).to.equal('my super description for server 2')
200 expect(video.serverHost).to.equal('localhost:9002')
201 expect(video.duration).to.equal(5)
202 expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
203 expect(dateIsValid(video.createdAt)).to.be.true
204 expect(dateIsValid(video.updatedAt)).to.be.true
205 expect(video.accountName).to.equal('user1')
207 if (server.url !== 'http://localhost:9002') {
208 expect(video.isLocal).to.be.false
210 expect(video.isLocal).to.be.true
213 const res2 = await getVideo(server.url, video.uuid)
214 const videoDetails = res2.body
216 expect(videoDetails.channel.name).to.equal('Default user1 channel')
217 expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true
218 expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true
220 expect(videoDetails.files).to.have.lengthOf(4)
222 // Check common attributes
223 for (const file of videoDetails.files) {
224 expect(file.magnetUri).to.have.lengthOf.above(2)
226 // All servers should have the same magnet Uri
227 if (baseMagnet[file.resolution] === undefined) {
228 baseMagnet[file.resolution] = file.magnet
230 expect(baseMagnet[file.resolution]).to.equal(file.magnet)
234 const file240p = videoDetails.files.find(f => f.resolution === 240)
235 expect(file240p).not.to.be.undefined
236 expect(file240p.resolutionLabel).to.equal('240p')
237 expect(file240p.size).to.be.above(180000).and.below(200000)
239 const file360p = videoDetails.files.find(f => f.resolution === 360)
240 expect(file360p).not.to.be.undefined
241 expect(file360p.resolutionLabel).to.equal('360p')
242 expect(file360p.size).to.be.above(270000).and.below(290000)
244 const file480p = videoDetails.files.find(f => f.resolution === 480)
245 expect(file480p).not.to.be.undefined
246 expect(file480p.resolutionLabel).to.equal('480p')
247 expect(file480p.size).to.be.above(380000).and.below(400000)
249 const file720p = videoDetails.files.find(f => f.resolution === 720)
250 expect(file720p).not.to.be.undefined
251 expect(file720p.resolutionLabel).to.equal('720p')
252 expect(file720p.size).to.be.above(700000).and.below(7200000)
254 const test = await testVideoImage(server.url, 'video_short2.webm', videoDetails.thumbnailPath)
255 expect(test).to.equal(true)
259 it('Should upload two videos on server 3 and propagate on each server', async function () {
262 const videoAttributes1 = {
263 name: 'my super name for server 3',
268 description: 'my super description for server 3',
270 fixture: 'video_short3.webm'
272 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1)
274 const videoAttributes2 = {
275 name: 'my super name for server 3-2',
280 description: 'my super description for server 3-2',
281 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
282 fixture: 'video_short.webm'
284 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2)
288 let baseMagnet = null
289 // All servers should have this video
290 for (const server of servers) {
291 const res = await getVideosList(server.url)
293 const videos = res.body.data
294 expect(videos).to.be.an('array')
295 expect(videos.length).to.equal(4)
297 // We not sure about the order of the two last uploads
300 if (videos[2].name === 'my super name for server 3') {
308 expect(video1.name).to.equal('my super name for server 3')
309 expect(video1.category).to.equal(6)
310 expect(video1.categoryLabel).to.equal('Travels')
311 expect(video1.licence).to.equal(5)
312 expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike')
313 expect(video1.language).to.equal(11)
314 expect(video1.languageLabel).to.equal('German')
315 expect(video1.nsfw).to.be.ok
316 expect(video1.description).to.equal('my super description for server 3')
317 expect(video1.serverHost).to.equal('localhost:9003')
318 expect(video1.duration).to.equal(5)
319 expect(video1.tags).to.deep.equal([ 'tag1p3' ])
320 expect(video1.accountName).to.equal('root')
321 expect(dateIsValid(video1.createdAt)).to.be.true
322 expect(dateIsValid(video1.updatedAt)).to.be.true
324 const res2 = await getVideo(server.url, video1.id)
325 const video1Details = res2.body
326 expect(video1Details.files).to.have.lengthOf(1)
328 const file1 = video1Details.files[0]
329 expect(file1.magnetUri).to.have.lengthOf.above(2)
330 expect(file1.resolution).to.equal(720)
331 expect(file1.resolutionLabel).to.equal('720p')
332 expect(file1.size).to.equal(292677)
334 expect(video2.name).to.equal('my super name for server 3-2')
335 expect(video2.category).to.equal(7)
336 expect(video2.categoryLabel).to.equal('Gaming')
337 expect(video2.licence).to.equal(6)
338 expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
339 expect(video2.language).to.equal(12)
340 expect(video2.languageLabel).to.equal('Korean')
341 expect(video2.nsfw).to.be.false
342 expect(video2.description).to.equal('my super description for server 3-2')
343 expect(video2.serverHost).to.equal('localhost:9003')
344 expect(video2.duration).to.equal(5)
345 expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
346 expect(video2.accountName).to.equal('root')
347 expect(dateIsValid(video2.createdAt)).to.be.true
348 expect(dateIsValid(video2.updatedAt)).to.be.true
350 const res3 = await getVideo(server.url, video2.id)
351 const video2Details = res3.body
353 expect(video2Details.files).to.have.lengthOf(1)
355 const file2 = video2Details.files[0]
356 const magnetUri2 = file2.magnetUri
357 expect(file2.magnetUri).to.have.lengthOf.above(2)
358 expect(file2.resolution).to.equal(720)
359 expect(file2.resolutionLabel).to.equal('720p')
360 expect(file2.size).to.equal(218910)
362 if (server.url !== 'http://localhost:9003') {
363 expect(video1.isLocal).to.be.false
364 expect(video2.isLocal).to.be.false
366 expect(video1.isLocal).to.be.true
367 expect(video2.isLocal).to.be.true
370 // All servers should have the same magnet Uri
371 if (baseMagnet === null) {
372 baseMagnet = magnetUri2
374 expect(baseMagnet).to.equal(magnetUri2)
377 const test1 = await testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath)
378 expect(test1).to.equal(true)
380 const test2 = await testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath)
381 expect(test2).to.equal(true)
386 describe('Should seed the uploaded video', function () {
387 it('Should add the file 1 by asking server 3', async function () {
390 const res = await getVideosList(servers[2].url)
392 const video = res.body.data[0]
393 toRemove.push(res.body.data[2])
394 toRemove.push(res.body.data[3])
396 const res2 = await getVideo(servers[2].url, video.id)
397 const videoDetails = res2.body
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('')
405 it('Should add the file 2 by asking server 1', async function () {
408 const res = await getVideosList(servers[0].url)
410 const video = res.body.data[1]
411 const res2 = await getVideo(servers[0].url, video.id)
412 const videoDetails = res2.body
414 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
415 expect(torrent.files).to.be.an('array')
416 expect(torrent.files.length).to.equal(1)
417 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
420 it('Should add the file 3 by asking server 2', async function () {
423 const res = await getVideosList(servers[1].url)
425 const video = res.body.data[2]
426 const res2 = await getVideo(servers[1].url, video.id)
427 const videoDetails = res2.body
429 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
430 expect(torrent.files).to.be.an('array')
431 expect(torrent.files.length).to.equal(1)
432 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
435 it('Should add the file 3-2 by asking server 1', async function () {
438 const res = await getVideosList(servers[0].url)
440 const video = res.body.data[3]
441 const res2 = await getVideo(servers[0].url, video.id)
442 const videoDetails = res2.body
444 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
445 expect(torrent.files).to.be.an('array')
446 expect(torrent.files.length).to.equal(1)
447 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
450 it('Should add the file 2 in 360p by asking server 1', async function () {
453 const res = await getVideosList(servers[0].url)
455 const video = res.body.data.find(v => v.name === 'my super name for server 2')
456 const res2 = await getVideo(servers[0].url, video.id)
457 const videoDetails = res2.body
459 const file = videoDetails.files.find(f => f.resolution === 360)
460 expect(file).not.to.be.undefined
462 const torrent = await webtorrentAdd(file.magnetUri)
463 expect(torrent.files).to.be.an('array')
464 expect(torrent.files.length).to.equal(1)
465 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
469 describe('Should update video views, likes and dislikes', function () {
470 let localVideosServer3 = []
471 let remoteVideosServer1 = []
472 let remoteVideosServer2 = []
473 let remoteVideosServer3 = []
475 before(async function () {
476 const res1 = await getVideosList(servers[0].url)
477 remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
479 const res2 = await getVideosList(servers[1].url)
480 remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
482 const res3 = await getVideosList(servers[2].url)
483 localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid)
484 remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
487 it('Should view multiple videos on owned servers', async function () {
490 const tasks: Promise<any>[] = []
491 tasks.push(viewVideo(servers[2].url, localVideosServer3[0]))
492 tasks.push(viewVideo(servers[2].url, localVideosServer3[0]))
493 tasks.push(viewVideo(servers[2].url, localVideosServer3[0]))
494 tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
496 await Promise.all(tasks)
500 for (const server of servers) {
501 const res = await getVideosList(server.url)
503 const videos = res.body.data
504 const video0 = videos.find(v => v.uuid === localVideosServer3[0])
505 const video1 = videos.find(v => v.uuid === localVideosServer3[1])
507 expect(video0.views).to.equal(3)
508 expect(video1.views).to.equal(1)
512 it('Should view multiple videos on each servers', async function () {
515 const tasks: Promise<any>[] = []
516 tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0]))
517 tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0]))
518 tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0]))
519 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0]))
520 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
521 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
522 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
523 tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
524 tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
525 tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
527 await Promise.all(tasks)
531 let baseVideos = null
533 for (const server of servers) {
534 const res = await getVideosList(server.url)
536 const videos = res.body.data
538 // Initialize base videos for future comparisons
539 if (baseVideos === null) {
544 for (const baseVideo of baseVideos) {
545 const sameVideo = videos.find(video => video.name === baseVideo.name)
546 expect(baseVideo.views).to.equal(sameVideo.views)
551 it('Should like and dislikes videos on different services', async function () {
554 const tasks: Promise<any>[] = []
555 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like'))
556 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike'))
557 tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like'))
558 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like'))
559 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike'))
560 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike'))
561 tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like'))
563 await Promise.all(tasks)
567 let baseVideos = null
568 for (const server of servers) {
569 const res = await getVideosList(server.url)
571 const videos = res.body.data
573 // Initialize base videos for future comparisons
574 if (baseVideos === null) {
579 for (const baseVideo of baseVideos) {
580 const sameVideo = videos.find(video => video.name === baseVideo.name)
581 expect(baseVideo.likes).to.equal(sameVideo.likes)
582 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
588 describe('Should manipulate these videos', function () {
589 it('Should update the video 3 by asking server 3', async function () {
593 name: 'my super video updated',
598 description: 'my super description updated',
599 tags: [ 'tag_up_1', 'tag_up_2' ]
602 await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes)
607 it('Should have the video 3 updated on each server', async function () {
610 for (const server of servers) {
611 const res = await getVideosList(server.url)
613 const videos = res.body.data
614 const videoUpdated = videos.find(video => video.name === 'my super video updated')
616 expect(!!videoUpdated).to.be.true
617 expect(videoUpdated.category).to.equal(10)
618 expect(videoUpdated.categoryLabel).to.equal('Entertainment')
619 expect(videoUpdated.licence).to.equal(7)
620 expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication')
621 expect(videoUpdated.language).to.equal(13)
622 expect(videoUpdated.languageLabel).to.equal('French')
623 expect(videoUpdated.nsfw).to.be.ok
624 expect(videoUpdated.description).to.equal('my super description updated')
625 expect(videoUpdated.tags).to.deep.equal([ 'tag_up_1', 'tag_up_2' ])
626 expect(dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
628 const res2 = await getVideo(server.url, videoUpdated.uuid)
629 const videoUpdatedDetails = res2.body
631 const file = videoUpdatedDetails .files[0]
632 expect(file.magnetUri).to.have.lengthOf.above(2)
633 expect(file.resolution).to.equal(720)
634 expect(file.resolutionLabel).to.equal('720p')
635 expect(file.size).to.equal(292677)
637 const test = await testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath)
638 expect(test).to.equal(true)
640 // Avoid "duplicate torrent" errors
641 const refreshWebTorrent = true
642 const torrent = await webtorrentAdd(videoUpdatedDetails .files[0].magnetUri, refreshWebTorrent)
643 expect(torrent.files).to.be.an('array')
644 expect(torrent.files.length).to.equal(1)
645 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
649 it('Should remove the videos 3 and 3-2 by asking server 3', async function () {
652 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id)
653 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id)
658 it('Should have videos 1 and 3 on each server', async function () {
659 for (const server of servers) {
660 const res = await getVideosList(server.url)
662 const videos = res.body.data
663 expect(videos).to.be.an('array')
664 expect(videos.length).to.equal(2)
665 expect(videos[0].name).not.to.equal(videos[1].name)
666 expect(videos[0].name).not.to.equal(toRemove[0].name)
667 expect(videos[1].name).not.to.equal(toRemove[0].name)
668 expect(videos[0].name).not.to.equal(toRemove[1].name)
669 expect(videos[1].name).not.to.equal(toRemove[1].name)
671 videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid
675 it('Should get the same video by UUID on each server', async function () {
677 for (const server of servers) {
678 const res = await getVideo(server.url, videoUUID)
680 const video = res.body
682 if (baseVideo === null) {
687 expect(baseVideo.name).to.equal(video.name)
688 expect(baseVideo.uuid).to.equal(video.uuid)
689 expect(baseVideo.category).to.equal(video.category)
690 expect(baseVideo.language).to.equal(video.language)
691 expect(baseVideo.licence).to.equal(video.licence)
692 expect(baseVideo.category).to.equal(video.category)
693 expect(baseVideo.nsfw).to.equal(video.nsfw)
694 expect(baseVideo.accountName).to.equal(video.accountName)
695 expect(baseVideo.tags).to.deep.equal(video.tags)
699 it('Should get the preview from each server', async function () {
700 for (const server of servers) {
701 const res = await getVideo(server.url, videoUUID)
702 const video = res.body
704 const test = await testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath)
705 expect(test).to.equal(true)
710 after(async function () {
711 killallServers(servers)
713 // Keep the logs if the test failed