1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { join } from 'path'
6 import * as request from 'supertest'
7 import { VideoPrivacy } from '../../../../shared/models/videos'
8 import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
11 addVideoChannel, checkVideoFilesWereRemoved, completeVideoCheck, createUser, dateIsValid, doubleFollow, flushAndRunMultipleServers,
13 getVideoChannelsList, getVideosList, killallServers, rateVideo, removeVideo, ServerInfo, setAccessTokensToServers, testImage,
14 updateVideo, uploadVideo, userLogin, viewVideo, wait, webtorrentAdd
17 addVideoCommentReply, addVideoCommentThread, deleteVideoComment, getVideoCommentThreads,
18 getVideoThreadComments
19 } from '../../utils/videos/video-comments'
21 const expect = chai.expect
23 describe('Test multiple servers', function () {
24 let servers: ServerInfo[] = []
27 let videoChannelId: number
29 before(async function () {
32 servers = await flushAndRunMultipleServers(3)
34 // Get the access tokens
35 await setAccessTokensToServers(servers)
37 const videoChannel = {
39 description: 'super channel'
41 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
42 const channelRes = await getVideoChannelsList(servers[0].url, 0, 1)
43 videoChannelId = channelRes.body.data[0].id
45 // Server 1 and server 2 follow each other
46 await doubleFollow(servers[0], servers[1])
47 // Server 1 and server 3 follow each other
48 await doubleFollow(servers[0], servers[2])
49 // Server 2 and server 3 follow each other
50 await doubleFollow(servers[1], servers[2])
53 it('Should not have videos for all servers', async function () {
54 for (const server of servers) {
55 const res = await getVideosList(server.url)
56 const videos = res.body.data
57 expect(videos).to.be.an('array')
58 expect(videos.length).to.equal(0)
62 describe('Should upload the video and propagate on each server', function () {
63 it('Should upload the video on server 1 and propagate on each server', async function () {
66 const videoAttributes = {
67 name: 'my super name for server 1',
72 description: 'my super description for server 1',
73 support: 'my super support text for server 1',
74 tags: [ 'tag1p1', 'tag2p1' ],
75 channelId: videoChannelId,
76 fixture: 'video_short1.webm'
78 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
82 // All servers should have this video
83 for (const server of servers) {
84 const isLocal = server.url === 'http://localhost:9001'
85 const checkAttributes = {
86 name: 'my super name for server 1',
91 description: 'my super description for server 1',
92 support: 'my super support text for server 1',
93 host: 'localhost:9001',
97 tags: [ 'tag1p1', 'tag2p1' ],
98 privacy: VideoPrivacy.PUBLIC,
99 commentsEnabled: true,
102 description: 'super channel',
105 fixture: 'video_short1.webm',
114 const res = await getVideosList(server.url)
115 const videos = res.body.data
116 expect(videos).to.be.an('array')
117 expect(videos.length).to.equal(1)
118 const video = videos[0]
120 await completeVideoCheck(server.url, video, checkAttributes)
124 it('Should upload the video on server 2 and propagate on each server', async function () {
129 password: 'super_password'
131 await createUser(servers[1].url, servers[1].accessToken, user.username, user.password)
132 const userAccessToken = await userLogin(servers[1], user)
134 const videoAttributes = {
135 name: 'my super name for server 2',
140 description: 'my super description for server 2',
141 support: 'my super support text for server 2',
142 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
143 fixture: 'video_short2.webm',
144 thumbnailfile: 'thumbnail.jpg',
145 previewfile: 'preview.jpg'
147 await uploadVideo(servers[1].url, userAccessToken, videoAttributes)
152 // All servers should have this video
153 for (const server of servers) {
154 const isLocal = server.url === 'http://localhost:9002'
155 const checkAttributes = {
156 name: 'my super name for server 2',
161 description: 'my super description for server 2',
162 support: 'my super support text for server 2',
163 host: 'localhost:9002',
166 commentsEnabled: true,
168 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
169 privacy: VideoPrivacy.PUBLIC,
171 name: 'Default user1 channel',
172 description: 'super channel',
175 fixture: 'video_short2.webm',
194 thumbnailfile: 'thumbnail',
195 previewfile: 'preview'
198 const res = await getVideosList(server.url)
199 const videos = res.body.data
200 expect(videos).to.be.an('array')
201 expect(videos.length).to.equal(2)
202 const video = videos[1]
204 await completeVideoCheck(server.url, video, checkAttributes)
208 it('Should upload two videos on server 3 and propagate on each server', async function () {
211 const videoAttributes1 = {
212 name: 'my super name for server 3',
217 description: 'my super description for server 3',
218 support: 'my super support text for server 3',
220 fixture: 'video_short3.webm'
222 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1)
224 const videoAttributes2 = {
225 name: 'my super name for server 3-2',
230 description: 'my super description for server 3-2',
231 support: 'my super support text for server 3-2',
232 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
233 fixture: 'video_short.webm'
235 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2)
239 // All servers should have this video
240 for (const server of servers) {
241 const isLocal = server.url === 'http://localhost:9003'
242 const res = await getVideosList(server.url)
244 const videos = res.body.data
245 expect(videos).to.be.an('array')
246 expect(videos.length).to.equal(4)
248 // We not sure about the order of the two last uploads
251 if (videos[2].name === 'my super name for server 3') {
259 const checkAttributesVideo1 = {
260 name: 'my super name for server 3',
265 description: 'my super description for server 3',
266 support: 'my super support text for server 3',
267 host: 'localhost:9003',
271 commentsEnabled: true,
273 privacy: VideoPrivacy.PUBLIC,
275 name: 'Default root channel',
279 fixture: 'video_short3.webm',
287 await completeVideoCheck(server.url, video1, checkAttributesVideo1)
289 const checkAttributesVideo2 = {
290 name: 'my super name for server 3-2',
295 description: 'my super description for server 3-2',
296 support: 'my super support text for server 3-2',
297 host: 'localhost:9003',
299 commentsEnabled: true,
302 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
303 privacy: VideoPrivacy.PUBLIC,
305 name: 'Default root channel',
309 fixture: 'video_short.webm',
317 await completeVideoCheck(server.url, video2, checkAttributesVideo2)
322 describe('Should seed the uploaded video', function () {
323 it('Should add the file 1 by asking server 3', async function () {
326 const res = await getVideosList(servers[2].url)
328 const video = res.body.data[0]
329 toRemove.push(res.body.data[2])
330 toRemove.push(res.body.data[3])
332 const res2 = await getVideo(servers[2].url, video.id)
333 const videoDetails = res2.body
335 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
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 server 1', async function () {
344 const res = await getVideosList(servers[0].url)
346 const video = res.body.data[1]
347 const res2 = await getVideo(servers[0].url, video.id)
348 const videoDetails = res2.body
350 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
351 expect(torrent.files).to.be.an('array')
352 expect(torrent.files.length).to.equal(1)
353 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
356 it('Should add the file 3 by asking server 2', async function () {
359 const res = await getVideosList(servers[1].url)
361 const video = res.body.data[2]
362 const res2 = await getVideo(servers[1].url, video.id)
363 const videoDetails = res2.body
365 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
366 expect(torrent.files).to.be.an('array')
367 expect(torrent.files.length).to.equal(1)
368 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
371 it('Should add the file 3-2 by asking server 1', async function () {
374 const res = await getVideosList(servers[0].url)
376 const video = res.body.data[3]
377 const res2 = await getVideo(servers[0].url, video.id)
378 const videoDetails = res2.body
380 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
381 expect(torrent.files).to.be.an('array')
382 expect(torrent.files.length).to.equal(1)
383 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
386 it('Should add the file 2 in 360p by asking server 1', async function () {
389 const res = await getVideosList(servers[0].url)
391 const video = res.body.data.find(v => v.name === 'my super name for server 2')
392 const res2 = await getVideo(servers[0].url, video.id)
393 const videoDetails = res2.body
395 const file = videoDetails.files.find(f => f.resolution === 360)
396 expect(file).not.to.be.undefined
398 const torrent = await webtorrentAdd(file.magnetUri)
399 expect(torrent.files).to.be.an('array')
400 expect(torrent.files.length).to.equal(1)
401 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
405 describe('Should update video views, likes and dislikes', function () {
406 let localVideosServer3 = []
407 let remoteVideosServer1 = []
408 let remoteVideosServer2 = []
409 let remoteVideosServer3 = []
411 before(async function () {
412 const res1 = await getVideosList(servers[0].url)
413 remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
415 const res2 = await getVideosList(servers[1].url)
416 remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
418 const res3 = await getVideosList(servers[2].url)
419 localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid)
420 remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
423 it('Should view multiple videos on owned servers', async function () {
426 const tasks: Promise<any>[] = []
427 await viewVideo(servers[2].url, localVideosServer3[0])
428 await viewVideo(servers[2].url, localVideosServer3[0])
429 await viewVideo(servers[2].url, localVideosServer3[0])
430 await viewVideo(servers[2].url, localVideosServer3[1])
432 await Promise.all(tasks)
435 await viewVideo(servers[2].url, localVideosServer3[0])
439 await viewVideo(servers[2].url, localVideosServer3[0])
443 for (const server of servers) {
444 const res = await getVideosList(server.url)
446 const videos = res.body.data
447 const video0 = videos.find(v => v.uuid === localVideosServer3[0])
448 const video1 = videos.find(v => v.uuid === localVideosServer3[1])
450 expect(video0.views).to.equal(3)
451 expect(video1.views).to.equal(1)
455 it('Should view multiple videos on each servers', async function () {
458 const tasks: Promise<any>[] = []
459 tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0]))
460 tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0]))
461 tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0]))
462 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0]))
463 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
464 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
465 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
466 tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
467 tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
468 tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
470 await Promise.all(tasks)
474 let baseVideos = null
476 for (const server of servers) {
477 const res = await getVideosList(server.url)
479 const videos = res.body.data
481 // Initialize base videos for future comparisons
482 if (baseVideos === null) {
487 for (const baseVideo of baseVideos) {
488 const sameVideo = videos.find(video => video.name === baseVideo.name)
489 expect(baseVideo.views).to.equal(sameVideo.views)
494 it('Should like and dislikes videos on different services', async function () {
497 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')
499 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike')
501 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')
502 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like')
504 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike')
505 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike')
507 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like')
511 let baseVideos = null
512 for (const server of servers) {
513 const res = await getVideosList(server.url)
515 const videos = res.body.data
517 // Initialize base videos for future comparisons
518 if (baseVideos === null) {
523 for (const baseVideo of baseVideos) {
524 const sameVideo = videos.find(video => video.name === baseVideo.name)
525 expect(baseVideo.likes).to.equal(sameVideo.likes)
526 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
532 describe('Should manipulate these videos', function () {
533 it('Should update the video 3 by asking server 3', async function () {
537 name: 'my super video updated',
542 description: 'my super description updated',
543 support: 'my super support text updated',
544 tags: [ 'tag_up_1', 'tag_up_2' ],
545 thumbnailfile: 'thumbnail.jpg',
546 previewfile: 'preview.jpg'
549 await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes)
554 it('Should have the video 3 updated on each server', async function () {
557 for (const server of servers) {
558 const res = await getVideosList(server.url)
560 const videos = res.body.data
561 const videoUpdated = videos.find(video => video.name === 'my super video updated')
562 expect(!!videoUpdated).to.be.true
564 const isLocal = server.url === 'http://localhost:9003'
565 const checkAttributes = {
566 name: 'my super video updated',
571 description: 'my super description updated',
572 support: 'my super support text updated',
573 host: 'localhost:9003',
577 commentsEnabled: true,
578 tags: [ 'tag_up_1', 'tag_up_2' ],
579 privacy: VideoPrivacy.PUBLIC,
581 name: 'Default root channel',
585 fixture: 'video_short3.webm',
592 thumbnailfile: 'thumbnail',
593 previewfile: 'preview'
595 await completeVideoCheck(server.url, videoUpdated, checkAttributes)
599 it('Should remove the videos 3 and 3-2 by asking server 3', async function () {
602 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id)
603 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id)
608 it('Should not have files of videos 3 and 3-2 on each server', async function () {
609 for (const server of servers) {
610 await checkVideoFilesWereRemoved(toRemove[0].uuid, server.serverNumber)
611 await checkVideoFilesWereRemoved(toRemove[1].uuid, server.serverNumber)
615 it('Should have videos 1 and 3 on each server', async function () {
616 for (const server of servers) {
617 const res = await getVideosList(server.url)
619 const videos = res.body.data
620 expect(videos).to.be.an('array')
621 expect(videos.length).to.equal(2)
622 expect(videos[0].name).not.to.equal(videos[1].name)
623 expect(videos[0].name).not.to.equal(toRemove[0].name)
624 expect(videos[1].name).not.to.equal(toRemove[0].name)
625 expect(videos[0].name).not.to.equal(toRemove[1].name)
626 expect(videos[1].name).not.to.equal(toRemove[1].name)
628 videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid
632 it('Should get the same video by UUID on each server', async function () {
634 for (const server of servers) {
635 const res = await getVideo(server.url, videoUUID)
637 const video = res.body
639 if (baseVideo === null) {
644 expect(baseVideo.name).to.equal(video.name)
645 expect(baseVideo.uuid).to.equal(video.uuid)
646 expect(baseVideo.category).to.equal(video.category)
647 expect(baseVideo.language).to.equal(video.language)
648 expect(baseVideo.licence).to.equal(video.licence)
649 expect(baseVideo.category).to.equal(video.category)
650 expect(baseVideo.nsfw).to.equal(video.nsfw)
651 expect(baseVideo.accountName).to.equal(video.accountName)
652 expect(baseVideo.tags).to.deep.equal(video.tags)
656 it('Should get the preview from each server', async function () {
657 for (const server of servers) {
658 const res = await getVideo(server.url, videoUUID)
659 const video = res.body
661 await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
666 describe('Should comment these videos', function () {
667 it('Should add comment (threads and replies)', async function () {
671 const text = 'my super first comment'
672 await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID, text)
676 const text = 'my super second comment'
677 await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, text)
683 const res = await getVideoCommentThreads(servers[1].url, videoUUID, 0, 5)
684 const threadId = res.body.data.find(c => c.text === 'my super first comment').id
686 const text = 'my super answer to thread 1'
687 await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, videoUUID, threadId, text)
693 const res1 = await getVideoCommentThreads(servers[2].url, videoUUID, 0, 5)
694 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
696 const res2 = await getVideoThreadComments(servers[2].url, videoUUID, threadId)
697 const childCommentId = res2.body.children[0].comment.id
699 const text3 = 'my second answer to thread 1'
700 await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, threadId, text3)
702 const text2 = 'my super answer to answer of thread 1'
703 await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, childCommentId, text2)
709 it('Should have these threads', async function () {
710 for (const server of servers) {
711 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
713 expect(res.body.total).to.equal(2)
714 expect(res.body.data).to.be.an('array')
715 expect(res.body.data).to.have.lengthOf(2)
718 const comment: VideoComment = res.body.data.find(c => c.text === 'my super first comment')
719 expect(comment).to.not.be.undefined
720 expect(comment.inReplyToCommentId).to.be.null
721 expect(comment.account.name).to.equal('root')
722 expect(comment.account.host).to.equal('localhost:9001')
723 expect(comment.totalReplies).to.equal(3)
724 expect(dateIsValid(comment.createdAt as string)).to.be.true
725 expect(dateIsValid(comment.updatedAt as string)).to.be.true
729 const comment: VideoComment = res.body.data.find(c => c.text === 'my super second comment')
730 expect(comment).to.not.be.undefined
731 expect(comment.inReplyToCommentId).to.be.null
732 expect(comment.account.name).to.equal('root')
733 expect(comment.account.host).to.equal('localhost:9003')
734 expect(comment.totalReplies).to.equal(0)
735 expect(dateIsValid(comment.createdAt as string)).to.be.true
736 expect(dateIsValid(comment.updatedAt as string)).to.be.true
741 it('Should have these comments', async function () {
742 for (const server of servers) {
743 const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
744 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
746 const res2 = await getVideoThreadComments(server.url, videoUUID, threadId)
748 const tree: VideoCommentThreadTree = res2.body
749 expect(tree.comment.text).equal('my super first comment')
750 expect(tree.comment.account.name).equal('root')
751 expect(tree.comment.account.host).equal('localhost:9001')
752 expect(tree.children).to.have.lengthOf(2)
754 const firstChild = tree.children[0]
755 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
756 expect(firstChild.comment.account.name).equal('root')
757 expect(firstChild.comment.account.host).equal('localhost:9002')
758 expect(firstChild.children).to.have.lengthOf(1)
760 const childOfFirstChild = firstChild.children[0]
761 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
762 expect(childOfFirstChild.comment.account.name).equal('root')
763 expect(childOfFirstChild.comment.account.host).equal('localhost:9003')
764 expect(childOfFirstChild.children).to.have.lengthOf(0)
766 const secondChild = tree.children[1]
767 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
768 expect(secondChild.comment.account.name).equal('root')
769 expect(secondChild.comment.account.host).equal('localhost:9003')
770 expect(secondChild.children).to.have.lengthOf(0)
774 it('Should delete the thread comments', async function () {
777 const res1 = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5)
778 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
779 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
784 it('Should have the thread comments deleted on other servers too', async function () {
785 for (const server of servers) {
786 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
788 expect(res.body.total).to.equal(1)
789 expect(res.body.data).to.be.an('array')
790 expect(res.body.data).to.have.lengthOf(1)
793 const comment: VideoComment = res.body.data[0]
794 expect(comment).to.not.be.undefined
795 expect(comment.inReplyToCommentId).to.be.null
796 expect(comment.account.name).to.equal('root')
797 expect(comment.account.host).to.equal('localhost:9003')
798 expect(comment.totalReplies).to.equal(0)
799 expect(dateIsValid(comment.createdAt as string)).to.be.true
800 expect(dateIsValid(comment.updatedAt as string)).to.be.true
805 it('Should disable comments', async function () {
809 commentsEnabled: false
812 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes)
816 for (const server of servers) {
817 const res = await getVideo(server.url, videoUUID)
818 expect(res.body.commentsEnabled).to.be.false
820 const text = 'my super forbidden comment'
821 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, 409)
826 describe('With minimum parameters', function () {
827 it('Should upload and propagate the video', async function () {
830 const path = '/api/v1/videos/upload'
832 const req = request(servers[1].url)
834 .set('Accept', 'application/json')
835 .set('Authorization', 'Bearer ' + servers[1].accessToken)
836 .field('name', 'minimum parameters')
837 .field('privacy', '1')
838 .field('nsfw', 'false')
839 .field('channelId', '1')
840 .field('commentsEnabled', 'true')
842 const filePath = join(__dirname, '..', '..', 'api', 'fixtures', 'video_short.webm')
844 await req.attach('videofile', filePath)
849 for (const server of servers) {
850 const res = await getVideosList(server.url)
851 const video = res.body.data.find(v => v.name === 'minimum parameters')
853 const isLocal = server.url === 'http://localhost:9002'
854 const checkAttributes = {
855 name: 'minimum parameters',
862 host: 'localhost:9002',
866 commentsEnabled: true,
868 privacy: VideoPrivacy.PUBLIC,
870 name: 'Default root channel',
874 fixture: 'video_short.webm',
894 await completeVideoCheck(server.url, video, checkAttributes)
899 after(async function () {
900 killallServers(servers)
902 // Keep the logs if the test failed