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