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, waitJobs } 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 support: 'my super support text for server 1',
40 tags: [ 'tag1p1', 'tag2p1' ],
41 fixture: 'video_short1.webm'
44 const unlistedVideoAttributes = immutableAssign(videoAttributes, {
45 privacy: VideoPrivacy.UNLISTED
48 const checkAttributes = {
49 name: 'my super name for server 1',
54 description: 'my super description for server 1',
55 support: 'my super support text for server 1',
58 host: 'localhost:9001'
62 tags: [ 'tag1p1', 'tag2p1' ],
63 privacy: VideoPrivacy.PUBLIC,
64 commentsEnabled: true,
66 name: 'Default root channel',
70 fixture: 'video_short1.webm',
79 const unlistedCheckAttributes = immutableAssign(checkAttributes, {
80 privacy: VideoPrivacy.UNLISTED
83 before(async function () {
86 servers = await flushAndRunMultipleServers(2)
88 // Get the access tokens
89 await setAccessTokensToServers(servers)
92 it('Should remove followers that are often down', async function () {
95 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
97 await waitJobs(servers)
99 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
101 await waitJobs(servers)
103 for (const server of servers) {
104 const res = await getVideosList(server.url)
105 expect(res.body.data).to.be.an('array')
106 expect(res.body.data).to.have.lengthOf(1)
110 killallServers([ servers[1] ])
112 let resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, unlistedVideoAttributes)
113 videos.push(resVideo.body.video)
115 // Remove server 2 follower
116 for (let i = 0; i < 10; i++) {
117 resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
118 videos.push(resVideo.body.video)
121 await waitJobs(servers[0])
123 await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
125 // Add comments to video 2
127 const text = 'thread 1'
128 let resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videos[1].uuid, text)
129 let comment = resComment.body.comment
130 threadIdServer1 = comment.id
132 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, comment.id, 'comment 1-1')
133 comment = resComment.body.comment
135 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, comment.id, 'comment 1-2')
136 commentIdServer1 = resComment.body.comment.id
139 await waitJobs(servers[0])
143 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt')
144 expect(res.body.data).to.be.an('array')
145 expect(res.body.data).to.have.lengthOf(0)
148 it('Should not have pending/processing jobs anymore', async function () {
149 const states: JobState[] = [ 'inactive', 'active' ]
151 for (const state of states) {
152 const res = await getJobsListPaginationAndSort(servers[ 0 ].url, servers[ 0 ].accessToken, state,0, 50, '-createdAt')
153 expect(res.body.data).to.have.length(0)
157 it('Should follow server 1', async function () {
160 await reRunServer(servers[1])
162 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
164 await waitJobs(servers)
166 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt')
167 expect(res.body.data).to.be.an('array')
168 expect(res.body.data).to.have.lengthOf(1)
171 it('Should send a view to server 2, and automatically fetch the video', async function () {
174 await viewVideo(servers[0].url, videos[0].uuid)
176 await waitJobs(servers)
178 const res = await getVideosList(servers[1].url)
179 expect(res.body.data).to.be.an('array')
181 expect(res.body.data).to.have.lengthOf(1)
183 const resVideo = await getVideo(servers[1].url, videos[0].uuid)
184 expect(resVideo.body).not.to.be.undefined
186 await completeVideoCheck(servers[1].url, resVideo.body, unlistedCheckAttributes)
189 it('Should send comments on a video to server 2, and automatically fetch the video', async function () {
192 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, commentIdServer1, 'comment 1-3')
194 await waitJobs(servers)
196 const resVideo = await getVideo(servers[1].url, videos[0].uuid)
197 expect(resVideo.body).not.to.be.undefined
199 await completeVideoCheck(servers[1].url, resVideo.body, unlistedCheckAttributes)
202 let resComment = await getVideoCommentThreads(servers[1].url, videos[1].uuid, 0, 5)
203 expect(resComment.body.data).to.be.an('array')
204 expect(resComment.body.data).to.have.lengthOf(1)
206 threadIdServer2 = resComment.body.data[0].id
208 resComment = await getVideoThreadComments(servers[1].url, videos[1].uuid, threadIdServer2)
210 const tree: VideoCommentThreadTree = resComment.body
211 expect(tree.comment.text).equal('thread 1')
212 expect(tree.children).to.have.lengthOf(1)
214 const firstChild = tree.children[0]
215 expect(firstChild.comment.text).to.equal('comment 1-1')
216 expect(firstChild.children).to.have.lengthOf(1)
218 const childOfFirstChild = firstChild.children[0]
219 expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
220 expect(childOfFirstChild.children).to.have.lengthOf(1)
222 const childOfChildFirstChild = childOfFirstChild.children[0]
223 expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
224 expect(childOfChildFirstChild.children).to.have.lengthOf(0)
226 commentIdServer2 = childOfChildFirstChild.comment.id
230 it('Should correctly reply to the comment', async function () {
233 await addVideoCommentReply(servers[1].url, servers[1].accessToken, videos[1].uuid, commentIdServer2, 'comment 1-4')
235 await waitJobs(servers)
238 const resComment = await getVideoThreadComments(servers[0].url, videos[1].uuid, threadIdServer1)
240 const tree: VideoCommentThreadTree = resComment.body
241 expect(tree.comment.text).equal('thread 1')
242 expect(tree.children).to.have.lengthOf(1)
244 const firstChild = tree.children[0]
245 expect(firstChild.comment.text).to.equal('comment 1-1')
246 expect(firstChild.children).to.have.lengthOf(1)
248 const childOfFirstChild = firstChild.children[0]
249 expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
250 expect(childOfFirstChild.children).to.have.lengthOf(1)
252 const childOfChildFirstChild = childOfFirstChild.children[0]
253 expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
254 expect(childOfChildFirstChild.children).to.have.lengthOf(1)
256 const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0]
257 expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4')
258 expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0)
262 after(async function () {
263 killallServers(servers)