aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users/user-subscriptions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/users/user-subscriptions.ts')
-rw-r--r--server/tests/api/users/user-subscriptions.ts312
1 files changed, 312 insertions, 0 deletions
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts
new file mode 100644
index 000000000..2ba6cdfaf
--- /dev/null
+++ b/server/tests/api/users/user-subscriptions.ts
@@ -0,0 +1,312 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { createUser, doubleFollow, flushAndRunMultipleServers, follow, getVideosList, unfollow, userLogin } from '../../utils'
6import { getMyUserInformation, killallServers, ServerInfo, uploadVideo } from '../../utils/index'
7import { setAccessTokensToServers } from '../../utils/users/login'
8import { Video, VideoChannel } from '../../../../shared/models/videos'
9import { waitJobs } from '../../utils/server/jobs'
10import {
11 addUserSubscription,
12 listUserSubscriptions,
13 listUserSubscriptionVideos,
14 removeUserSubscription
15} from '../../utils/users/user-subscriptions'
16
17const expect = chai.expect
18
19describe('Test users subscriptions', function () {
20 let servers: ServerInfo[] = []
21 const users: { accessToken: string, videoChannelName: string }[] = []
22 let rootChannelNameServer1: string
23
24 before(async function () {
25 this.timeout(120000)
26
27 servers = await flushAndRunMultipleServers(3)
28
29 // Get the access tokens
30 await setAccessTokensToServers(servers)
31
32 // Server 1 and server 2 follow each other
33 await doubleFollow(servers[0], servers[1])
34
35 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
36 rootChannelNameServer1 = res.body.videoChannels[0].name
37
38 {
39 for (const server of servers) {
40 const user = { username: 'user' + server.serverNumber, password: 'password' }
41 await createUser(server.url, server.accessToken, user.username, user.password)
42
43 const accessToken = await userLogin(server, user)
44 const res = await getMyUserInformation(server.url, accessToken)
45 const videoChannels: VideoChannel[] = res.body.videoChannels
46
47 users.push({ accessToken, videoChannelName: videoChannels[0].name })
48
49 const videoName1 = 'video 1-' + server.serverNumber
50 await uploadVideo(server.url, accessToken, { name: videoName1 })
51
52 const videoName2 = 'video 2-' + server.serverNumber
53 await uploadVideo(server.url, accessToken, { name: videoName2 })
54 }
55 }
56
57 await waitJobs(servers)
58 })
59
60 it('Should display videos of server 2 on server 1', async function () {
61 const res = await getVideosList(servers[0].url)
62
63 expect(res.body.total).to.equal(4)
64 })
65
66 it('User of server 1 should follow user of server 3 and root of server 1', async function () {
67 this.timeout(30000)
68
69 await addUserSubscription(servers[0].url, users[0].accessToken, users[2].videoChannelName + '@localhost:9003')
70 await addUserSubscription(servers[0].url, users[0].accessToken, rootChannelNameServer1 + '@localhost:9001')
71
72 await waitJobs(servers)
73
74 await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' })
75
76 await waitJobs(servers)
77 })
78
79 it('Should not display videos of server 3 on server 1', async function () {
80 const res = await getVideosList(servers[0].url)
81
82 expect(res.body.total).to.equal(4)
83 for (const video of res.body.data) {
84 expect(video.name).to.not.contain('1-3')
85 expect(video.name).to.not.contain('2-3')
86 expect(video.name).to.not.contain('video server 3 added after follow')
87 }
88 })
89
90 it('Should list subscriptions', async function () {
91 {
92 const res = await listUserSubscriptions(servers[0].url, servers[0].accessToken)
93 expect(res.body.total).to.equal(0)
94 expect(res.body.data).to.be.an('array')
95 expect(res.body.data).to.have.lengthOf(0)
96 }
97
98 {
99 const res = await listUserSubscriptions(servers[0].url, users[0].accessToken)
100 expect(res.body.total).to.equal(2)
101
102 const subscriptions: VideoChannel[] = res.body.data
103 expect(subscriptions).to.be.an('array')
104 expect(subscriptions).to.have.lengthOf(2)
105
106 expect(subscriptions[0].name).to.equal(users[2].videoChannelName)
107 expect(subscriptions[1].name).to.equal(rootChannelNameServer1)
108 }
109 })
110
111 it('Should list subscription videos', async function () {
112 {
113 const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken)
114 expect(res.body.total).to.equal(0)
115 expect(res.body.data).to.be.an('array')
116 expect(res.body.data).to.have.lengthOf(0)
117 }
118
119 {
120 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt')
121 expect(res.body.total).to.equal(3)
122
123 const videos: Video[] = res.body.data
124 expect(videos).to.be.an('array')
125 expect(videos).to.have.lengthOf(3)
126
127 expect(videos[0].name).to.equal('video 1-3')
128 expect(videos[1].name).to.equal('video 2-3')
129 expect(videos[2].name).to.equal('video server 3 added after follow')
130 }
131 })
132
133 it('Should upload a video by root on server 1 and see it in the subscription videos', async function () {
134 this.timeout(30000)
135
136 const videoName = 'video server 1 added after follow'
137 await uploadVideo(servers[0].url, servers[0].accessToken, { name: videoName })
138
139 await waitJobs(servers)
140
141 {
142 const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken)
143 expect(res.body.total).to.equal(0)
144 expect(res.body.data).to.be.an('array')
145 expect(res.body.data).to.have.lengthOf(0)
146 }
147
148 {
149 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt')
150 expect(res.body.total).to.equal(4)
151
152 const videos: Video[] = res.body.data
153 expect(videos).to.be.an('array')
154 expect(videos).to.have.lengthOf(4)
155
156 expect(videos[0].name).to.equal('video 1-3')
157 expect(videos[1].name).to.equal('video 2-3')
158 expect(videos[2].name).to.equal('video server 3 added after follow')
159 expect(videos[3].name).to.equal('video server 1 added after follow')
160 }
161
162 {
163 const res = await getVideosList(servers[0].url)
164
165 expect(res.body.total).to.equal(5)
166 for (const video of res.body.data) {
167 expect(video.name).to.not.contain('1-3')
168 expect(video.name).to.not.contain('2-3')
169 expect(video.name).to.not.contain('video server 3 added after follow')
170 }
171 }
172 })
173
174 it('Should have server 1 follow server 3 and display server 3 videos', async function () {
175 this.timeout(30000)
176
177 await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken)
178
179 await waitJobs(servers)
180
181 const res = await getVideosList(servers[0].url)
182
183 expect(res.body.total).to.equal(8)
184
185 const names = [ '1-3', '2-3', 'video server 3 added after follow' ]
186 for (const name of names) {
187 const video = res.body.data.find(v => v.name.indexOf(name) === -1)
188 expect(video).to.not.be.undefined
189 }
190 })
191
192 it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () {
193 this.timeout(30000)
194
195 await unfollow(servers[0].url, servers[0].accessToken, servers[2])
196
197 await waitJobs(servers)
198
199 const res = await getVideosList(servers[0].url)
200
201 expect(res.body.total).to.equal(5)
202 for (const video of res.body.data) {
203 expect(video.name).to.not.contain('1-3')
204 expect(video.name).to.not.contain('2-3')
205 expect(video.name).to.not.contain('video server 3 added after follow')
206 }
207 })
208
209 it('Should still list subscription videos', async function () {
210 {
211 const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken)
212 expect(res.body.total).to.equal(0)
213 expect(res.body.data).to.be.an('array')
214 expect(res.body.data).to.have.lengthOf(0)
215 }
216
217 {
218 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt')
219 expect(res.body.total).to.equal(4)
220
221 const videos: Video[] = res.body.data
222 expect(videos).to.be.an('array')
223 expect(videos).to.have.lengthOf(4)
224
225 expect(videos[0].name).to.equal('video 1-3')
226 expect(videos[1].name).to.equal('video 2-3')
227 expect(videos[2].name).to.equal('video server 3 added after follow')
228 expect(videos[3].name).to.equal('video server 1 added after follow')
229 }
230 })
231
232 it('Should remove user of server 3 subscription', async function () {
233 await removeUserSubscription(servers[0].url, users[0].accessToken, users[2].videoChannelName + '@localhost:9003')
234
235 await waitJobs(servers)
236 })
237
238 it('Should not display its videos anymore', async function () {
239 {
240 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt')
241 expect(res.body.total).to.equal(1)
242
243 const videos: Video[] = res.body.data
244 expect(videos).to.be.an('array')
245 expect(videos).to.have.lengthOf(1)
246
247 expect(videos[0].name).to.equal('video server 1 added after follow')
248 }
249 })
250
251 it('Should remove the root subscription and not display the videos anymore', async function () {
252 await removeUserSubscription(servers[0].url, users[0].accessToken, rootChannelNameServer1 + '@localhost:9001')
253
254 await waitJobs(servers)
255
256 {
257 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt')
258 expect(res.body.total).to.equal(0)
259
260 const videos: Video[] = res.body.data
261 expect(videos).to.be.an('array')
262 expect(videos).to.have.lengthOf(0)
263 }
264 })
265
266 it('Should correctly display public videos on server 1', async function () {
267 const res = await getVideosList(servers[0].url)
268
269 expect(res.body.total).to.equal(5)
270 for (const video of res.body.data) {
271 expect(video.name).to.not.contain('1-3')
272 expect(video.name).to.not.contain('2-3')
273 expect(video.name).to.not.contain('video server 3 added after follow')
274 }
275 })
276
277 it('Should follow user of server 3 again', async function () {
278 this.timeout(30000)
279
280 await addUserSubscription(servers[0].url, users[0].accessToken, users[2].videoChannelName + '@localhost:9003')
281
282 await waitJobs(servers)
283
284 {
285 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt')
286 expect(res.body.total).to.equal(3)
287
288 const videos: Video[] = res.body.data
289 expect(videos).to.be.an('array')
290 expect(videos).to.have.lengthOf(3)
291
292 expect(videos[0].name).to.equal('video 1-3')
293 expect(videos[1].name).to.equal('video 2-3')
294 expect(videos[2].name).to.equal('video server 3 added after follow')
295 }
296
297 {
298 const res = await getVideosList(servers[0].url)
299
300 expect(res.body.total).to.equal(5)
301 for (const video of res.body.data) {
302 expect(video.name).to.not.contain('1-3')
303 expect(video.name).to.not.contain('2-3')
304 expect(video.name).to.not.contain('video server 3 added after follow')
305 }
306 }
307 })
308
309 after(async function () {
310 killallServers(servers)
311 })
312})