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'
15 flushAndRunMultipleServers,
19 setAccessTokensToServers,
22 } from '../../../../shared/utils'
23 import { follow, getFollowersListPaginationAndSort } from '../../../../shared/utils/server/follows'
24 import { getJobsListPaginationAndSort, waitJobs } from '../../../../shared/utils/server/jobs'
27 addVideoCommentThread,
28 getVideoCommentThreads,
29 getVideoThreadComments
30 } from '../../../../shared/utils/videos/video-comments'
32 const expect = chai.expect
34 describe('Test handle downs', function () {
35 let servers: ServerInfo[] = []
36 let threadIdServer1: number
37 let threadIdServer2: number
38 let commentIdServer1: number
39 let commentIdServer2: number
40 let missedVideo1: Video
41 let missedVideo2: Video
42 let unlistedVideo: Video
44 const videoAttributes = {
45 name: 'my super name for server 1',
50 privacy: VideoPrivacy.PUBLIC,
51 description: 'my super description for server 1',
52 support: 'my super support text for server 1',
53 tags: [ 'tag1p1', 'tag2p1' ],
54 fixture: 'video_short1.webm'
57 const unlistedVideoAttributes = immutableAssign(videoAttributes, {
58 privacy: VideoPrivacy.UNLISTED
61 const checkAttributes = {
62 name: 'my super name for server 1',
67 description: 'my super description for server 1',
68 support: 'my super support text for server 1',
71 host: 'localhost:9001'
75 tags: [ 'tag1p1', 'tag2p1' ],
76 privacy: VideoPrivacy.PUBLIC,
77 commentsEnabled: true,
80 displayName: 'Main root channel',
84 fixture: 'video_short1.webm',
93 const unlistedCheckAttributes = immutableAssign(checkAttributes, {
94 privacy: VideoPrivacy.UNLISTED
97 before(async function () {
100 servers = await flushAndRunMultipleServers(3)
102 // Get the access tokens
103 await setAccessTokensToServers(servers)
106 it('Should remove followers that are often down', async function () {
109 // Server 2 and 3 follow server 1
110 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
111 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
113 await waitJobs(servers)
115 // Upload a video to server 1
116 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
118 await waitJobs(servers)
120 // And check all servers have this video
121 for (const server of servers) {
122 const res = await getVideosList(server.url)
123 expect(res.body.data).to.be.an('array')
124 expect(res.body.data).to.have.lengthOf(1)
128 killallServers([ servers[1] ])
130 // Remove server 2 follower
131 for (let i = 0; i < 10; i++) {
132 await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
135 await waitJobs(servers[0])
138 killallServers([ servers[2] ])
140 const resLastVideo1 = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
141 missedVideo1 = resLastVideo1.body.video
143 const resLastVideo2 = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
144 missedVideo2 = resLastVideo2.body.video
147 let resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, unlistedVideoAttributes)
148 unlistedVideo = resVideo.body.video
150 // Add comments to video 2
152 const text = 'thread 1'
153 let resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, missedVideo2.uuid, text)
154 let comment = resComment.body.comment
155 threadIdServer1 = comment.id
157 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-1')
158 comment = resComment.body.comment
160 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-2')
161 commentIdServer1 = resComment.body.comment.id
164 await waitJobs(servers[0])
168 // Only server 3 is still a follower of server 1
169 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt')
170 expect(res.body.data).to.be.an('array')
171 expect(res.body.data).to.have.lengthOf(1)
172 expect(res.body.data[0].follower.host).to.equal('localhost:9003')
175 it('Should not have pending/processing jobs anymore', async function () {
176 const states: JobState[] = [ 'waiting', 'active' ]
178 for (const state of states) {
179 const res = await getJobsListPaginationAndSort(servers[ 0 ].url, servers[ 0 ].accessToken, state,0, 50, '-createdAt')
180 expect(res.body.data).to.have.length(0)
184 it('Should re-follow server 1', async function () {
187 await reRunServer(servers[1])
188 await reRunServer(servers[2])
190 await unfollow(servers[1].url, servers[1].accessToken, servers[0])
191 await waitJobs(servers)
193 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
195 await waitJobs(servers)
197 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt')
198 expect(res.body.data).to.be.an('array')
199 expect(res.body.data).to.have.lengthOf(2)
202 it('Should send a view to server 3, and automatically fetch the video', async function () {
205 const res1 = await getVideosList(servers[2].url)
206 expect(res1.body.data).to.be.an('array')
207 expect(res1.body.data).to.have.lengthOf(11)
209 await viewVideo(servers[0].url, missedVideo1.uuid)
210 await viewVideo(servers[0].url, unlistedVideo.uuid)
212 await waitJobs(servers)
214 const res = await getVideosList(servers[2].url)
215 expect(res.body.data).to.be.an('array')
216 // 1 video is unlisted
217 expect(res.body.data).to.have.lengthOf(12)
219 // Check unlisted video
220 const resVideo = await getVideo(servers[2].url, unlistedVideo.uuid)
221 expect(resVideo.body).not.to.be.undefined
223 await completeVideoCheck(servers[2].url, resVideo.body, unlistedCheckAttributes)
226 it('Should send comments on a video to server 3, and automatically fetch the video', async function () {
229 await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, commentIdServer1, 'comment 1-3')
231 await waitJobs(servers)
233 const resVideo = await getVideo(servers[2].url, missedVideo2.uuid)
234 expect(resVideo.body).not.to.be.undefined
237 let resComment = await getVideoCommentThreads(servers[2].url, missedVideo2.uuid, 0, 5)
238 expect(resComment.body.data).to.be.an('array')
239 expect(resComment.body.data).to.have.lengthOf(1)
241 threadIdServer2 = resComment.body.data[0].id
243 resComment = await getVideoThreadComments(servers[2].url, missedVideo2.uuid, threadIdServer2)
245 const tree: VideoCommentThreadTree = resComment.body
246 expect(tree.comment.text).equal('thread 1')
247 expect(tree.children).to.have.lengthOf(1)
249 const firstChild = tree.children[0]
250 expect(firstChild.comment.text).to.equal('comment 1-1')
251 expect(firstChild.children).to.have.lengthOf(1)
253 const childOfFirstChild = firstChild.children[0]
254 expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
255 expect(childOfFirstChild.children).to.have.lengthOf(1)
257 const childOfChildFirstChild = childOfFirstChild.children[0]
258 expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
259 expect(childOfChildFirstChild.children).to.have.lengthOf(0)
261 commentIdServer2 = childOfChildFirstChild.comment.id
265 it('Should correctly reply to the comment', async function () {
268 await addVideoCommentReply(servers[2].url, servers[2].accessToken, missedVideo2.uuid, commentIdServer2, 'comment 1-4')
270 await waitJobs(servers)
273 const resComment = await getVideoThreadComments(servers[0].url, missedVideo2.uuid, threadIdServer1)
275 const tree: VideoCommentThreadTree = resComment.body
276 expect(tree.comment.text).equal('thread 1')
277 expect(tree.children).to.have.lengthOf(1)
279 const firstChild = tree.children[0]
280 expect(firstChild.comment.text).to.equal('comment 1-1')
281 expect(firstChild.children).to.have.lengthOf(1)
283 const childOfFirstChild = firstChild.children[0]
284 expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
285 expect(childOfFirstChild.children).to.have.lengthOf(1)
287 const childOfChildFirstChild = childOfFirstChild.children[0]
288 expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
289 expect(childOfChildFirstChild.children).to.have.lengthOf(1)
291 const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0]
292 expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4')
293 expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0)
297 after(async function () {
298 killallServers(servers)