1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { Video, VideoPrivacy } from '../../../../shared/models/videos'
6 import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
7 import { completeVideoCheck } from '../../utils'
10 flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo,
12 } from '../../utils/index'
13 import { dateIsValid } from '../../utils/miscs/miscs'
14 import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../../utils/server/follows'
15 import { userLogin } from '../../utils/users/login'
16 import { createUser } from '../../utils/users/users'
18 addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads,
19 getVideoThreadComments
20 } from '../../utils/videos/video-comments'
21 import { rateVideo } from '../../utils/videos/videos'
23 const expect = chai.expect
25 describe('Test follows', function () {
26 let servers: ServerInfo[] = []
28 before(async function () {
31 servers = await flushAndRunMultipleServers(3)
33 // Get the access tokens
34 await setAccessTokensToServers(servers)
37 it('Should not have followers', async function () {
38 for (const server of servers) {
39 const res = await getFollowersListPaginationAndSort(server.url, 0, 5, 'createdAt')
40 const follows = res.body.data
42 expect(res.body.total).to.equal(0)
43 expect(follows).to.be.an('array')
44 expect(follows.length).to.equal(0)
48 it('Should not have following', async function () {
49 for (const server of servers) {
50 const res = await getFollowingListPaginationAndSort(server.url, 0, 5, 'createdAt')
51 const follows = res.body.data
53 expect(res.body.total).to.equal(0)
54 expect(follows).to.be.an('array')
55 expect(follows.length).to.equal(0)
59 it('Should have server 1 following server 2 and 3', async function () {
62 await follow(servers[0].url, [ servers[1].url, servers[2].url ], servers[0].accessToken)
67 it('Should have 2 followings on server 1', async function () {
68 let res = await getFollowingListPaginationAndSort(servers[0].url, 0, 1, 'createdAt')
69 let follows = res.body.data
71 expect(res.body.total).to.equal(2)
72 expect(follows).to.be.an('array')
73 expect(follows.length).to.equal(1)
75 res = await getFollowingListPaginationAndSort(servers[0].url, 1, 1, 'createdAt')
76 follows = follows.concat(res.body.data)
78 const server2Follow = follows.find(f => f.following.host === 'localhost:9002')
79 const server3Follow = follows.find(f => f.following.host === 'localhost:9003')
81 expect(server2Follow).to.not.be.undefined
82 expect(server3Follow).to.not.be.undefined
83 expect(server2Follow.state).to.equal('accepted')
84 expect(server3Follow.state).to.equal('accepted')
87 it('Should have 0 followings on server 1 and 2', async function () {
88 for (const server of [ servers[1], servers[2] ]) {
89 const res = await getFollowingListPaginationAndSort(server.url, 0, 5, 'createdAt')
90 const follows = res.body.data
92 expect(res.body.total).to.equal(0)
93 expect(follows).to.be.an('array')
94 expect(follows.length).to.equal(0)
98 it('Should have 1 followers on server 2 and 3', async function () {
99 for (const server of [ servers[1], servers[2] ]) {
100 let res = await getFollowersListPaginationAndSort(server.url, 0, 1, 'createdAt')
102 let follows = res.body.data
103 expect(res.body.total).to.equal(1)
104 expect(follows).to.be.an('array')
105 expect(follows.length).to.equal(1)
106 expect(follows[0].follower.host).to.equal('localhost:9001')
110 it('Should have 0 followers on server 1', async function () {
111 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
112 const follows = res.body.data
114 expect(res.body.total).to.equal(0)
115 expect(follows).to.be.an('array')
116 expect(follows.length).to.equal(0)
119 it('Should unfollow server 3 on server 1', async function () {
122 await unfollow(servers[0].url, servers[0].accessToken, servers[2])
127 it('Should not follow server 3 on server 1 anymore', async function () {
128 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 2, 'createdAt')
129 let follows = res.body.data
131 expect(res.body.total).to.equal(1)
132 expect(follows).to.be.an('array')
133 expect(follows.length).to.equal(1)
135 expect(follows[0].following.host).to.equal('localhost:9002')
138 it('Should not have server 1 as follower on server 3 anymore', async function () {
139 const res = await getFollowersListPaginationAndSort(servers[2].url, 0, 1, 'createdAt')
141 let follows = res.body.data
142 expect(res.body.total).to.equal(0)
143 expect(follows).to.be.an('array')
144 expect(follows.length).to.equal(0)
147 it('Should upload a video on server 2 ans 3 and propagate only the video of server 2', async function () {
150 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' })
151 await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' })
155 let res = await getVideosList(servers[0].url)
156 expect(res.body.total).to.equal(1)
157 expect(res.body.data[0].name).to.equal('server2')
159 res = await getVideosList(servers[1].url)
160 expect(res.body.total).to.equal(1)
161 expect(res.body.data[0].name).to.equal('server2')
163 res = await getVideosList(servers[2].url)
164 expect(res.body.total).to.equal(1)
165 expect(res.body.data[0].name).to.equal('server3')
168 describe('Should propagate data on a new following', async function () {
171 before(async function () {
174 const video4Attributes = {
179 tags: [ 'tag1', 'tag2', 'tag3' ]
182 await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, { name: 'server3-2' })
183 await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, { name: 'server3-3' })
184 await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, video4Attributes)
185 await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, { name: 'server3-5' })
186 await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, { name: 'server3-6' })
189 const user = { username: 'captain', password: 'password' }
190 await createUser(servers[ 2 ].url, servers[ 2 ].accessToken, user.username, user.password)
191 const userAccessToken = await userLogin(servers[ 2 ], user)
193 const resVideos = await getVideosList(servers[ 2 ].url)
194 video4 = resVideos.body.data.find(v => v.name === 'server3-4')
197 await rateVideo(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, 'like')
198 await rateVideo(servers[ 2 ].url, userAccessToken, video4.id, 'dislike')
202 const text = 'my super first comment'
203 const res = await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, text)
204 const threadId = res.body.comment.id
206 const text1 = 'my super answer to thread 1'
207 const childCommentRes = await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text1)
208 const childCommentId = childCommentRes.body.comment.id
210 const text2 = 'my super answer to answer of thread 1'
211 await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, childCommentId, text2)
213 const text3 = 'my second answer to thread 1'
214 await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text3)
220 // Server 1 follows server 3
221 await follow(servers[ 0 ].url, [ servers[ 2 ].url ], servers[ 0 ].accessToken)
226 it('Should propagate videos', async function () {
227 const res = await getVideosList(servers[ 0 ].url)
228 expect(res.body.total).to.equal(7)
230 const video2 = res.body.data.find(v => v.name === 'server3-2')
231 video4 = res.body.data.find(v => v.name === 'server3-4')
232 const video6 = res.body.data.find(v => v.name === 'server3-6')
234 expect(video2).to.not.be.undefined
235 expect(video4).to.not.be.undefined
236 expect(video6).to.not.be.undefined
238 const isLocal = false
239 const checkAttributes = {
245 description: 'my super description',
246 host: 'localhost:9003',
249 commentsEnabled: true,
251 tags: [ 'tag1', 'tag2', 'tag3' ],
252 privacy: VideoPrivacy.PUBLIC,
256 name: 'Default root channel',
260 fixture: 'video_short.webm',
268 await completeVideoCheck(servers[ 0 ].url, video4, checkAttributes)
271 it('Should propagate comments', async function () {
272 const res1 = await getVideoCommentThreads(servers[0].url, video4.id, 0, 5)
274 expect(res1.body.total).to.equal(1)
275 expect(res1.body.data).to.be.an('array')
276 expect(res1.body.data).to.have.lengthOf(1)
278 const comment: VideoComment = res1.body.data[0]
279 expect(comment.inReplyToCommentId).to.be.null
280 expect(comment.text).equal('my super first comment')
281 expect(comment.videoId).to.equal(video4.id)
282 expect(comment.id).to.equal(comment.threadId)
283 expect(comment.account.name).to.equal('root')
284 expect(comment.account.host).to.equal('localhost:9003')
285 expect(comment.totalReplies).to.equal(3)
286 expect(dateIsValid(comment.createdAt as string)).to.be.true
287 expect(dateIsValid(comment.updatedAt as string)).to.be.true
289 const threadId = comment.threadId
291 const res2 = await getVideoThreadComments(servers[0].url, video4.id, threadId)
293 const tree: VideoCommentThreadTree = res2.body
294 expect(tree.comment.text).equal('my super first comment')
295 expect(tree.children).to.have.lengthOf(2)
297 const firstChild = tree.children[0]
298 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
299 expect(firstChild.children).to.have.lengthOf(1)
301 const childOfFirstChild = firstChild.children[0]
302 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
303 expect(childOfFirstChild.children).to.have.lengthOf(0)
305 const secondChild = tree.children[1]
306 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
307 expect(secondChild.children).to.have.lengthOf(0)
311 after(async function () {
312 killallServers(servers)
314 // Keep the logs if the test failed