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