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'
10 flushAndRunMultipleServers,
14 setAccessTokensToServers,
17 } from '../../utils/index'
18 import { follow, getFollowersListPaginationAndSort } from '../../utils/server/follows'
19 import { getJobsListPaginationAndSort, waitJobs } from '../../utils/server/jobs'
22 addVideoCommentThread,
23 getVideoCommentThreads,
24 getVideoThreadComments
25 } from '../../utils/videos/video-comments'
27 const expect = chai.expect
29 describe('Test handle downs', function () {
30 let servers: ServerInfo[] = []
32 let threadIdServer1: number
33 let threadIdServer2: number
34 let commentIdServer1: number
35 let commentIdServer2: number
37 const videoAttributes = {
38 name: 'my super name for server 1',
43 privacy: VideoPrivacy.PUBLIC,
44 description: 'my super description for server 1',
45 support: 'my super support text for server 1',
46 tags: [ 'tag1p1', 'tag2p1' ],
47 fixture: 'video_short1.webm'
50 const unlistedVideoAttributes = immutableAssign(videoAttributes, {
51 privacy: VideoPrivacy.UNLISTED
54 const checkAttributes = {
55 name: 'my super name for server 1',
60 description: 'my super description for server 1',
61 support: 'my super support text for server 1',
64 host: 'localhost:9001'
68 tags: [ 'tag1p1', 'tag2p1' ],
69 privacy: VideoPrivacy.PUBLIC,
70 commentsEnabled: true,
72 name: 'Default root channel',
76 fixture: 'video_short1.webm',
85 const unlistedCheckAttributes = immutableAssign(checkAttributes, {
86 privacy: VideoPrivacy.UNLISTED
89 before(async function () {
92 servers = await flushAndRunMultipleServers(2)
94 // Get the access tokens
95 await setAccessTokensToServers(servers)
98 it('Should remove followers that are often down', async function () {
101 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
103 await waitJobs(servers)
105 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
107 await waitJobs(servers)
109 for (const server of servers) {
110 const res = await getVideosList(server.url)
111 expect(res.body.data).to.be.an('array')
112 expect(res.body.data).to.have.lengthOf(1)
116 killallServers([ servers[1] ])
118 let resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, unlistedVideoAttributes)
119 videos.push(resVideo.body.video)
121 // Remove server 2 follower
122 for (let i = 0; i < 10; i++) {
123 resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
124 videos.push(resVideo.body.video)
127 await waitJobs(servers[0])
129 await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
131 // Add comments to video 2
133 const text = 'thread 1'
134 let resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videos[1].uuid, text)
135 let comment = resComment.body.comment
136 threadIdServer1 = comment.id
138 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, comment.id, 'comment 1-1')
139 comment = resComment.body.comment
141 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, comment.id, 'comment 1-2')
142 commentIdServer1 = resComment.body.comment.id
145 await waitJobs(servers[0])
149 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt')
150 expect(res.body.data).to.be.an('array')
151 expect(res.body.data).to.have.lengthOf(0)
154 it('Should not have pending/processing jobs anymore', async function () {
155 const states: JobState[] = [ 'waiting', 'active' ]
157 for (const state of states) {
158 const res = await getJobsListPaginationAndSort(servers[ 0 ].url, servers[ 0 ].accessToken, state,0, 50, '-createdAt')
159 expect(res.body.data).to.have.length(0)
163 it('Should follow server 1', async function () {
166 await reRunServer(servers[1])
168 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
170 await waitJobs(servers)
172 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt')
173 expect(res.body.data).to.be.an('array')
174 expect(res.body.data).to.have.lengthOf(1)
177 it('Should send a view to server 2, and automatically fetch the video', async function () {
180 await viewVideo(servers[0].url, videos[0].uuid)
182 await waitJobs(servers)
184 const res = await getVideosList(servers[1].url)
185 expect(res.body.data).to.be.an('array')
187 expect(res.body.data).to.have.lengthOf(1)
189 const resVideo = await getVideo(servers[1].url, videos[0].uuid)
190 expect(resVideo.body).not.to.be.undefined
192 await completeVideoCheck(servers[1].url, resVideo.body, unlistedCheckAttributes)
195 it('Should send comments on a video to server 2, and automatically fetch the video', async function () {
198 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, commentIdServer1, 'comment 1-3')
200 await waitJobs(servers)
202 const resVideo = await getVideo(servers[1].url, videos[0].uuid)
203 expect(resVideo.body).not.to.be.undefined
205 await completeVideoCheck(servers[1].url, resVideo.body, unlistedCheckAttributes)
208 let resComment = await getVideoCommentThreads(servers[1].url, videos[1].uuid, 0, 5)
209 expect(resComment.body.data).to.be.an('array')
210 expect(resComment.body.data).to.have.lengthOf(1)
212 threadIdServer2 = resComment.body.data[0].id
214 resComment = await getVideoThreadComments(servers[1].url, videos[1].uuid, threadIdServer2)
216 const tree: VideoCommentThreadTree = resComment.body
217 expect(tree.comment.text).equal('thread 1')
218 expect(tree.children).to.have.lengthOf(1)
220 const firstChild = tree.children[0]
221 expect(firstChild.comment.text).to.equal('comment 1-1')
222 expect(firstChild.children).to.have.lengthOf(1)
224 const childOfFirstChild = firstChild.children[0]
225 expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
226 expect(childOfFirstChild.children).to.have.lengthOf(1)
228 const childOfChildFirstChild = childOfFirstChild.children[0]
229 expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
230 expect(childOfChildFirstChild.children).to.have.lengthOf(0)
232 commentIdServer2 = childOfChildFirstChild.comment.id
236 it('Should correctly reply to the comment', async function () {
239 await addVideoCommentReply(servers[1].url, servers[1].accessToken, videos[1].uuid, commentIdServer2, 'comment 1-4')
241 await waitJobs(servers)
244 const resComment = await getVideoThreadComments(servers[0].url, videos[1].uuid, threadIdServer1)
246 const tree: VideoCommentThreadTree = resComment.body
247 expect(tree.comment.text).equal('thread 1')
248 expect(tree.children).to.have.lengthOf(1)
250 const firstChild = tree.children[0]
251 expect(firstChild.comment.text).to.equal('comment 1-1')
252 expect(firstChild.children).to.have.lengthOf(1)
254 const childOfFirstChild = firstChild.children[0]
255 expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
256 expect(childOfFirstChild.children).to.have.lengthOf(1)
258 const childOfChildFirstChild = childOfFirstChild.children[0]
259 expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
260 expect(childOfChildFirstChild.children).to.have.lengthOf(1)
262 const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0]
263 expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4')
264 expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0)
268 after(async function () {
269 killallServers(servers)