1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { JobState } from '../../../../shared/models'
6 import { VideoPrivacy } from '../../../../shared/models/videos'
7 import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
8 import { completeVideoCheck, getVideo, immutableAssign, reRunServer, viewVideo } from '../../utils'
11 flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo,
13 } from '../../utils/index'
14 import { follow, getFollowersListPaginationAndSort } from '../../utils/server/follows'
15 import { getJobsListPaginationAndSort } from '../../utils/server/jobs'
17 addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads,
18 getVideoThreadComments
19 } from '../../utils/videos/video-comments'
21 const expect = chai.expect
23 describe('Test handle downs', function () {
24 let servers: ServerInfo[] = []
26 let threadIdServer1: number
27 let threadIdServer2: number
28 let commentIdServer1: number
29 let commentIdServer2: number
31 const videoAttributes = {
32 name: 'my super name for server 1',
37 privacy: VideoPrivacy.PUBLIC,
38 description: 'my super description for server 1',
39 tags: [ 'tag1p1', 'tag2p1' ],
40 fixture: 'video_short1.webm'
43 const unlistedVideoAttributes = immutableAssign(videoAttributes, {
44 privacy: VideoPrivacy.UNLISTED
47 const checkAttributes = {
48 name: 'my super name for server 1',
53 description: 'my super description for server 1',
54 host: 'localhost:9001',
58 tags: [ 'tag1p1', 'tag2p1' ],
59 privacy: VideoPrivacy.PUBLIC,
60 commentsEnabled: true,
62 name: 'Default root channel',
66 fixture: 'video_short1.webm',
75 const unlistedCheckAttributes = immutableAssign(checkAttributes, {
76 privacy: VideoPrivacy.UNLISTED
79 before(async function () {
82 servers = await flushAndRunMultipleServers(2)
84 // Get the access tokens
85 await setAccessTokensToServers(servers)
88 it('Should remove followers that are often down', async function () {
91 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
95 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
99 for (const server of servers) {
100 const res = await getVideosList(server.url)
101 expect(res.body.data).to.be.an('array')
102 expect(res.body.data).to.have.lengthOf(1)
106 killallServers([ servers[1] ])
108 let resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, unlistedVideoAttributes)
109 videos.push(resVideo.body.video)
111 // Remove server 2 follower
112 for (let i = 0; i < 10; i++) {
113 resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
114 videos.push(resVideo.body.video)
119 await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
121 // Add comments to video 2
123 const text = 'thread 1'
124 let resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videos[1].uuid, text)
125 let comment = resComment.body.comment
126 threadIdServer1 = comment.id
128 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, comment.id, 'comment 1-1')
129 comment = resComment.body.comment
131 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, comment.id, 'comment 1-2')
132 commentIdServer1 = resComment.body.comment.id
137 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt')
138 expect(res.body.data).to.be.an('array')
139 expect(res.body.data).to.have.lengthOf(0)
142 it('Should not have pending/processing jobs anymore', async function () {
143 const states: JobState[] = [ 'inactive', 'active' ]
145 for (const state of states) {
146 const res = await getJobsListPaginationAndSort(servers[ 0 ].url, servers[ 0 ].accessToken, state,0, 50, '-createdAt')
147 expect(res.body.data).to.have.length(0)
151 it('Should follow server 1', async function () {
154 await reRunServer(servers[1])
156 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
160 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt')
161 expect(res.body.data).to.be.an('array')
162 expect(res.body.data).to.have.lengthOf(1)
165 it('Should send a view to server 2, and automatically fetch the video', async function () {
168 await viewVideo(servers[0].url, videos[0].uuid)
172 const res = await getVideosList(servers[1].url)
173 expect(res.body.data).to.be.an('array')
175 expect(res.body.data).to.have.lengthOf(1)
177 const resVideo = await getVideo(servers[1].url, videos[0].uuid)
178 expect(resVideo.body).not.to.be.undefined
180 await completeVideoCheck(servers[1].url, resVideo.body, unlistedCheckAttributes)
183 it('Should send comments on a video to server 2, and automatically fetch the video', async function () {
186 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, commentIdServer1, 'comment 1-3')
190 const resVideo = await getVideo(servers[1].url, videos[0].uuid)
191 expect(resVideo.body).not.to.be.undefined
193 await completeVideoCheck(servers[1].url, resVideo.body, unlistedCheckAttributes)
196 let resComment = await getVideoCommentThreads(servers[1].url, videos[1].uuid, 0, 5)
197 expect(resComment.body.data).to.be.an('array')
198 expect(resComment.body.data).to.have.lengthOf(1)
200 threadIdServer2 = resComment.body.data[0].id
202 resComment = await getVideoThreadComments(servers[1].url, videos[1].uuid, threadIdServer2)
204 const tree: VideoCommentThreadTree = resComment.body
205 expect(tree.comment.text).equal('thread 1')
206 expect(tree.children).to.have.lengthOf(1)
208 const firstChild = tree.children[0]
209 expect(firstChild.comment.text).to.equal('comment 1-1')
210 expect(firstChild.children).to.have.lengthOf(1)
212 const childOfFirstChild = firstChild.children[0]
213 expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
214 expect(childOfFirstChild.children).to.have.lengthOf(1)
216 const childOfChildFirstChild = childOfFirstChild.children[0]
217 expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
218 expect(childOfChildFirstChild.children).to.have.lengthOf(0)
220 commentIdServer2 = childOfChildFirstChild.comment.id
224 it('Should correctly reply to the comment', async function () {
227 await addVideoCommentReply(servers[1].url, servers[1].accessToken, videos[1].uuid, commentIdServer2, 'comment 1-4')
232 const resComment = await getVideoThreadComments(servers[0].url, videos[1].uuid, threadIdServer1)
234 const tree: VideoCommentThreadTree = resComment.body
235 expect(tree.comment.text).equal('thread 1')
236 expect(tree.children).to.have.lengthOf(1)
238 const firstChild = tree.children[0]
239 expect(firstChild.comment.text).to.equal('comment 1-1')
240 expect(firstChild.children).to.have.lengthOf(1)
242 const childOfFirstChild = firstChild.children[0]
243 expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
244 expect(childOfFirstChild.children).to.have.lengthOf(1)
246 const childOfChildFirstChild = childOfFirstChild.children[0]
247 expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
248 expect(childOfChildFirstChild.children).to.have.lengthOf(1)
250 const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0]
251 expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4')
252 expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0)
256 after(async function () {
257 killallServers(servers)
259 // Keep the logs if the test failed