1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { JobState, Video } from '../../../../shared/models'
6 import { VideoPrivacy } from '../../../../shared/models/videos'
7 import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
12 flushAndRunMultipleServers,
19 setAccessTokensToServers,
24 } from '../../../../shared/extra-utils'
25 import { follow, getFollowersListPaginationAndSort } from '../../../../shared/extra-utils/server/follows'
26 import { getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs'
29 addVideoCommentThread,
30 getVideoCommentThreads,
31 getVideoThreadComments
32 } from '../../../../shared/extra-utils/videos/video-comments'
34 const expect = chai.expect
36 describe('Test handle downs', function () {
37 let servers: ServerInfo[] = []
38 let threadIdServer1: number
39 let threadIdServer2: number
40 let commentIdServer1: number
41 let commentIdServer2: number
42 let missedVideo1: Video
43 let missedVideo2: Video
44 let unlistedVideo: Video
46 const videoAttributes = {
47 name: 'my super name for server 1',
52 privacy: VideoPrivacy.PUBLIC,
53 description: 'my super description for server 1',
54 support: 'my super support text for server 1',
55 tags: [ 'tag1p1', 'tag2p1' ],
56 fixture: 'video_short1.webm'
59 const unlistedVideoAttributes = immutableAssign(videoAttributes, {
60 privacy: VideoPrivacy.UNLISTED
63 let checkAttributes: any
64 let unlistedCheckAttributes: any
66 before(async function () {
69 servers = await flushAndRunMultipleServers(3)
72 name: 'my super name for server 1',
77 description: 'my super description for server 1',
78 support: 'my super support text for server 1',
81 host: 'localhost:' + servers[0].port
85 tags: [ 'tag1p1', 'tag2p1' ],
86 privacy: VideoPrivacy.PUBLIC,
87 commentsEnabled: true,
88 downloadEnabled: true,
91 displayName: 'Main root channel',
95 fixture: 'video_short1.webm',
103 unlistedCheckAttributes = immutableAssign(checkAttributes, {
104 privacy: VideoPrivacy.UNLISTED
107 // Get the access tokens
108 await setAccessTokensToServers(servers)
111 it('Should remove followers that are often down', async function () {
114 // Server 2 and 3 follow server 1
115 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
116 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
118 await waitJobs(servers)
120 // Upload a video to server 1
121 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
123 await waitJobs(servers)
125 // And check all servers have this video
126 for (const server of servers) {
127 const res = await getVideosList(server.url)
128 expect(res.body.data).to.be.an('array')
129 expect(res.body.data).to.have.lengthOf(1)
133 killallServers([ servers[1] ])
135 // Remove server 2 follower
136 for (let i = 0; i < 10; i++) {
137 await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
140 await waitJobs(servers[0])
143 killallServers([ servers[2] ])
145 const resLastVideo1 = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
146 missedVideo1 = resLastVideo1.body.video
148 const resLastVideo2 = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
149 missedVideo2 = resLastVideo2.body.video
152 let resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, unlistedVideoAttributes)
153 unlistedVideo = resVideo.body.video
155 // Add comments to video 2
157 const text = 'thread 1'
158 let resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, missedVideo2.uuid, text)
159 let comment = resComment.body.comment
160 threadIdServer1 = comment.id
162 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-1')
163 comment = resComment.body.comment
165 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-2')
166 commentIdServer1 = resComment.body.comment.id
169 await waitJobs(servers[0])
173 // Only server 3 is still a follower of server 1
174 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt')
175 expect(res.body.data).to.be.an('array')
176 expect(res.body.data).to.have.lengthOf(1)
177 expect(res.body.data[0].follower.host).to.equal('localhost:' + servers[2].port)
180 it('Should not have pending/processing jobs anymore', async function () {
181 const states: JobState[] = [ 'waiting', 'active' ]
183 for (const state of states) {
184 const res = await getJobsListPaginationAndSort(servers[ 0 ].url, servers[ 0 ].accessToken, state,0, 50, '-createdAt')
185 expect(res.body.data).to.have.length(0)
189 it('Should re-follow server 1', async function () {
192 await reRunServer(servers[1])
193 await reRunServer(servers[2])
195 await unfollow(servers[1].url, servers[1].accessToken, servers[0])
196 await waitJobs(servers)
198 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
200 await waitJobs(servers)
202 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt')
203 expect(res.body.data).to.be.an('array')
204 expect(res.body.data).to.have.lengthOf(2)
207 it('Should send an update to server 3, and automatically fetch the video', async function () {
210 const res1 = await getVideosList(servers[2].url)
211 expect(res1.body.data).to.be.an('array')
212 expect(res1.body.data).to.have.lengthOf(11)
214 await updateVideo(servers[0].url, servers[0].accessToken, missedVideo1.uuid, { })
215 await updateVideo(servers[0].url, servers[0].accessToken, unlistedVideo.uuid, { })
217 await waitJobs(servers)
219 const res = await getVideosList(servers[2].url)
220 expect(res.body.data).to.be.an('array')
221 // 1 video is unlisted
222 expect(res.body.data).to.have.lengthOf(12)
224 // Check unlisted video
225 const resVideo = await getVideo(servers[2].url, unlistedVideo.uuid)
226 expect(resVideo.body).not.to.be.undefined
228 await completeVideoCheck(servers[2].url, resVideo.body, unlistedCheckAttributes)
231 it('Should send comments on a video to server 3, and automatically fetch the video', async function () {
234 await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, commentIdServer1, 'comment 1-3')
236 await waitJobs(servers)
238 const resVideo = await getVideo(servers[2].url, missedVideo2.uuid)
239 expect(resVideo.body).not.to.be.undefined
242 let resComment = await getVideoCommentThreads(servers[2].url, missedVideo2.uuid, 0, 5)
243 expect(resComment.body.data).to.be.an('array')
244 expect(resComment.body.data).to.have.lengthOf(1)
246 threadIdServer2 = resComment.body.data[0].id
248 resComment = await getVideoThreadComments(servers[2].url, missedVideo2.uuid, threadIdServer2)
250 const tree: VideoCommentThreadTree = resComment.body
251 expect(tree.comment.text).equal('thread 1')
252 expect(tree.children).to.have.lengthOf(1)
254 const firstChild = tree.children[0]
255 expect(firstChild.comment.text).to.equal('comment 1-1')
256 expect(firstChild.children).to.have.lengthOf(1)
258 const childOfFirstChild = firstChild.children[0]
259 expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
260 expect(childOfFirstChild.children).to.have.lengthOf(1)
262 const childOfChildFirstChild = childOfFirstChild.children[0]
263 expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
264 expect(childOfChildFirstChild.children).to.have.lengthOf(0)
266 commentIdServer2 = childOfChildFirstChild.comment.id
270 it('Should correctly reply to the comment', async function () {
273 await addVideoCommentReply(servers[2].url, servers[2].accessToken, missedVideo2.uuid, commentIdServer2, 'comment 1-4')
275 await waitJobs(servers)
278 const resComment = await getVideoThreadComments(servers[0].url, missedVideo2.uuid, threadIdServer1)
280 const tree: VideoCommentThreadTree = resComment.body
281 expect(tree.comment.text).equal('thread 1')
282 expect(tree.children).to.have.lengthOf(1)
284 const firstChild = tree.children[0]
285 expect(firstChild.comment.text).to.equal('comment 1-1')
286 expect(firstChild.children).to.have.lengthOf(1)
288 const childOfFirstChild = firstChild.children[0]
289 expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
290 expect(childOfFirstChild.children).to.have.lengthOf(1)
292 const childOfChildFirstChild = childOfFirstChild.children[0]
293 expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
294 expect(childOfChildFirstChild.children).to.have.lengthOf(1)
296 const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0]
297 expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4')
298 expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0)
302 after(async function () {
303 await cleanupTests(servers)