]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
06a05d5f C |
2 | |
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
9639bd17 | 5 | import { |
7c3b7976 | 6 | cleanupTests, |
9639bd17 | 7 | createUser, |
8 | doubleFollow, | |
9 | flushAndRunMultipleServers, | |
10 | follow, | |
11 | getVideosList, | |
12 | unfollow, | |
13 | updateVideo, | |
14 | userLogin | |
94565d52 | 15 | } from '../../../../shared/extra-utils' |
a1587156 | 16 | import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' |
94565d52 | 17 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' |
06a05d5f | 18 | import { Video, VideoChannel } from '../../../../shared/models/videos' |
94565d52 | 19 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
06a05d5f C |
20 | import { |
21 | addUserSubscription, | |
a1587156 C |
22 | areSubscriptionsExist, |
23 | getUserSubscription, | |
06a05d5f C |
24 | listUserSubscriptions, |
25 | listUserSubscriptionVideos, | |
a1587156 | 26 | removeUserSubscription |
94565d52 | 27 | } from '../../../../shared/extra-utils/users/user-subscriptions' |
06a05d5f C |
28 | |
29 | const expect = chai.expect | |
30 | ||
31 | describe('Test users subscriptions', function () { | |
32 | let servers: ServerInfo[] = [] | |
8a19bee1 | 33 | const users: { accessToken: string }[] = [] |
f6eebcb3 | 34 | let video3UUID: string |
06a05d5f C |
35 | |
36 | before(async function () { | |
37 | this.timeout(120000) | |
38 | ||
39 | servers = await flushAndRunMultipleServers(3) | |
40 | ||
41 | // Get the access tokens | |
42 | await setAccessTokensToServers(servers) | |
43 | ||
44 | // Server 1 and server 2 follow each other | |
45 | await doubleFollow(servers[0], servers[1]) | |
46 | ||
06a05d5f C |
47 | { |
48 | for (const server of servers) { | |
49 | const user = { username: 'user' + server.serverNumber, password: 'password' } | |
1eddc9a7 | 50 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
06a05d5f C |
51 | |
52 | const accessToken = await userLogin(server, user) | |
8a19bee1 | 53 | users.push({ accessToken }) |
06a05d5f C |
54 | |
55 | const videoName1 = 'video 1-' + server.serverNumber | |
56 | await uploadVideo(server.url, accessToken, { name: videoName1 }) | |
57 | ||
58 | const videoName2 = 'video 2-' + server.serverNumber | |
59 | await uploadVideo(server.url, accessToken, { name: videoName2 }) | |
60 | } | |
61 | } | |
62 | ||
63 | await waitJobs(servers) | |
64 | }) | |
65 | ||
66 | it('Should display videos of server 2 on server 1', async function () { | |
67 | const res = await getVideosList(servers[0].url) | |
68 | ||
69 | expect(res.body.total).to.equal(4) | |
70 | }) | |
71 | ||
72 | it('User of server 1 should follow user of server 3 and root of server 1', async function () { | |
8a19bee1 | 73 | this.timeout(60000) |
06a05d5f | 74 | |
48f07b4a C |
75 | await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) |
76 | await addUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) | |
06a05d5f C |
77 | |
78 | await waitJobs(servers) | |
79 | ||
f6eebcb3 C |
80 | const res = await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' }) |
81 | video3UUID = res.body.video.uuid | |
06a05d5f C |
82 | |
83 | await waitJobs(servers) | |
84 | }) | |
85 | ||
86 | it('Should not display videos of server 3 on server 1', async function () { | |
87 | const res = await getVideosList(servers[0].url) | |
88 | ||
89 | expect(res.body.total).to.equal(4) | |
90 | for (const video of res.body.data) { | |
91 | expect(video.name).to.not.contain('1-3') | |
92 | expect(video.name).to.not.contain('2-3') | |
93 | expect(video.name).to.not.contain('video server 3 added after follow') | |
94 | } | |
95 | }) | |
96 | ||
97 | it('Should list subscriptions', async function () { | |
98 | { | |
7b390964 | 99 | const res = await listUserSubscriptions({ url: servers[0].url, token: servers[0].accessToken }) |
06a05d5f C |
100 | expect(res.body.total).to.equal(0) |
101 | expect(res.body.data).to.be.an('array') | |
102 | expect(res.body.data).to.have.lengthOf(0) | |
103 | } | |
104 | ||
105 | { | |
7b390964 | 106 | const res = await listUserSubscriptions({ url: servers[0].url, token: users[0].accessToken, sort: 'createdAt' }) |
06a05d5f C |
107 | expect(res.body.total).to.equal(2) |
108 | ||
109 | const subscriptions: VideoChannel[] = res.body.data | |
110 | expect(subscriptions).to.be.an('array') | |
111 | expect(subscriptions).to.have.lengthOf(2) | |
112 | ||
8a19bee1 C |
113 | expect(subscriptions[0].name).to.equal('user3_channel') |
114 | expect(subscriptions[1].name).to.equal('root_channel') | |
06a05d5f C |
115 | } |
116 | }) | |
117 | ||
99492dbc C |
118 | it('Should get subscription', async function () { |
119 | { | |
a1587156 | 120 | const res = await getUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) |
99492dbc C |
121 | const videoChannel: VideoChannel = res.body |
122 | ||
123 | expect(videoChannel.name).to.equal('user3_channel') | |
48f07b4a | 124 | expect(videoChannel.host).to.equal('localhost:' + servers[2].port) |
99492dbc C |
125 | expect(videoChannel.displayName).to.equal('Main user3 channel') |
126 | expect(videoChannel.followingCount).to.equal(0) | |
127 | expect(videoChannel.followersCount).to.equal(1) | |
128 | } | |
129 | ||
130 | { | |
a1587156 | 131 | const res = await getUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) |
99492dbc C |
132 | const videoChannel: VideoChannel = res.body |
133 | ||
134 | expect(videoChannel.name).to.equal('root_channel') | |
48f07b4a | 135 | expect(videoChannel.host).to.equal('localhost:' + servers[0].port) |
99492dbc C |
136 | expect(videoChannel.displayName).to.equal('Main root channel') |
137 | expect(videoChannel.followingCount).to.equal(0) | |
138 | expect(videoChannel.followersCount).to.equal(1) | |
139 | } | |
140 | }) | |
141 | ||
f37dc0dd C |
142 | it('Should return the existing subscriptions', async function () { |
143 | const uris = [ | |
48f07b4a C |
144 | 'user3_channel@localhost:' + servers[2].port, |
145 | 'root2_channel@localhost:' + servers[0].port, | |
146 | 'root_channel@localhost:' + servers[0].port, | |
147 | 'user3_channel@localhost:' + servers[0].port | |
f37dc0dd C |
148 | ] |
149 | ||
a1587156 | 150 | const res = await areSubscriptionsExist(servers[0].url, users[0].accessToken, uris) |
f37dc0dd C |
151 | const body = res.body |
152 | ||
48f07b4a C |
153 | expect(body['user3_channel@localhost:' + servers[2].port]).to.be.true |
154 | expect(body['root2_channel@localhost:' + servers[0].port]).to.be.false | |
155 | expect(body['root_channel@localhost:' + servers[0].port]).to.be.true | |
156 | expect(body['user3_channel@localhost:' + servers[0].port]).to.be.false | |
f37dc0dd C |
157 | }) |
158 | ||
7b390964 RK |
159 | it('Should search among subscriptions', async function () { |
160 | { | |
161 | const res = await listUserSubscriptions({ | |
162 | url: servers[0].url, | |
163 | token: users[0].accessToken, | |
164 | sort: '-createdAt', | |
165 | search: 'user3_channel' | |
166 | }) | |
167 | expect(res.body.total).to.equal(1) | |
168 | ||
169 | const subscriptions = res.body.data | |
170 | expect(subscriptions).to.have.lengthOf(1) | |
171 | } | |
172 | ||
173 | { | |
174 | const res = await listUserSubscriptions({ | |
175 | url: servers[0].url, | |
176 | token: users[0].accessToken, | |
177 | sort: '-createdAt', | |
178 | search: 'toto' | |
179 | }) | |
180 | expect(res.body.total).to.equal(0) | |
181 | ||
182 | const subscriptions = res.body.data | |
183 | expect(subscriptions).to.have.lengthOf(0) | |
184 | } | |
185 | }) | |
186 | ||
06a05d5f C |
187 | it('Should list subscription videos', async function () { |
188 | { | |
189 | const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) | |
190 | expect(res.body.total).to.equal(0) | |
191 | expect(res.body.data).to.be.an('array') | |
192 | expect(res.body.data).to.have.lengthOf(0) | |
193 | } | |
194 | ||
195 | { | |
196 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | |
197 | expect(res.body.total).to.equal(3) | |
198 | ||
199 | const videos: Video[] = res.body.data | |
200 | expect(videos).to.be.an('array') | |
201 | expect(videos).to.have.lengthOf(3) | |
202 | ||
203 | expect(videos[0].name).to.equal('video 1-3') | |
204 | expect(videos[1].name).to.equal('video 2-3') | |
205 | expect(videos[2].name).to.equal('video server 3 added after follow') | |
206 | } | |
207 | }) | |
208 | ||
209 | it('Should upload a video by root on server 1 and see it in the subscription videos', async function () { | |
8a19bee1 | 210 | this.timeout(60000) |
06a05d5f C |
211 | |
212 | const videoName = 'video server 1 added after follow' | |
213 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: videoName }) | |
214 | ||
215 | await waitJobs(servers) | |
216 | ||
217 | { | |
218 | const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) | |
219 | expect(res.body.total).to.equal(0) | |
220 | expect(res.body.data).to.be.an('array') | |
221 | expect(res.body.data).to.have.lengthOf(0) | |
222 | } | |
223 | ||
224 | { | |
225 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | |
226 | expect(res.body.total).to.equal(4) | |
227 | ||
228 | const videos: Video[] = res.body.data | |
229 | expect(videos).to.be.an('array') | |
230 | expect(videos).to.have.lengthOf(4) | |
231 | ||
232 | expect(videos[0].name).to.equal('video 1-3') | |
233 | expect(videos[1].name).to.equal('video 2-3') | |
234 | expect(videos[2].name).to.equal('video server 3 added after follow') | |
235 | expect(videos[3].name).to.equal('video server 1 added after follow') | |
236 | } | |
237 | ||
238 | { | |
239 | const res = await getVideosList(servers[0].url) | |
240 | ||
241 | expect(res.body.total).to.equal(5) | |
242 | for (const video of res.body.data) { | |
243 | expect(video.name).to.not.contain('1-3') | |
244 | expect(video.name).to.not.contain('2-3') | |
245 | expect(video.name).to.not.contain('video server 3 added after follow') | |
246 | } | |
247 | } | |
248 | }) | |
249 | ||
250 | it('Should have server 1 follow server 3 and display server 3 videos', async function () { | |
8a19bee1 | 251 | this.timeout(60000) |
06a05d5f C |
252 | |
253 | await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken) | |
254 | ||
255 | await waitJobs(servers) | |
256 | ||
257 | const res = await getVideosList(servers[0].url) | |
258 | ||
259 | expect(res.body.total).to.equal(8) | |
260 | ||
261 | const names = [ '1-3', '2-3', 'video server 3 added after follow' ] | |
262 | for (const name of names) { | |
263 | const video = res.body.data.find(v => v.name.indexOf(name) === -1) | |
264 | expect(video).to.not.be.undefined | |
265 | } | |
266 | }) | |
267 | ||
268 | it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () { | |
8a19bee1 | 269 | this.timeout(60000) |
06a05d5f C |
270 | |
271 | await unfollow(servers[0].url, servers[0].accessToken, servers[2]) | |
272 | ||
273 | await waitJobs(servers) | |
274 | ||
275 | const res = await getVideosList(servers[0].url) | |
276 | ||
277 | expect(res.body.total).to.equal(5) | |
278 | for (const video of res.body.data) { | |
279 | expect(video.name).to.not.contain('1-3') | |
280 | expect(video.name).to.not.contain('2-3') | |
281 | expect(video.name).to.not.contain('video server 3 added after follow') | |
282 | } | |
283 | }) | |
284 | ||
285 | it('Should still list subscription videos', async function () { | |
286 | { | |
287 | const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) | |
288 | expect(res.body.total).to.equal(0) | |
289 | expect(res.body.data).to.be.an('array') | |
290 | expect(res.body.data).to.have.lengthOf(0) | |
291 | } | |
292 | ||
293 | { | |
294 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | |
295 | expect(res.body.total).to.equal(4) | |
296 | ||
297 | const videos: Video[] = res.body.data | |
298 | expect(videos).to.be.an('array') | |
299 | expect(videos).to.have.lengthOf(4) | |
300 | ||
301 | expect(videos[0].name).to.equal('video 1-3') | |
302 | expect(videos[1].name).to.equal('video 2-3') | |
303 | expect(videos[2].name).to.equal('video server 3 added after follow') | |
304 | expect(videos[3].name).to.equal('video server 1 added after follow') | |
305 | } | |
306 | }) | |
307 | ||
f6eebcb3 C |
308 | it('Should update a video of server 3 and see the updated video on server 1', async function () { |
309 | this.timeout(30000) | |
310 | ||
311 | await updateVideo(servers[2].url, users[2].accessToken, video3UUID, { name: 'video server 3 added after follow updated' }) | |
312 | ||
313 | await waitJobs(servers) | |
314 | ||
315 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | |
316 | const videos: Video[] = res.body.data | |
317 | expect(videos[2].name).to.equal('video server 3 added after follow updated') | |
318 | }) | |
319 | ||
06a05d5f | 320 | it('Should remove user of server 3 subscription', async function () { |
f6eebcb3 C |
321 | this.timeout(30000) |
322 | ||
48f07b4a | 323 | await removeUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) |
06a05d5f C |
324 | |
325 | await waitJobs(servers) | |
326 | }) | |
327 | ||
328 | it('Should not display its videos anymore', async function () { | |
329 | { | |
330 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | |
331 | expect(res.body.total).to.equal(1) | |
332 | ||
333 | const videos: Video[] = res.body.data | |
334 | expect(videos).to.be.an('array') | |
335 | expect(videos).to.have.lengthOf(1) | |
336 | ||
337 | expect(videos[0].name).to.equal('video server 1 added after follow') | |
338 | } | |
339 | }) | |
340 | ||
341 | it('Should remove the root subscription and not display the videos anymore', async function () { | |
f6eebcb3 C |
342 | this.timeout(30000) |
343 | ||
48f07b4a | 344 | await removeUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) |
06a05d5f C |
345 | |
346 | await waitJobs(servers) | |
347 | ||
348 | { | |
349 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | |
350 | expect(res.body.total).to.equal(0) | |
351 | ||
352 | const videos: Video[] = res.body.data | |
353 | expect(videos).to.be.an('array') | |
354 | expect(videos).to.have.lengthOf(0) | |
355 | } | |
356 | }) | |
357 | ||
358 | it('Should correctly display public videos on server 1', async function () { | |
359 | const res = await getVideosList(servers[0].url) | |
360 | ||
361 | expect(res.body.total).to.equal(5) | |
362 | for (const video of res.body.data) { | |
363 | expect(video.name).to.not.contain('1-3') | |
364 | expect(video.name).to.not.contain('2-3') | |
f6eebcb3 | 365 | expect(video.name).to.not.contain('video server 3 added after follow updated') |
06a05d5f C |
366 | } |
367 | }) | |
368 | ||
369 | it('Should follow user of server 3 again', async function () { | |
8a19bee1 | 370 | this.timeout(60000) |
06a05d5f | 371 | |
48f07b4a | 372 | await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) |
06a05d5f C |
373 | |
374 | await waitJobs(servers) | |
375 | ||
376 | { | |
377 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | |
378 | expect(res.body.total).to.equal(3) | |
379 | ||
380 | const videos: Video[] = res.body.data | |
381 | expect(videos).to.be.an('array') | |
382 | expect(videos).to.have.lengthOf(3) | |
383 | ||
384 | expect(videos[0].name).to.equal('video 1-3') | |
385 | expect(videos[1].name).to.equal('video 2-3') | |
f6eebcb3 | 386 | expect(videos[2].name).to.equal('video server 3 added after follow updated') |
06a05d5f C |
387 | } |
388 | ||
389 | { | |
390 | const res = await getVideosList(servers[0].url) | |
391 | ||
392 | expect(res.body.total).to.equal(5) | |
393 | for (const video of res.body.data) { | |
394 | expect(video.name).to.not.contain('1-3') | |
395 | expect(video.name).to.not.contain('2-3') | |
f6eebcb3 | 396 | expect(video.name).to.not.contain('video server 3 added after follow updated') |
06a05d5f C |
397 | } |
398 | } | |
399 | }) | |
400 | ||
7c3b7976 C |
401 | after(async function () { |
402 | await cleanupTests(servers) | |
06a05d5f C |
403 | }) |
404 | }) |