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