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