]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
0f91ae62 | 2 | |
0f91ae62 | 3 | import 'mocha' |
2b02c520 | 4 | import * as chai from 'chai' |
0f91ae62 | 5 | import { |
2b02c520 C |
6 | addVideoCommentReply, |
7 | addVideoCommentThread, | |
8 | cleanupTests, | |
9 | completeVideoCheck, | |
10 | createUser, | |
11 | createVideoCaption, | |
12 | dateIsValid, | |
13 | deleteVideoComment, | |
14 | expectAccountFollows, | |
3cd0734f | 15 | flushAndRunMultipleServers, |
9639bd17 | 16 | follow, |
17 | getFollowersListPaginationAndSort, | |
18 | getFollowingListPaginationAndSort, | |
3cd0734f | 19 | getVideoCommentThreads, |
2b02c520 C |
20 | getVideosList, |
21 | getVideoThreadComments, | |
22 | listVideoCaptions, | |
23 | rateVideo, | |
24 | ServerInfo, | |
25 | setAccessTokensToServers, | |
26 | testCaptionFile, | |
27 | unfollow, | |
28 | uploadVideo, | |
29 | userLogin, | |
30 | waitJobs | |
31 | } from '@shared/extra-utils' | |
32 | import { Video, VideoCaption, VideoComment, VideoCommentThreadTree, VideoPrivacy } from '@shared/models' | |
0f91ae62 C |
33 | |
34 | const expect = chai.expect | |
35 | ||
36 | describe('Test follows', function () { | |
37 | let servers: ServerInfo[] = [] | |
0f91ae62 C |
38 | |
39 | before(async function () { | |
e212f887 | 40 | this.timeout(30000) |
0f91ae62 C |
41 | |
42 | servers = await flushAndRunMultipleServers(3) | |
43 | ||
44 | // Get the access tokens | |
45 | await setAccessTokensToServers(servers) | |
46 | }) | |
47 | ||
48 | it('Should not have followers', async function () { | |
49 | for (const server of servers) { | |
97ecddae | 50 | const res = await getFollowersListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' }) |
0f91ae62 C |
51 | const follows = res.body.data |
52 | ||
53 | expect(res.body.total).to.equal(0) | |
54 | expect(follows).to.be.an('array') | |
55 | expect(follows.length).to.equal(0) | |
56 | } | |
57 | }) | |
58 | ||
59 | it('Should not have following', async function () { | |
60 | for (const server of servers) { | |
97ecddae | 61 | const res = await getFollowingListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' }) |
0f91ae62 C |
62 | const follows = res.body.data |
63 | ||
64 | expect(res.body.total).to.equal(0) | |
65 | expect(follows).to.be.an('array') | |
66 | expect(follows.length).to.equal(0) | |
67 | } | |
68 | }) | |
69 | ||
70 | it('Should have server 1 following server 2 and 3', async function () { | |
288178bf | 71 | this.timeout(30000) |
0f91ae62 C |
72 | |
73 | await follow(servers[0].url, [ servers[1].url, servers[2].url ], servers[0].accessToken) | |
74 | ||
3cd0734f | 75 | await waitJobs(servers) |
0f91ae62 C |
76 | }) |
77 | ||
78 | it('Should have 2 followings on server 1', async function () { | |
a1587156 | 79 | let res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 1, sort: 'createdAt' }) |
0f91ae62 C |
80 | let follows = res.body.data |
81 | ||
82 | expect(res.body.total).to.equal(2) | |
83 | expect(follows).to.be.an('array') | |
84 | expect(follows.length).to.equal(1) | |
85 | ||
a1587156 | 86 | res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 1, count: 1, sort: 'createdAt' }) |
0f91ae62 C |
87 | follows = follows.concat(res.body.data) |
88 | ||
7243f84d C |
89 | const server2Follow = follows.find(f => f.following.host === 'localhost:' + servers[1].port) |
90 | const server3Follow = follows.find(f => f.following.host === 'localhost:' + servers[2].port) | |
0f91ae62 C |
91 | |
92 | expect(server2Follow).to.not.be.undefined | |
93 | expect(server3Follow).to.not.be.undefined | |
94 | expect(server2Follow.state).to.equal('accepted') | |
95 | expect(server3Follow.state).to.equal('accepted') | |
0f91ae62 C |
96 | }) |
97 | ||
b8f4167f | 98 | it('Should search/filter followings on server 1', async function () { |
97ecddae C |
99 | const sort = 'createdAt' |
100 | const start = 0 | |
101 | const count = 1 | |
a1587156 | 102 | const url = servers[0].url |
97ecddae | 103 | |
b014b6b9 | 104 | { |
b8f4167f | 105 | const search = ':' + servers[1].port |
b8f4167f | 106 | |
97ecddae C |
107 | { |
108 | const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search }) | |
109 | const follows = res.body.data | |
110 | ||
111 | expect(res.body.total).to.equal(1) | |
112 | expect(follows.length).to.equal(1) | |
a1587156 | 113 | expect(follows[0].following.host).to.equal('localhost:' + servers[1].port) |
97ecddae C |
114 | } |
115 | ||
116 | { | |
117 | const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'accepted' }) | |
118 | expect(res.body.total).to.equal(1) | |
119 | expect(res.body.data).to.have.lengthOf(1) | |
120 | } | |
121 | ||
122 | { | |
123 | const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'accepted', actorType: 'Person' }) | |
124 | expect(res.body.total).to.equal(0) | |
125 | expect(res.body.data).to.have.lengthOf(0) | |
126 | } | |
127 | ||
128 | { | |
129 | const res = await getFollowingListPaginationAndSort({ | |
130 | url, | |
131 | start, | |
132 | count, | |
133 | sort, | |
134 | search, | |
135 | state: 'accepted', | |
136 | actorType: 'Application' | |
137 | }) | |
138 | expect(res.body.total).to.equal(1) | |
139 | expect(res.body.data).to.have.lengthOf(1) | |
140 | } | |
141 | ||
142 | { | |
143 | const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'pending' }) | |
144 | expect(res.body.total).to.equal(0) | |
145 | expect(res.body.data).to.have.lengthOf(0) | |
146 | } | |
b014b6b9 C |
147 | } |
148 | ||
149 | { | |
97ecddae | 150 | const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search: 'bla' }) |
b014b6b9 C |
151 | const follows = res.body.data |
152 | ||
153 | expect(res.body.total).to.equal(0) | |
154 | expect(follows.length).to.equal(0) | |
155 | } | |
156 | }) | |
157 | ||
158 | it('Should have 0 followings on server 2 and 3', async function () { | |
0f91ae62 | 159 | for (const server of [ servers[1], servers[2] ]) { |
97ecddae | 160 | const res = await getFollowingListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' }) |
0f91ae62 C |
161 | const follows = res.body.data |
162 | ||
163 | expect(res.body.total).to.equal(0) | |
164 | expect(follows).to.be.an('array') | |
165 | expect(follows.length).to.equal(0) | |
166 | } | |
167 | }) | |
168 | ||
169 | it('Should have 1 followers on server 2 and 3', async function () { | |
170 | for (const server of [ servers[1], servers[2] ]) { | |
a1587156 | 171 | const res = await getFollowersListPaginationAndSort({ url: server.url, start: 0, count: 1, sort: 'createdAt' }) |
0f91ae62 | 172 | |
a1587156 | 173 | const follows = res.body.data |
0f91ae62 C |
174 | expect(res.body.total).to.equal(1) |
175 | expect(follows).to.be.an('array') | |
176 | expect(follows.length).to.equal(1) | |
7243f84d | 177 | expect(follows[0].follower.host).to.equal('localhost:' + servers[0].port) |
0f91ae62 C |
178 | } |
179 | }) | |
180 | ||
b8f4167f | 181 | it('Should search/filter followers on server 2', async function () { |
a1587156 | 182 | const url = servers[2].url |
97ecddae C |
183 | const start = 0 |
184 | const count = 5 | |
185 | const sort = 'createdAt' | |
186 | ||
b014b6b9 | 187 | { |
b8f4167f | 188 | const search = servers[0].port + '' |
b8f4167f | 189 | |
97ecddae C |
190 | { |
191 | const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search }) | |
192 | const follows = res.body.data | |
193 | ||
194 | expect(res.body.total).to.equal(1) | |
195 | expect(follows.length).to.equal(1) | |
a1587156 | 196 | expect(follows[0].following.host).to.equal('localhost:' + servers[2].port) |
97ecddae C |
197 | } |
198 | ||
199 | { | |
200 | const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'accepted' }) | |
201 | expect(res.body.total).to.equal(1) | |
202 | expect(res.body.data).to.have.lengthOf(1) | |
203 | } | |
204 | ||
205 | { | |
206 | const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'accepted', actorType: 'Person' }) | |
207 | expect(res.body.total).to.equal(0) | |
208 | expect(res.body.data).to.have.lengthOf(0) | |
209 | } | |
210 | ||
211 | { | |
212 | const res = await getFollowersListPaginationAndSort({ | |
213 | url, | |
214 | start, | |
215 | count, | |
216 | sort, | |
217 | search, | |
218 | state: 'accepted', | |
219 | actorType: 'Application' | |
220 | }) | |
221 | expect(res.body.total).to.equal(1) | |
222 | expect(res.body.data).to.have.lengthOf(1) | |
223 | } | |
224 | ||
225 | { | |
226 | const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'pending' }) | |
227 | expect(res.body.total).to.equal(0) | |
228 | expect(res.body.data).to.have.lengthOf(0) | |
229 | } | |
b014b6b9 C |
230 | } |
231 | ||
232 | { | |
97ecddae | 233 | const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search: 'bla' }) |
b014b6b9 C |
234 | const follows = res.body.data |
235 | ||
236 | expect(res.body.total).to.equal(0) | |
237 | expect(follows.length).to.equal(0) | |
238 | } | |
239 | }) | |
240 | ||
0f91ae62 | 241 | it('Should have 0 followers on server 1', async function () { |
a1587156 | 242 | const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' }) |
0f91ae62 C |
243 | const follows = res.body.data |
244 | ||
245 | expect(res.body.total).to.equal(0) | |
246 | expect(follows).to.be.an('array') | |
247 | expect(follows.length).to.equal(0) | |
248 | }) | |
249 | ||
38768a36 | 250 | it('Should have the correct follows counts', async function () { |
7243f84d C |
251 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2) |
252 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) | |
253 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0) | |
32b2b43c C |
254 | |
255 | // Server 2 and 3 does not know server 1 follow another server (there was not a refresh) | |
7243f84d C |
256 | await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) |
257 | await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) | |
32b2b43c | 258 | |
7243f84d C |
259 | await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1) |
260 | await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0) | |
32b2b43c C |
261 | }) |
262 | ||
0f91ae62 C |
263 | it('Should unfollow server 3 on server 1', async function () { |
264 | this.timeout(5000) | |
265 | ||
50d6de9c | 266 | await unfollow(servers[0].url, servers[0].accessToken, servers[2]) |
0f91ae62 | 267 | |
3cd0734f | 268 | await waitJobs(servers) |
0f91ae62 C |
269 | }) |
270 | ||
271 | it('Should not follow server 3 on server 1 anymore', async function () { | |
a1587156 C |
272 | const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' }) |
273 | const follows = res.body.data | |
0f91ae62 C |
274 | |
275 | expect(res.body.total).to.equal(1) | |
276 | expect(follows).to.be.an('array') | |
277 | expect(follows.length).to.equal(1) | |
278 | ||
7243f84d | 279 | expect(follows[0].following.host).to.equal('localhost:' + servers[1].port) |
0f91ae62 C |
280 | }) |
281 | ||
282 | it('Should not have server 1 as follower on server 3 anymore', async function () { | |
a1587156 | 283 | const res = await getFollowersListPaginationAndSort({ url: servers[2].url, start: 0, count: 1, sort: 'createdAt' }) |
0f91ae62 | 284 | |
a1587156 | 285 | const follows = res.body.data |
0f91ae62 C |
286 | expect(res.body.total).to.equal(0) |
287 | expect(follows).to.be.an('array') | |
288 | expect(follows.length).to.equal(0) | |
289 | }) | |
290 | ||
38768a36 | 291 | it('Should have the correct follows counts 2', async function () { |
7243f84d C |
292 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 1) |
293 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) | |
32b2b43c | 294 | |
7243f84d C |
295 | await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) |
296 | await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) | |
32b2b43c | 297 | |
7243f84d C |
298 | await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 0) |
299 | await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 0, 0) | |
32b2b43c C |
300 | }) |
301 | ||
2bb0f9d5 | 302 | it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { |
e0783718 | 303 | this.timeout(60000) |
0f91ae62 C |
304 | |
305 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' }) | |
306 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' }) | |
307 | ||
3cd0734f | 308 | await waitJobs(servers) |
0f91ae62 C |
309 | |
310 | let res = await getVideosList(servers[0].url) | |
311 | expect(res.body.total).to.equal(1) | |
312 | expect(res.body.data[0].name).to.equal('server2') | |
313 | ||
314 | res = await getVideosList(servers[1].url) | |
315 | expect(res.body.total).to.equal(1) | |
316 | expect(res.body.data[0].name).to.equal('server2') | |
317 | ||
318 | res = await getVideosList(servers[2].url) | |
319 | expect(res.body.total).to.equal(1) | |
320 | expect(res.body.data[0].name).to.equal('server3') | |
321 | }) | |
322 | ||
9b39106d | 323 | describe('Should propagate data on a new following', function () { |
b1f5b93e | 324 | let video4: Video |
d8553faa | 325 | |
b1f5b93e | 326 | before(async function () { |
8b381422 | 327 | this.timeout(50000) |
c46edbc2 | 328 | |
b1f5b93e C |
329 | const video4Attributes = { |
330 | name: 'server3-4', | |
331 | category: 2, | |
332 | nsfw: true, | |
333 | licence: 6, | |
334 | tags: [ 'tag1', 'tag2', 'tag3' ] | |
335 | } | |
d8553faa | 336 | |
a1587156 C |
337 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-2' }) |
338 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-3' }) | |
339 | await uploadVideo(servers[2].url, servers[2].accessToken, video4Attributes) | |
340 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-5' }) | |
341 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' }) | |
d8553faa | 342 | |
db799da3 | 343 | { |
b1f5b93e | 344 | const user = { username: 'captain', password: 'password' } |
a1587156 C |
345 | await createUser({ url: servers[2].url, accessToken: servers[2].accessToken, username: user.username, password: user.password }) |
346 | const userAccessToken = await userLogin(servers[2], user) | |
db799da3 | 347 | |
a1587156 | 348 | const resVideos = await getVideosList(servers[2].url) |
b1f5b93e | 349 | video4 = resVideos.body.data.find(v => v.name === 'server3-4') |
db799da3 | 350 | |
b1f5b93e | 351 | { |
a1587156 C |
352 | await rateVideo(servers[2].url, servers[2].accessToken, video4.id, 'like') |
353 | await rateVideo(servers[2].url, userAccessToken, video4.id, 'dislike') | |
b1f5b93e | 354 | } |
db799da3 | 355 | |
b1f5b93e | 356 | { |
c883db6d C |
357 | { |
358 | const text = 'my super first comment' | |
a1587156 | 359 | const res = await addVideoCommentThread(servers[2].url, servers[2].accessToken, video4.id, text) |
c883db6d C |
360 | const threadId = res.body.comment.id |
361 | ||
362 | const text1 = 'my super answer to thread 1' | |
a1587156 | 363 | const childCommentRes = await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, threadId, text1) |
c883db6d C |
364 | const childCommentId = childCommentRes.body.comment.id |
365 | ||
366 | const text2 = 'my super answer to answer of thread 1' | |
a1587156 | 367 | await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, childCommentId, text2) |
c883db6d C |
368 | |
369 | const text3 = 'my second answer to thread 1' | |
a1587156 | 370 | await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, threadId, text3) |
c883db6d C |
371 | } |
372 | ||
373 | { | |
374 | const text = 'will be deleted' | |
a1587156 | 375 | const res = await addVideoCommentThread(servers[2].url, servers[2].accessToken, video4.id, text) |
c883db6d C |
376 | const threadId = res.body.comment.id |
377 | ||
378 | const text1 = 'answer to deleted' | |
a1587156 | 379 | await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, threadId, text1) |
db799da3 | 380 | |
c883db6d | 381 | const text2 = 'will also be deleted' |
a1587156 | 382 | const childCommentRes = await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, threadId, text2) |
c883db6d | 383 | const childCommentId = childCommentRes.body.comment.id |
d8553faa | 384 | |
c883db6d | 385 | const text3 = 'my second answer to deleted' |
a1587156 | 386 | await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, childCommentId, text3) |
c46edbc2 | 387 | |
a1587156 C |
388 | await deleteVideoComment(servers[2].url, servers[2].accessToken, video4.id, threadId) |
389 | await deleteVideoComment(servers[2].url, servers[2].accessToken, video4.id, childCommentId) | |
c883db6d | 390 | } |
b1f5b93e | 391 | } |
40e87e9e C |
392 | |
393 | { | |
394 | await createVideoCaption({ | |
395 | url: servers[2].url, | |
396 | accessToken: servers[2].accessToken, | |
397 | language: 'ar', | |
398 | videoId: video4.id, | |
399 | fixture: 'subtitle-good2.vtt' | |
400 | }) | |
401 | } | |
b1f5b93e | 402 | } |
c46edbc2 | 403 | |
3cd0734f | 404 | await waitJobs(servers) |
b1f5b93e C |
405 | |
406 | // Server 1 follows server 3 | |
a1587156 | 407 | await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken) |
b1f5b93e | 408 | |
3cd0734f | 409 | await waitJobs(servers) |
b1f5b93e C |
410 | }) |
411 | ||
38768a36 | 412 | it('Should have the correct follows counts 3', async function () { |
7243f84d C |
413 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2) |
414 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) | |
415 | await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0) | |
32b2b43c | 416 | |
7243f84d C |
417 | await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) |
418 | await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) | |
32b2b43c | 419 | |
e6122097 | 420 | await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1) |
7243f84d | 421 | await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0) |
32b2b43c C |
422 | }) |
423 | ||
40e87e9e | 424 | it('Should have propagated videos', async function () { |
a1587156 | 425 | const res = await getVideosList(servers[0].url) |
b1f5b93e C |
426 | expect(res.body.total).to.equal(7) |
427 | ||
428 | const video2 = res.body.data.find(v => v.name === 'server3-2') | |
429 | video4 = res.body.data.find(v => v.name === 'server3-4') | |
430 | const video6 = res.body.data.find(v => v.name === 'server3-6') | |
431 | ||
432 | expect(video2).to.not.be.undefined | |
433 | expect(video4).to.not.be.undefined | |
434 | expect(video6).to.not.be.undefined | |
435 | ||
436 | const isLocal = false | |
437 | const checkAttributes = { | |
438 | name: 'server3-4', | |
439 | category: 2, | |
440 | licence: 6, | |
9d3ef9fe | 441 | language: 'zh', |
b1f5b93e C |
442 | nsfw: true, |
443 | description: 'my super description', | |
2422c46b | 444 | support: 'my super support text', |
b64c950a C |
445 | account: { |
446 | name: 'root', | |
7243f84d | 447 | host: 'localhost:' + servers[2].port |
b64c950a | 448 | }, |
b1f5b93e | 449 | isLocal, |
47564bbe | 450 | commentsEnabled: true, |
7f2cfe3a | 451 | downloadEnabled: true, |
b1f5b93e C |
452 | duration: 5, |
453 | tags: [ 'tag1', 'tag2', 'tag3' ], | |
454 | privacy: VideoPrivacy.PUBLIC, | |
455 | likes: 1, | |
456 | dislikes: 1, | |
457 | channel: { | |
f6eebcb3 C |
458 | displayName: 'Main root channel', |
459 | name: 'root_channel', | |
b1f5b93e C |
460 | description: '', |
461 | isLocal | |
462 | }, | |
463 | fixture: 'video_short.webm', | |
464 | files: [ | |
465 | { | |
466 | resolution: 720, | |
467 | size: 218910 | |
468 | } | |
469 | ] | |
470 | } | |
a1587156 | 471 | await completeVideoCheck(servers[0].url, video4, checkAttributes) |
b1f5b93e | 472 | }) |
c46edbc2 | 473 | |
40e87e9e | 474 | it('Should have propagated comments', async function () { |
c883db6d | 475 | const res1 = await getVideoCommentThreads(servers[0].url, video4.id, 0, 5, 'createdAt') |
db799da3 | 476 | |
c883db6d | 477 | expect(res1.body.total).to.equal(2) |
db799da3 | 478 | expect(res1.body.data).to.be.an('array') |
c883db6d C |
479 | expect(res1.body.data).to.have.lengthOf(2) |
480 | ||
481 | { | |
a1587156 | 482 | const comment: VideoComment = res1.body.data[0] |
c883db6d C |
483 | expect(comment.inReplyToCommentId).to.be.null |
484 | expect(comment.text).equal('my super first comment') | |
485 | expect(comment.videoId).to.equal(video4.id) | |
486 | expect(comment.id).to.equal(comment.threadId) | |
487 | expect(comment.account.name).to.equal('root') | |
a1587156 | 488 | expect(comment.account.host).to.equal('localhost:' + servers[2].port) |
c883db6d C |
489 | expect(comment.totalReplies).to.equal(3) |
490 | expect(dateIsValid(comment.createdAt as string)).to.be.true | |
491 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | |
492 | ||
493 | const threadId = comment.threadId | |
494 | ||
a1587156 | 495 | const res2 = await getVideoThreadComments(servers[0].url, video4.id, threadId) |
c883db6d C |
496 | |
497 | const tree: VideoCommentThreadTree = res2.body | |
498 | expect(tree.comment.text).equal('my super first comment') | |
499 | expect(tree.children).to.have.lengthOf(2) | |
500 | ||
a1587156 | 501 | const firstChild = tree.children[0] |
c883db6d C |
502 | expect(firstChild.comment.text).to.equal('my super answer to thread 1') |
503 | expect(firstChild.children).to.have.lengthOf(1) | |
504 | ||
a1587156 | 505 | const childOfFirstChild = firstChild.children[0] |
c883db6d C |
506 | expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') |
507 | expect(childOfFirstChild.children).to.have.lengthOf(0) | |
508 | ||
a1587156 | 509 | const secondChild = tree.children[1] |
c883db6d C |
510 | expect(secondChild.comment.text).to.equal('my second answer to thread 1') |
511 | expect(secondChild.children).to.have.lengthOf(0) | |
512 | } | |
513 | ||
514 | { | |
515 | const deletedComment: VideoComment = res1.body.data[1] | |
516 | expect(deletedComment).to.not.be.undefined | |
517 | expect(deletedComment.isDeleted).to.be.true | |
518 | expect(deletedComment.deletedAt).to.not.be.null | |
519 | expect(deletedComment.text).to.equal('') | |
520 | expect(deletedComment.inReplyToCommentId).to.be.null | |
521 | expect(deletedComment.account).to.be.null | |
522 | expect(deletedComment.totalReplies).to.equal(3) | |
523 | expect(dateIsValid(deletedComment.deletedAt as string)).to.be.true | |
524 | ||
525 | const res2 = await getVideoThreadComments(servers[0].url, video4.id, deletedComment.threadId) | |
526 | ||
527 | const tree: VideoCommentThreadTree = res2.body | |
528 | const [ commentRoot, deletedChildRoot ] = tree.children | |
529 | ||
530 | expect(deletedChildRoot).to.not.be.undefined | |
531 | expect(deletedChildRoot.comment.isDeleted).to.be.true | |
532 | expect(deletedChildRoot.comment.deletedAt).to.not.be.null | |
533 | expect(deletedChildRoot.comment.text).to.equal('') | |
534 | expect(deletedChildRoot.comment.inReplyToCommentId).to.equal(deletedComment.id) | |
535 | expect(deletedChildRoot.comment.account).to.be.null | |
536 | expect(deletedChildRoot.children).to.have.lengthOf(1) | |
537 | ||
538 | const answerToDeletedChild = deletedChildRoot.children[0] | |
539 | expect(answerToDeletedChild.comment).to.not.be.undefined | |
540 | expect(answerToDeletedChild.comment.inReplyToCommentId).to.equal(deletedChildRoot.comment.id) | |
541 | expect(answerToDeletedChild.comment.text).to.equal('my second answer to deleted') | |
542 | expect(answerToDeletedChild.comment.account.name).to.equal('root') | |
543 | ||
544 | expect(commentRoot.comment).to.not.be.undefined | |
545 | expect(commentRoot.comment.inReplyToCommentId).to.equal(deletedComment.id) | |
546 | expect(commentRoot.comment.text).to.equal('answer to deleted') | |
547 | expect(commentRoot.comment.account.name).to.equal('root') | |
548 | } | |
b1f5b93e | 549 | }) |
f05a1c30 | 550 | |
40e87e9e C |
551 | it('Should have propagated captions', async function () { |
552 | const res = await listVideoCaptions(servers[0].url, video4.id) | |
553 | expect(res.body.total).to.equal(1) | |
554 | expect(res.body.data).to.have.lengthOf(1) | |
555 | ||
556 | const caption1: VideoCaption = res.body.data[0] | |
557 | expect(caption1.language.id).to.equal('ar') | |
558 | expect(caption1.language.label).to.equal('Arabic') | |
a35a2279 | 559 | expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/.+-ar.vtt$')) |
40e87e9e C |
560 | await testCaptionFile(servers[0].url, caption1.captionPath, 'Subtitle good 2.') |
561 | }) | |
562 | ||
f05a1c30 C |
563 | it('Should unfollow server 3 on server 1 and does not list server 3 videos', async function () { |
564 | this.timeout(5000) | |
565 | ||
566 | await unfollow(servers[0].url, servers[0].accessToken, servers[2]) | |
567 | ||
3cd0734f | 568 | await waitJobs(servers) |
f05a1c30 | 569 | |
a1587156 | 570 | const res = await getVideosList(servers[0].url) |
f05a1c30 | 571 | expect(res.body.total).to.equal(1) |
f05a1c30 C |
572 | }) |
573 | ||
c46edbc2 C |
574 | }) |
575 | ||
7c3b7976 C |
576 | after(async function () { |
577 | await cleanupTests(servers) | |
0f91ae62 C |
578 | }) |
579 | }) |