]>
Commit | Line | Data |
---|---|---|
0f91ae62 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
b1f5b93e | 5 | import { Video, VideoPrivacy } from '../../../../shared/models/videos' |
c5d31dba | 6 | import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' |
7c3b7976 | 7 | import { cleanupTests, completeVideoCheck } from '../../../../shared/extra-utils' |
0f91ae62 | 8 | import { |
3cd0734f C |
9 | flushAndRunMultipleServers, |
10 | getVideosList, | |
3cd0734f C |
11 | ServerInfo, |
12 | setAccessTokensToServers, | |
13 | uploadVideo | |
94565d52 C |
14 | } from '../../../../shared/extra-utils/index' |
15 | import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs' | |
9639bd17 | 16 | import { |
17 | follow, | |
18 | getFollowersListPaginationAndSort, | |
19 | getFollowingListPaginationAndSort, | |
20 | unfollow | |
94565d52 C |
21 | } from '../../../../shared/extra-utils/server/follows' |
22 | import { expectAccountFollows } from '../../../../shared/extra-utils/users/accounts' | |
23 | import { userLogin } from '../../../../shared/extra-utils/users/login' | |
24 | import { createUser } from '../../../../shared/extra-utils/users/users' | |
c5d31dba | 25 | import { |
3cd0734f C |
26 | addVideoCommentReply, |
27 | addVideoCommentThread, | |
28 | getVideoCommentThreads, | |
c5d31dba | 29 | getVideoThreadComments |
94565d52 C |
30 | } from '../../../../shared/extra-utils/videos/video-comments' |
31 | import { rateVideo } from '../../../../shared/extra-utils/videos/videos' | |
32 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
33 | import { createVideoCaption, listVideoCaptions, testCaptionFile } from '../../../../shared/extra-utils/videos/video-captions' | |
59c76ffa | 34 | import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model' |
0f91ae62 C |
35 | |
36 | const expect = chai.expect | |
37 | ||
38 | describe('Test follows', function () { | |
39 | let servers: ServerInfo[] = [] | |
0f91ae62 C |
40 | |
41 | before(async function () { | |
e212f887 | 42 | this.timeout(30000) |
0f91ae62 C |
43 | |
44 | servers = await flushAndRunMultipleServers(3) | |
45 | ||
46 | // Get the access tokens | |
47 | await setAccessTokensToServers(servers) | |
48 | }) | |
49 | ||
50 | it('Should not have followers', async function () { | |
51 | for (const server of servers) { | |
52 | const res = await getFollowersListPaginationAndSort(server.url, 0, 5, 'createdAt') | |
53 | const follows = res.body.data | |
54 | ||
55 | expect(res.body.total).to.equal(0) | |
56 | expect(follows).to.be.an('array') | |
57 | expect(follows.length).to.equal(0) | |
58 | } | |
59 | }) | |
60 | ||
61 | it('Should not have following', async function () { | |
62 | for (const server of servers) { | |
63 | const res = await getFollowingListPaginationAndSort(server.url, 0, 5, 'createdAt') | |
64 | const follows = res.body.data | |
65 | ||
66 | expect(res.body.total).to.equal(0) | |
67 | expect(follows).to.be.an('array') | |
68 | expect(follows.length).to.equal(0) | |
69 | } | |
70 | }) | |
71 | ||
72 | it('Should have server 1 following server 2 and 3', async function () { | |
288178bf | 73 | this.timeout(30000) |
0f91ae62 C |
74 | |
75 | await follow(servers[0].url, [ servers[1].url, servers[2].url ], servers[0].accessToken) | |
76 | ||
3cd0734f | 77 | await waitJobs(servers) |
0f91ae62 C |
78 | }) |
79 | ||
80 | it('Should have 2 followings on server 1', async function () { | |
81 | let res = await getFollowingListPaginationAndSort(servers[0].url, 0, 1, 'createdAt') | |
82 | let follows = res.body.data | |
83 | ||
84 | expect(res.body.total).to.equal(2) | |
85 | expect(follows).to.be.an('array') | |
86 | expect(follows.length).to.equal(1) | |
87 | ||
88 | res = await getFollowingListPaginationAndSort(servers[0].url, 1, 1, 'createdAt') | |
89 | follows = follows.concat(res.body.data) | |
90 | ||
7243f84d C |
91 | const server2Follow = follows.find(f => f.following.host === 'localhost:' + servers[1].port) |
92 | const server3Follow = follows.find(f => f.following.host === 'localhost:' + servers[2].port) | |
0f91ae62 C |
93 | |
94 | expect(server2Follow).to.not.be.undefined | |
95 | expect(server3Follow).to.not.be.undefined | |
96 | expect(server2Follow.state).to.equal('accepted') | |
97 | expect(server3Follow.state).to.equal('accepted') | |
0f91ae62 C |
98 | }) |
99 | ||
b014b6b9 C |
100 | it('Should search followings on server 1', async function () { |
101 | { | |
7243f84d | 102 | const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt', ':' + servers[1].port) |
b014b6b9 C |
103 | const follows = res.body.data |
104 | ||
105 | expect(res.body.total).to.equal(1) | |
106 | expect(follows.length).to.equal(1) | |
7243f84d | 107 | expect(follows[ 0 ].following.host).to.equal('localhost:' + servers[1].port) |
b014b6b9 C |
108 | } |
109 | ||
110 | { | |
111 | const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt', 'bla') | |
112 | const follows = res.body.data | |
113 | ||
114 | expect(res.body.total).to.equal(0) | |
115 | expect(follows.length).to.equal(0) | |
116 | } | |
117 | }) | |
118 | ||
119 | it('Should have 0 followings on server 2 and 3', async function () { | |
0f91ae62 C |
120 | for (const server of [ servers[1], servers[2] ]) { |
121 | const res = await getFollowingListPaginationAndSort(server.url, 0, 5, 'createdAt') | |
122 | const follows = res.body.data | |
123 | ||
124 | expect(res.body.total).to.equal(0) | |
125 | expect(follows).to.be.an('array') | |
126 | expect(follows.length).to.equal(0) | |
127 | } | |
128 | }) | |
129 | ||
130 | it('Should have 1 followers on server 2 and 3', async function () { | |
131 | for (const server of [ servers[1], servers[2] ]) { | |
132 | let res = await getFollowersListPaginationAndSort(server.url, 0, 1, 'createdAt') | |
133 | ||
134 | let follows = res.body.data | |
135 | expect(res.body.total).to.equal(1) | |
136 | expect(follows).to.be.an('array') | |
137 | expect(follows.length).to.equal(1) | |
7243f84d | 138 | expect(follows[0].follower.host).to.equal('localhost:' + servers[0].port) |
0f91ae62 C |
139 | } |
140 | }) | |
141 | ||
b014b6b9 C |
142 | it('Should search followers on server 2', async function () { |
143 | { | |
48f07b4a | 144 | const res = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt', servers[0].port + '') |
b014b6b9 C |
145 | const follows = res.body.data |
146 | ||
147 | expect(res.body.total).to.equal(1) | |
148 | expect(follows.length).to.equal(1) | |
7243f84d | 149 | expect(follows[ 0 ].following.host).to.equal('localhost:' + servers[2].port) |
b014b6b9 C |
150 | } |
151 | ||
152 | { | |
153 | const res = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt', 'bla') | |
154 | const follows = res.body.data | |
155 | ||
156 | expect(res.body.total).to.equal(0) | |
157 | expect(follows.length).to.equal(0) | |
158 | } | |
159 | }) | |
160 | ||
0f91ae62 C |
161 | it('Should have 0 followers on server 1', async function () { |
162 | const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 5, 'createdAt') | |
163 | const follows = res.body.data | |
164 | ||
165 | expect(res.body.total).to.equal(0) | |
166 | expect(follows).to.be.an('array') | |
167 | expect(follows.length).to.equal(0) | |
168 | }) | |
169 | ||
38768a36 | 170 | it('Should have the correct follows counts', async function () { |
7243f84d C |
171 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2) |
172 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) | |
173 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0) | |
32b2b43c C |
174 | |
175 | // Server 2 and 3 does not know server 1 follow another server (there was not a refresh) | |
7243f84d C |
176 | await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) |
177 | await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) | |
32b2b43c | 178 | |
7243f84d C |
179 | await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1) |
180 | await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0) | |
32b2b43c C |
181 | }) |
182 | ||
0f91ae62 C |
183 | it('Should unfollow server 3 on server 1', async function () { |
184 | this.timeout(5000) | |
185 | ||
50d6de9c | 186 | await unfollow(servers[0].url, servers[0].accessToken, servers[2]) |
0f91ae62 | 187 | |
3cd0734f | 188 | await waitJobs(servers) |
0f91ae62 C |
189 | }) |
190 | ||
191 | it('Should not follow server 3 on server 1 anymore', async function () { | |
192 | const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 2, 'createdAt') | |
193 | let follows = res.body.data | |
194 | ||
195 | expect(res.body.total).to.equal(1) | |
196 | expect(follows).to.be.an('array') | |
197 | expect(follows.length).to.equal(1) | |
198 | ||
7243f84d | 199 | expect(follows[0].following.host).to.equal('localhost:' + servers[1].port) |
0f91ae62 C |
200 | }) |
201 | ||
202 | it('Should not have server 1 as follower on server 3 anymore', async function () { | |
203 | const res = await getFollowersListPaginationAndSort(servers[2].url, 0, 1, 'createdAt') | |
204 | ||
205 | let follows = res.body.data | |
206 | expect(res.body.total).to.equal(0) | |
207 | expect(follows).to.be.an('array') | |
208 | expect(follows.length).to.equal(0) | |
209 | }) | |
210 | ||
38768a36 | 211 | it('Should have the correct follows counts 2', async function () { |
7243f84d C |
212 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 1) |
213 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) | |
32b2b43c | 214 | |
7243f84d C |
215 | await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) |
216 | await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) | |
32b2b43c | 217 | |
7243f84d C |
218 | await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 0) |
219 | await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 0, 0) | |
32b2b43c C |
220 | }) |
221 | ||
2bb0f9d5 | 222 | it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { |
cf7a61b5 | 223 | this.timeout(35000) |
0f91ae62 C |
224 | |
225 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' }) | |
226 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' }) | |
227 | ||
3cd0734f | 228 | await waitJobs(servers) |
0f91ae62 C |
229 | |
230 | let res = await getVideosList(servers[0].url) | |
231 | expect(res.body.total).to.equal(1) | |
232 | expect(res.body.data[0].name).to.equal('server2') | |
233 | ||
234 | res = await getVideosList(servers[1].url) | |
235 | expect(res.body.total).to.equal(1) | |
236 | expect(res.body.data[0].name).to.equal('server2') | |
237 | ||
238 | res = await getVideosList(servers[2].url) | |
239 | expect(res.body.total).to.equal(1) | |
240 | expect(res.body.data[0].name).to.equal('server3') | |
241 | }) | |
242 | ||
9b39106d | 243 | describe('Should propagate data on a new following', function () { |
b1f5b93e | 244 | let video4: Video |
d8553faa | 245 | |
b1f5b93e C |
246 | before(async function () { |
247 | this.timeout(20000) | |
c46edbc2 | 248 | |
b1f5b93e C |
249 | const video4Attributes = { |
250 | name: 'server3-4', | |
251 | category: 2, | |
252 | nsfw: true, | |
253 | licence: 6, | |
254 | tags: [ 'tag1', 'tag2', 'tag3' ] | |
255 | } | |
d8553faa | 256 | |
b1f5b93e C |
257 | await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, { name: 'server3-2' }) |
258 | await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, { name: 'server3-3' }) | |
259 | await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, video4Attributes) | |
260 | await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, { name: 'server3-5' }) | |
261 | await uploadVideo(servers[ 2 ].url, servers[ 2 ].accessToken, { name: 'server3-6' }) | |
d8553faa | 262 | |
db799da3 | 263 | { |
b1f5b93e | 264 | const user = { username: 'captain', password: 'password' } |
1eddc9a7 | 265 | await createUser({ url: servers[ 2 ].url, accessToken: servers[ 2 ].accessToken, username: user.username, password: user.password }) |
b1f5b93e | 266 | const userAccessToken = await userLogin(servers[ 2 ], user) |
db799da3 | 267 | |
b1f5b93e C |
268 | const resVideos = await getVideosList(servers[ 2 ].url) |
269 | video4 = resVideos.body.data.find(v => v.name === 'server3-4') | |
db799da3 | 270 | |
b1f5b93e C |
271 | { |
272 | await rateVideo(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, 'like') | |
273 | await rateVideo(servers[ 2 ].url, userAccessToken, video4.id, 'dislike') | |
274 | } | |
db799da3 | 275 | |
b1f5b93e C |
276 | { |
277 | const text = 'my super first comment' | |
278 | const res = await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, text) | |
279 | const threadId = res.body.comment.id | |
db799da3 | 280 | |
b1f5b93e C |
281 | const text1 = 'my super answer to thread 1' |
282 | const childCommentRes = await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text1) | |
283 | const childCommentId = childCommentRes.body.comment.id | |
d8553faa | 284 | |
b1f5b93e C |
285 | const text2 = 'my super answer to answer of thread 1' |
286 | await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, childCommentId, text2) | |
c46edbc2 | 287 | |
b1f5b93e C |
288 | const text3 = 'my second answer to thread 1' |
289 | await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text3) | |
290 | } | |
40e87e9e C |
291 | |
292 | { | |
293 | await createVideoCaption({ | |
294 | url: servers[2].url, | |
295 | accessToken: servers[2].accessToken, | |
296 | language: 'ar', | |
297 | videoId: video4.id, | |
298 | fixture: 'subtitle-good2.vtt' | |
299 | }) | |
300 | } | |
b1f5b93e | 301 | } |
c46edbc2 | 302 | |
3cd0734f | 303 | await waitJobs(servers) |
b1f5b93e C |
304 | |
305 | // Server 1 follows server 3 | |
306 | await follow(servers[ 0 ].url, [ servers[ 2 ].url ], servers[ 0 ].accessToken) | |
307 | ||
3cd0734f | 308 | await waitJobs(servers) |
b1f5b93e C |
309 | }) |
310 | ||
38768a36 | 311 | it('Should have the correct follows counts 3', async function () { |
7243f84d C |
312 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2) |
313 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) | |
314 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0) | |
32b2b43c | 315 | |
7243f84d C |
316 | await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) |
317 | await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) | |
32b2b43c | 318 | |
7243f84d C |
319 | await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 2) |
320 | await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0) | |
32b2b43c C |
321 | }) |
322 | ||
40e87e9e | 323 | it('Should have propagated videos', async function () { |
b1f5b93e C |
324 | const res = await getVideosList(servers[ 0 ].url) |
325 | expect(res.body.total).to.equal(7) | |
326 | ||
327 | const video2 = res.body.data.find(v => v.name === 'server3-2') | |
328 | video4 = res.body.data.find(v => v.name === 'server3-4') | |
329 | const video6 = res.body.data.find(v => v.name === 'server3-6') | |
330 | ||
331 | expect(video2).to.not.be.undefined | |
332 | expect(video4).to.not.be.undefined | |
333 | expect(video6).to.not.be.undefined | |
334 | ||
335 | const isLocal = false | |
336 | const checkAttributes = { | |
337 | name: 'server3-4', | |
338 | category: 2, | |
339 | licence: 6, | |
9d3ef9fe | 340 | language: 'zh', |
b1f5b93e C |
341 | nsfw: true, |
342 | description: 'my super description', | |
2422c46b | 343 | support: 'my super support text', |
b64c950a C |
344 | account: { |
345 | name: 'root', | |
7243f84d | 346 | host: 'localhost:' + servers[2].port |
b64c950a | 347 | }, |
b1f5b93e | 348 | isLocal, |
47564bbe | 349 | commentsEnabled: true, |
7f2cfe3a | 350 | downloadEnabled: true, |
b1f5b93e C |
351 | duration: 5, |
352 | tags: [ 'tag1', 'tag2', 'tag3' ], | |
353 | privacy: VideoPrivacy.PUBLIC, | |
354 | likes: 1, | |
355 | dislikes: 1, | |
356 | channel: { | |
f6eebcb3 C |
357 | displayName: 'Main root channel', |
358 | name: 'root_channel', | |
b1f5b93e C |
359 | description: '', |
360 | isLocal | |
361 | }, | |
362 | fixture: 'video_short.webm', | |
363 | files: [ | |
364 | { | |
365 | resolution: 720, | |
366 | size: 218910 | |
367 | } | |
368 | ] | |
369 | } | |
370 | await completeVideoCheck(servers[ 0 ].url, video4, checkAttributes) | |
371 | }) | |
c46edbc2 | 372 | |
40e87e9e | 373 | it('Should have propagated comments', async function () { |
db799da3 C |
374 | const res1 = await getVideoCommentThreads(servers[0].url, video4.id, 0, 5) |
375 | ||
376 | expect(res1.body.total).to.equal(1) | |
377 | expect(res1.body.data).to.be.an('array') | |
378 | expect(res1.body.data).to.have.lengthOf(1) | |
379 | ||
380 | const comment: VideoComment = res1.body.data[0] | |
381 | expect(comment.inReplyToCommentId).to.be.null | |
382 | expect(comment.text).equal('my super first comment') | |
383 | expect(comment.videoId).to.equal(video4.id) | |
384 | expect(comment.id).to.equal(comment.threadId) | |
385 | expect(comment.account.name).to.equal('root') | |
7243f84d | 386 | expect(comment.account.host).to.equal('localhost:' + servers[2].port) |
db799da3 C |
387 | expect(comment.totalReplies).to.equal(3) |
388 | expect(dateIsValid(comment.createdAt as string)).to.be.true | |
389 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | |
390 | ||
391 | const threadId = comment.threadId | |
392 | ||
393 | const res2 = await getVideoThreadComments(servers[0].url, video4.id, threadId) | |
394 | ||
395 | const tree: VideoCommentThreadTree = res2.body | |
396 | expect(tree.comment.text).equal('my super first comment') | |
397 | expect(tree.children).to.have.lengthOf(2) | |
398 | ||
399 | const firstChild = tree.children[0] | |
400 | expect(firstChild.comment.text).to.equal('my super answer to thread 1') | |
401 | expect(firstChild.children).to.have.lengthOf(1) | |
402 | ||
403 | const childOfFirstChild = firstChild.children[0] | |
404 | expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') | |
405 | expect(childOfFirstChild.children).to.have.lengthOf(0) | |
406 | ||
407 | const secondChild = tree.children[1] | |
408 | expect(secondChild.comment.text).to.equal('my second answer to thread 1') | |
409 | expect(secondChild.children).to.have.lengthOf(0) | |
b1f5b93e | 410 | }) |
f05a1c30 | 411 | |
40e87e9e C |
412 | it('Should have propagated captions', async function () { |
413 | const res = await listVideoCaptions(servers[0].url, video4.id) | |
414 | expect(res.body.total).to.equal(1) | |
415 | expect(res.body.data).to.have.lengthOf(1) | |
416 | ||
417 | const caption1: VideoCaption = res.body.data[0] | |
418 | expect(caption1.language.id).to.equal('ar') | |
419 | expect(caption1.language.label).to.equal('Arabic') | |
420 | expect(caption1.captionPath).to.equal('/static/video-captions/' + video4.uuid + '-ar.vtt') | |
421 | await testCaptionFile(servers[0].url, caption1.captionPath, 'Subtitle good 2.') | |
422 | }) | |
423 | ||
f05a1c30 C |
424 | it('Should unfollow server 3 on server 1 and does not list server 3 videos', async function () { |
425 | this.timeout(5000) | |
426 | ||
427 | await unfollow(servers[0].url, servers[0].accessToken, servers[2]) | |
428 | ||
3cd0734f | 429 | await waitJobs(servers) |
f05a1c30 C |
430 | |
431 | let res = await getVideosList(servers[ 0 ].url) | |
432 | expect(res.body.total).to.equal(1) | |
f05a1c30 C |
433 | }) |
434 | ||
c46edbc2 C |
435 | }) |
436 | ||
7c3b7976 C |
437 | after(async function () { |
438 | await cleanupTests(servers) | |
0f91ae62 C |
439 | }) |
440 | }) |