]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { VideoPrivacy } from '@shared/models' | |
6 | import { | |
7 | cleanupTests, | |
8 | createMultipleServers, | |
9 | doubleFollow, | |
10 | PeerTubeServer, | |
11 | setAccessTokensToServers, | |
12 | setDefaultAccountAvatar, | |
13 | setDefaultChannelAvatar, | |
14 | SubscriptionsCommand, | |
15 | waitJobs | |
16 | } from '@shared/server-commands' | |
17 | ||
18 | const expect = chai.expect | |
19 | ||
20 | describe('Test users subscriptions', function () { | |
21 | let servers: PeerTubeServer[] = [] | |
22 | const users: { accessToken: string }[] = [] | |
23 | let video3UUID: string | |
24 | ||
25 | let command: SubscriptionsCommand | |
26 | ||
27 | before(async function () { | |
28 | this.timeout(240000) | |
29 | ||
30 | servers = await createMultipleServers(3) | |
31 | ||
32 | // Get the access tokens | |
33 | await setAccessTokensToServers(servers) | |
34 | await setDefaultChannelAvatar(servers) | |
35 | await setDefaultAccountAvatar(servers) | |
36 | ||
37 | // Server 1 and server 2 follow each other | |
38 | await doubleFollow(servers[0], servers[1]) | |
39 | ||
40 | for (const server of servers) { | |
41 | const user = { username: 'user' + server.serverNumber, password: 'password' } | |
42 | await server.users.create({ username: user.username, password: user.password }) | |
43 | ||
44 | const accessToken = await server.login.getAccessToken(user) | |
45 | users.push({ accessToken }) | |
46 | ||
47 | const videoName1 = 'video 1-' + server.serverNumber | |
48 | await server.videos.upload({ token: accessToken, attributes: { name: videoName1 } }) | |
49 | ||
50 | const videoName2 = 'video 2-' + server.serverNumber | |
51 | await server.videos.upload({ token: accessToken, attributes: { name: videoName2 } }) | |
52 | } | |
53 | ||
54 | await waitJobs(servers) | |
55 | ||
56 | command = servers[0].subscriptions | |
57 | }) | |
58 | ||
59 | it('Should display videos of server 2 on server 1', async function () { | |
60 | const { total } = await servers[0].videos.list() | |
61 | ||
62 | expect(total).to.equal(4) | |
63 | }) | |
64 | ||
65 | it('User of server 1 should follow user of server 3 and root of server 1', async function () { | |
66 | this.timeout(60000) | |
67 | ||
68 | await command.add({ token: users[0].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port }) | |
69 | await command.add({ token: users[0].accessToken, targetUri: 'root_channel@localhost:' + servers[0].port }) | |
70 | ||
71 | await waitJobs(servers) | |
72 | ||
73 | const attributes = { name: 'video server 3 added after follow' } | |
74 | const { uuid } = await servers[2].videos.upload({ token: users[2].accessToken, attributes }) | |
75 | video3UUID = uuid | |
76 | ||
77 | await waitJobs(servers) | |
78 | }) | |
79 | ||
80 | it('Should not display videos of server 3 on server 1', async function () { | |
81 | const { total, data } = await servers[0].videos.list() | |
82 | expect(total).to.equal(4) | |
83 | ||
84 | for (const video of data) { | |
85 | expect(video.name).to.not.contain('1-3') | |
86 | expect(video.name).to.not.contain('2-3') | |
87 | expect(video.name).to.not.contain('video server 3 added after follow') | |
88 | } | |
89 | }) | |
90 | ||
91 | it('Should list subscriptions', async function () { | |
92 | { | |
93 | const body = await command.list() | |
94 | expect(body.total).to.equal(0) | |
95 | expect(body.data).to.be.an('array') | |
96 | expect(body.data).to.have.lengthOf(0) | |
97 | } | |
98 | ||
99 | { | |
100 | const body = await command.list({ token: users[0].accessToken, sort: 'createdAt' }) | |
101 | expect(body.total).to.equal(2) | |
102 | ||
103 | const subscriptions = body.data | |
104 | expect(subscriptions).to.be.an('array') | |
105 | expect(subscriptions).to.have.lengthOf(2) | |
106 | ||
107 | expect(subscriptions[0].name).to.equal('user3_channel') | |
108 | expect(subscriptions[1].name).to.equal('root_channel') | |
109 | } | |
110 | }) | |
111 | ||
112 | it('Should get subscription', async function () { | |
113 | { | |
114 | const videoChannel = await command.get({ token: users[0].accessToken, uri: 'user3_channel@localhost:' + servers[2].port }) | |
115 | ||
116 | expect(videoChannel.name).to.equal('user3_channel') | |
117 | expect(videoChannel.host).to.equal('localhost:' + servers[2].port) | |
118 | expect(videoChannel.displayName).to.equal('Main user3 channel') | |
119 | expect(videoChannel.followingCount).to.equal(0) | |
120 | expect(videoChannel.followersCount).to.equal(1) | |
121 | } | |
122 | ||
123 | { | |
124 | const videoChannel = await command.get({ token: users[0].accessToken, uri: 'root_channel@localhost:' + servers[0].port }) | |
125 | ||
126 | expect(videoChannel.name).to.equal('root_channel') | |
127 | expect(videoChannel.host).to.equal('localhost:' + servers[0].port) | |
128 | expect(videoChannel.displayName).to.equal('Main root channel') | |
129 | expect(videoChannel.followingCount).to.equal(0) | |
130 | expect(videoChannel.followersCount).to.equal(1) | |
131 | } | |
132 | }) | |
133 | ||
134 | it('Should return the existing subscriptions', async function () { | |
135 | const uris = [ | |
136 | 'user3_channel@localhost:' + servers[2].port, | |
137 | 'root2_channel@localhost:' + servers[0].port, | |
138 | 'root_channel@localhost:' + servers[0].port, | |
139 | 'user3_channel@localhost:' + servers[0].port | |
140 | ] | |
141 | ||
142 | const body = await command.exist({ token: users[0].accessToken, uris }) | |
143 | ||
144 | expect(body['user3_channel@localhost:' + servers[2].port]).to.be.true | |
145 | expect(body['root2_channel@localhost:' + servers[0].port]).to.be.false | |
146 | expect(body['root_channel@localhost:' + servers[0].port]).to.be.true | |
147 | expect(body['user3_channel@localhost:' + servers[0].port]).to.be.false | |
148 | }) | |
149 | ||
150 | it('Should search among subscriptions', async function () { | |
151 | { | |
152 | const body = await command.list({ token: users[0].accessToken, sort: '-createdAt', search: 'user3_channel' }) | |
153 | expect(body.total).to.equal(1) | |
154 | expect(body.data).to.have.lengthOf(1) | |
155 | } | |
156 | ||
157 | { | |
158 | const body = await command.list({ token: users[0].accessToken, sort: '-createdAt', search: 'toto' }) | |
159 | expect(body.total).to.equal(0) | |
160 | expect(body.data).to.have.lengthOf(0) | |
161 | } | |
162 | }) | |
163 | ||
164 | it('Should list subscription videos', async function () { | |
165 | { | |
166 | const body = await command.listVideos() | |
167 | expect(body.total).to.equal(0) | |
168 | expect(body.data).to.be.an('array') | |
169 | expect(body.data).to.have.lengthOf(0) | |
170 | } | |
171 | ||
172 | { | |
173 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) | |
174 | expect(body.total).to.equal(3) | |
175 | ||
176 | const videos = body.data | |
177 | expect(videos).to.be.an('array') | |
178 | expect(videos).to.have.lengthOf(3) | |
179 | ||
180 | expect(videos[0].name).to.equal('video 1-3') | |
181 | expect(videos[1].name).to.equal('video 2-3') | |
182 | expect(videos[2].name).to.equal('video server 3 added after follow') | |
183 | } | |
184 | }) | |
185 | ||
186 | it('Should upload a video by root on server 1 and see it in the subscription videos', async function () { | |
187 | this.timeout(60000) | |
188 | ||
189 | const videoName = 'video server 1 added after follow' | |
190 | await servers[0].videos.upload({ attributes: { name: videoName } }) | |
191 | ||
192 | await waitJobs(servers) | |
193 | ||
194 | { | |
195 | const body = await command.listVideos() | |
196 | expect(body.total).to.equal(0) | |
197 | expect(body.data).to.be.an('array') | |
198 | expect(body.data).to.have.lengthOf(0) | |
199 | } | |
200 | ||
201 | { | |
202 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) | |
203 | expect(body.total).to.equal(4) | |
204 | ||
205 | const videos = body.data | |
206 | expect(videos).to.be.an('array') | |
207 | expect(videos).to.have.lengthOf(4) | |
208 | ||
209 | expect(videos[0].name).to.equal('video 1-3') | |
210 | expect(videos[1].name).to.equal('video 2-3') | |
211 | expect(videos[2].name).to.equal('video server 3 added after follow') | |
212 | expect(videos[3].name).to.equal('video server 1 added after follow') | |
213 | } | |
214 | ||
215 | { | |
216 | const { data, total } = await servers[0].videos.list() | |
217 | expect(total).to.equal(5) | |
218 | ||
219 | for (const video of data) { | |
220 | expect(video.name).to.not.contain('1-3') | |
221 | expect(video.name).to.not.contain('2-3') | |
222 | expect(video.name).to.not.contain('video server 3 added after follow') | |
223 | } | |
224 | } | |
225 | }) | |
226 | ||
227 | it('Should have server 1 follow server 3 and display server 3 videos', async function () { | |
228 | this.timeout(60000) | |
229 | ||
230 | await servers[0].follows.follow({ hosts: [ servers[2].url ] }) | |
231 | ||
232 | await waitJobs(servers) | |
233 | ||
234 | const { data, total } = await servers[0].videos.list() | |
235 | expect(total).to.equal(8) | |
236 | ||
237 | const names = [ '1-3', '2-3', 'video server 3 added after follow' ] | |
238 | for (const name of names) { | |
239 | const video = data.find(v => v.name.includes(name)) | |
240 | expect(video).to.not.be.undefined | |
241 | } | |
242 | }) | |
243 | ||
244 | it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () { | |
245 | this.timeout(60000) | |
246 | ||
247 | await servers[0].follows.unfollow({ target: servers[2] }) | |
248 | ||
249 | await waitJobs(servers) | |
250 | ||
251 | const { total, data } = await servers[0].videos.list() | |
252 | expect(total).to.equal(5) | |
253 | ||
254 | for (const video of data) { | |
255 | expect(video.name).to.not.contain('1-3') | |
256 | expect(video.name).to.not.contain('2-3') | |
257 | expect(video.name).to.not.contain('video server 3 added after follow') | |
258 | } | |
259 | }) | |
260 | ||
261 | it('Should still list subscription videos', async function () { | |
262 | { | |
263 | const body = await command.listVideos() | |
264 | expect(body.total).to.equal(0) | |
265 | expect(body.data).to.be.an('array') | |
266 | expect(body.data).to.have.lengthOf(0) | |
267 | } | |
268 | ||
269 | { | |
270 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) | |
271 | expect(body.total).to.equal(4) | |
272 | ||
273 | const videos = body.data | |
274 | expect(videos).to.be.an('array') | |
275 | expect(videos).to.have.lengthOf(4) | |
276 | ||
277 | expect(videos[0].name).to.equal('video 1-3') | |
278 | expect(videos[1].name).to.equal('video 2-3') | |
279 | expect(videos[2].name).to.equal('video server 3 added after follow') | |
280 | expect(videos[3].name).to.equal('video server 1 added after follow') | |
281 | } | |
282 | }) | |
283 | ||
284 | it('Should update a video of server 3 and see the updated video on server 1', async function () { | |
285 | this.timeout(30000) | |
286 | ||
287 | await servers[2].videos.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } }) | |
288 | ||
289 | await waitJobs(servers) | |
290 | ||
291 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) | |
292 | expect(body.data[2].name).to.equal('video server 3 added after follow updated') | |
293 | }) | |
294 | ||
295 | it('Should remove user of server 3 subscription', async function () { | |
296 | this.timeout(30000) | |
297 | ||
298 | await command.remove({ token: users[0].accessToken, uri: 'user3_channel@localhost:' + servers[2].port }) | |
299 | ||
300 | await waitJobs(servers) | |
301 | }) | |
302 | ||
303 | it('Should not display its videos anymore', async function () { | |
304 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) | |
305 | expect(body.total).to.equal(1) | |
306 | ||
307 | const videos = body.data | |
308 | expect(videos).to.be.an('array') | |
309 | expect(videos).to.have.lengthOf(1) | |
310 | ||
311 | expect(videos[0].name).to.equal('video server 1 added after follow') | |
312 | }) | |
313 | ||
314 | it('Should remove the root subscription and not display the videos anymore', async function () { | |
315 | this.timeout(30000) | |
316 | ||
317 | await command.remove({ token: users[0].accessToken, uri: 'root_channel@localhost:' + servers[0].port }) | |
318 | ||
319 | await waitJobs(servers) | |
320 | ||
321 | { | |
322 | const body = await command.list({ token: users[0].accessToken, sort: 'createdAt' }) | |
323 | expect(body.total).to.equal(0) | |
324 | ||
325 | const videos = body.data | |
326 | expect(videos).to.be.an('array') | |
327 | expect(videos).to.have.lengthOf(0) | |
328 | } | |
329 | }) | |
330 | ||
331 | it('Should correctly display public videos on server 1', async function () { | |
332 | const { total, data } = await servers[0].videos.list() | |
333 | expect(total).to.equal(5) | |
334 | ||
335 | for (const video of data) { | |
336 | expect(video.name).to.not.contain('1-3') | |
337 | expect(video.name).to.not.contain('2-3') | |
338 | expect(video.name).to.not.contain('video server 3 added after follow updated') | |
339 | } | |
340 | }) | |
341 | ||
342 | it('Should follow user of server 3 again', async function () { | |
343 | this.timeout(60000) | |
344 | ||
345 | await command.add({ token: users[0].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port }) | |
346 | ||
347 | await waitJobs(servers) | |
348 | ||
349 | { | |
350 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) | |
351 | expect(body.total).to.equal(3) | |
352 | ||
353 | const videos = body.data | |
354 | expect(videos).to.be.an('array') | |
355 | expect(videos).to.have.lengthOf(3) | |
356 | ||
357 | expect(videos[0].name).to.equal('video 1-3') | |
358 | expect(videos[1].name).to.equal('video 2-3') | |
359 | expect(videos[2].name).to.equal('video server 3 added after follow updated') | |
360 | } | |
361 | ||
362 | { | |
363 | const { total, data } = await servers[0].videos.list() | |
364 | expect(total).to.equal(5) | |
365 | ||
366 | for (const video of data) { | |
367 | expect(video.name).to.not.contain('1-3') | |
368 | expect(video.name).to.not.contain('2-3') | |
369 | expect(video.name).to.not.contain('video server 3 added after follow updated') | |
370 | } | |
371 | } | |
372 | }) | |
373 | ||
374 | it('Should follow user channels of server 3 by root of server 3', async function () { | |
375 | this.timeout(60000) | |
376 | ||
377 | await servers[2].channels.create({ token: users[2].accessToken, attributes: { name: 'user3_channel2' } }) | |
378 | ||
379 | await servers[2].subscriptions.add({ token: servers[2].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port }) | |
380 | await servers[2].subscriptions.add({ token: servers[2].accessToken, targetUri: 'user3_channel2@localhost:' + servers[2].port }) | |
381 | ||
382 | await waitJobs(servers) | |
383 | }) | |
384 | ||
385 | it('Should list user 3 followers', async function () { | |
386 | { | |
387 | const { total, data } = await servers[2].accounts.listFollowers({ | |
388 | token: users[2].accessToken, | |
389 | accountName: 'user3', | |
390 | start: 0, | |
391 | count: 5, | |
392 | sort: 'createdAt' | |
393 | }) | |
394 | ||
395 | expect(total).to.equal(3) | |
396 | expect(data).to.have.lengthOf(3) | |
397 | ||
398 | expect(data[0].following.host).to.equal(servers[2].host) | |
399 | expect(data[0].following.name).to.equal('user3_channel') | |
400 | expect(data[0].follower.host).to.equal(servers[0].host) | |
401 | expect(data[0].follower.name).to.equal('user1') | |
402 | ||
403 | expect(data[1].following.host).to.equal(servers[2].host) | |
404 | expect(data[1].following.name).to.equal('user3_channel') | |
405 | expect(data[1].follower.host).to.equal(servers[2].host) | |
406 | expect(data[1].follower.name).to.equal('root') | |
407 | ||
408 | expect(data[2].following.host).to.equal(servers[2].host) | |
409 | expect(data[2].following.name).to.equal('user3_channel2') | |
410 | expect(data[2].follower.host).to.equal(servers[2].host) | |
411 | expect(data[2].follower.name).to.equal('root') | |
412 | } | |
413 | ||
414 | { | |
415 | const { total, data } = await servers[2].accounts.listFollowers({ | |
416 | token: users[2].accessToken, | |
417 | accountName: 'user3', | |
418 | start: 0, | |
419 | count: 1, | |
420 | sort: '-createdAt' | |
421 | }) | |
422 | ||
423 | expect(total).to.equal(3) | |
424 | expect(data).to.have.lengthOf(1) | |
425 | ||
426 | expect(data[0].following.host).to.equal(servers[2].host) | |
427 | expect(data[0].following.name).to.equal('user3_channel2') | |
428 | expect(data[0].follower.host).to.equal(servers[2].host) | |
429 | expect(data[0].follower.name).to.equal('root') | |
430 | } | |
431 | ||
432 | { | |
433 | const { total, data } = await servers[2].accounts.listFollowers({ | |
434 | token: users[2].accessToken, | |
435 | accountName: 'user3', | |
436 | start: 1, | |
437 | count: 1, | |
438 | sort: '-createdAt' | |
439 | }) | |
440 | ||
441 | expect(total).to.equal(3) | |
442 | expect(data).to.have.lengthOf(1) | |
443 | ||
444 | expect(data[0].following.host).to.equal(servers[2].host) | |
445 | expect(data[0].following.name).to.equal('user3_channel') | |
446 | expect(data[0].follower.host).to.equal(servers[2].host) | |
447 | expect(data[0].follower.name).to.equal('root') | |
448 | } | |
449 | ||
450 | { | |
451 | const { total, data } = await servers[2].accounts.listFollowers({ | |
452 | token: users[2].accessToken, | |
453 | accountName: 'user3', | |
454 | search: 'user1', | |
455 | sort: '-createdAt' | |
456 | }) | |
457 | ||
458 | expect(total).to.equal(1) | |
459 | expect(data).to.have.lengthOf(1) | |
460 | ||
461 | expect(data[0].following.host).to.equal(servers[2].host) | |
462 | expect(data[0].following.name).to.equal('user3_channel') | |
463 | expect(data[0].follower.host).to.equal(servers[0].host) | |
464 | expect(data[0].follower.name).to.equal('user1') | |
465 | } | |
466 | }) | |
467 | ||
468 | it('Should list user3_channel followers', async function () { | |
469 | { | |
470 | const { total, data } = await servers[2].channels.listFollowers({ | |
471 | token: users[2].accessToken, | |
472 | channelName: 'user3_channel', | |
473 | start: 0, | |
474 | count: 5, | |
475 | sort: 'createdAt' | |
476 | }) | |
477 | ||
478 | expect(total).to.equal(2) | |
479 | expect(data).to.have.lengthOf(2) | |
480 | ||
481 | expect(data[0].following.host).to.equal(servers[2].host) | |
482 | expect(data[0].following.name).to.equal('user3_channel') | |
483 | expect(data[0].follower.host).to.equal(servers[0].host) | |
484 | expect(data[0].follower.name).to.equal('user1') | |
485 | ||
486 | expect(data[1].following.host).to.equal(servers[2].host) | |
487 | expect(data[1].following.name).to.equal('user3_channel') | |
488 | expect(data[1].follower.host).to.equal(servers[2].host) | |
489 | expect(data[1].follower.name).to.equal('root') | |
490 | } | |
491 | ||
492 | { | |
493 | const { total, data } = await servers[2].channels.listFollowers({ | |
494 | token: users[2].accessToken, | |
495 | channelName: 'user3_channel', | |
496 | start: 0, | |
497 | count: 1, | |
498 | sort: '-createdAt' | |
499 | }) | |
500 | ||
501 | expect(total).to.equal(2) | |
502 | expect(data).to.have.lengthOf(1) | |
503 | ||
504 | expect(data[0].following.host).to.equal(servers[2].host) | |
505 | expect(data[0].following.name).to.equal('user3_channel') | |
506 | expect(data[0].follower.host).to.equal(servers[2].host) | |
507 | expect(data[0].follower.name).to.equal('root') | |
508 | } | |
509 | ||
510 | { | |
511 | const { total, data } = await servers[2].channels.listFollowers({ | |
512 | token: users[2].accessToken, | |
513 | channelName: 'user3_channel', | |
514 | start: 1, | |
515 | count: 1, | |
516 | sort: '-createdAt' | |
517 | }) | |
518 | ||
519 | expect(total).to.equal(2) | |
520 | expect(data).to.have.lengthOf(1) | |
521 | ||
522 | expect(data[0].following.host).to.equal(servers[2].host) | |
523 | expect(data[0].following.name).to.equal('user3_channel') | |
524 | expect(data[0].follower.host).to.equal(servers[0].host) | |
525 | expect(data[0].follower.name).to.equal('user1') | |
526 | } | |
527 | ||
528 | { | |
529 | const { total, data } = await servers[2].channels.listFollowers({ | |
530 | token: users[2].accessToken, | |
531 | channelName: 'user3_channel', | |
532 | search: 'user1', | |
533 | sort: '-createdAt' | |
534 | }) | |
535 | ||
536 | expect(total).to.equal(1) | |
537 | expect(data).to.have.lengthOf(1) | |
538 | ||
539 | expect(data[0].following.host).to.equal(servers[2].host) | |
540 | expect(data[0].following.name).to.equal('user3_channel') | |
541 | expect(data[0].follower.host).to.equal(servers[0].host) | |
542 | expect(data[0].follower.name).to.equal('user1') | |
543 | } | |
544 | }) | |
545 | ||
546 | it('Should update video as internal and not see from remote server', async function () { | |
547 | this.timeout(30000) | |
548 | ||
549 | await servers[2].videos.update({ id: video3UUID, attributes: { name: 'internal', privacy: VideoPrivacy.INTERNAL } }) | |
550 | await waitJobs(servers) | |
551 | ||
552 | { | |
553 | const { data } = await command.listVideos({ token: users[0].accessToken }) | |
554 | expect(data.find(v => v.name === 'internal')).to.not.exist | |
555 | } | |
556 | }) | |
557 | ||
558 | it('Should see internal from local user', async function () { | |
559 | const { data } = await servers[2].subscriptions.listVideos({ token: servers[2].accessToken }) | |
560 | expect(data.find(v => v.name === 'internal')).to.exist | |
561 | }) | |
562 | ||
563 | it('Should update video as private and not see from anyone server', async function () { | |
564 | this.timeout(30000) | |
565 | ||
566 | await servers[2].videos.update({ id: video3UUID, attributes: { name: 'private', privacy: VideoPrivacy.PRIVATE } }) | |
567 | await waitJobs(servers) | |
568 | ||
569 | { | |
570 | const { data } = await command.listVideos({ token: users[0].accessToken }) | |
571 | expect(data.find(v => v.name === 'private')).to.not.exist | |
572 | } | |
573 | ||
574 | { | |
575 | const { data } = await servers[2].subscriptions.listVideos({ token: servers[2].accessToken }) | |
576 | expect(data.find(v => v.name === 'private')).to.not.exist | |
577 | } | |
578 | }) | |
579 | ||
580 | after(async function () { | |
581 | await cleanupTests(servers) | |
582 | }) | |
583 | }) |