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