]>
Commit | Line | Data |
---|---|---|
0e1dc3e7 | 1 | /* tslint:disable:no-unused-expression */ |
86d13ec2 | 2 | |
0e1dc3e7 | 3 | import * as chai from 'chai' |
afffe988 | 4 | import 'mocha' |
a18f275d | 5 | import { User, UserRole, Video } from '../../../../shared/index' |
0e1dc3e7 | 6 | import { |
a890d1e0 | 7 | blockUser, |
7c3b7976 | 8 | cleanupTests, |
a890d1e0 C |
9 | createUser, |
10 | deleteMe, | |
7c3b7976 | 11 | flushAndRunServer, |
c100a614 | 12 | getAccountRatings, |
a890d1e0 C |
13 | getBlacklistedVideosList, |
14 | getMyUserInformation, | |
15 | getMyUserVideoQuotaUsed, | |
16 | getMyUserVideoRating, | |
17 | getUserInformation, | |
18 | getUsersList, | |
19 | getUsersListPaginationAndSort, | |
1f20622f | 20 | getVideoChannel, |
a890d1e0 | 21 | getVideosList, |
a890d1e0 C |
22 | login, |
23 | makePutBodyRequest, | |
24 | rateVideo, | |
1f20622f | 25 | registerUserWithChannel, |
a890d1e0 C |
26 | removeUser, |
27 | removeVideo, | |
a890d1e0 C |
28 | ServerInfo, |
29 | testImage, | |
30 | unblockUser, | |
31 | updateMyAvatar, | |
32 | updateMyUser, | |
33 | updateUser, | |
34 | uploadVideo, | |
1f20622f | 35 | userLogin |
94565d52 C |
36 | } from '../../../../shared/extra-utils' |
37 | import { follow } from '../../../../shared/extra-utils/server/follows' | |
38 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | |
39 | import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' | |
1eddc9a7 | 40 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' |
0e1dc3e7 | 41 | |
afffe988 C |
42 | const expect = chai.expect |
43 | ||
0e1dc3e7 C |
44 | describe('Test users', function () { |
45 | let server: ServerInfo | |
46 | let accessToken: string | |
47 | let accessTokenUser: string | |
48 | let videoId: number | |
49 | let userId: number | |
f8b8c36b C |
50 | const user = { |
51 | username: 'user_1', | |
52 | password: 'super password' | |
53 | } | |
0e1dc3e7 C |
54 | |
55 | before(async function () { | |
e212f887 | 56 | this.timeout(30000) |
210feb6c | 57 | server = await flushAndRunServer(1) |
86d13ec2 C |
58 | |
59 | await setAccessTokensToServers([ server ]) | |
0e1dc3e7 C |
60 | }) |
61 | ||
1eddc9a7 C |
62 | describe('OAuth client', function () { |
63 | it('Should create a new client') | |
0e1dc3e7 | 64 | |
1eddc9a7 | 65 | it('Should return the first client') |
0e1dc3e7 | 66 | |
1eddc9a7 | 67 | it('Should remove the last client') |
0e1dc3e7 | 68 | |
1eddc9a7 C |
69 | it('Should not login with an invalid client id', async function () { |
70 | const client = { id: 'client', secret: server.client.secret } | |
71 | const res = await login(server.url, client, server.user, 400) | |
0e1dc3e7 | 72 | |
1eddc9a7 C |
73 | expect(res.body.error).to.contain('client is invalid') |
74 | }) | |
0e1dc3e7 | 75 | |
1eddc9a7 C |
76 | it('Should not login with an invalid client secret', async function () { |
77 | const client = { id: server.client.id, secret: 'coucou' } | |
78 | const res = await login(server.url, client, server.user, 400) | |
0e1dc3e7 | 79 | |
1eddc9a7 C |
80 | expect(res.body.error).to.contain('client is invalid') |
81 | }) | |
0e1dc3e7 C |
82 | }) |
83 | ||
1eddc9a7 | 84 | describe('Login', function () { |
0e1dc3e7 | 85 | |
1eddc9a7 C |
86 | it('Should not login with an invalid username', async function () { |
87 | const user = { username: 'captain crochet', password: server.user.password } | |
88 | const res = await login(server.url, server.client, user, 400) | |
0e1dc3e7 | 89 | |
1eddc9a7 C |
90 | expect(res.body.error).to.contain('credentials are invalid') |
91 | }) | |
0e1dc3e7 | 92 | |
1eddc9a7 C |
93 | it('Should not login with an invalid password', async function () { |
94 | const user = { username: server.user.username, password: 'mew_three' } | |
95 | const res = await login(server.url, server.client, user, 400) | |
0e1dc3e7 | 96 | |
1eddc9a7 C |
97 | expect(res.body.error).to.contain('credentials are invalid') |
98 | }) | |
0e1dc3e7 | 99 | |
1eddc9a7 C |
100 | it('Should not be able to upload a video', async function () { |
101 | accessToken = 'my_super_token' | |
0e1dc3e7 | 102 | |
1eddc9a7 C |
103 | const videoAttributes = {} |
104 | await uploadVideo(server.url, accessToken, videoAttributes, 401) | |
105 | }) | |
0e1dc3e7 | 106 | |
1eddc9a7 C |
107 | it('Should not be able to follow', async function () { |
108 | accessToken = 'my_super_token' | |
109 | await follow(server.url, [ 'http://example.com' ], accessToken, 401) | |
110 | }) | |
0e1dc3e7 | 111 | |
1eddc9a7 | 112 | it('Should not be able to unfollow') |
0e1dc3e7 | 113 | |
1eddc9a7 C |
114 | it('Should be able to login', async function () { |
115 | const res = await login(server.url, server.client, server.user, 200) | |
0e1dc3e7 | 116 | |
1eddc9a7 C |
117 | accessToken = res.body.access_token |
118 | }) | |
50b4dcce NB |
119 | |
120 | it('Should be able to login with an insensitive username', async function () { | |
121 | const user = { username: 'RoOt', password: server.user.password } | |
122 | const res = await login(server.url, server.client, user, 200) | |
123 | ||
124 | const user2 = { username: 'rOoT', password: server.user.password } | |
125 | const res2 = await login(server.url, server.client, user2, 200) | |
126 | ||
127 | const user3 = { username: 'ROOt', password: server.user.password } | |
128 | const res3 = await login(server.url, server.client, user3, 200) | |
129 | }) | |
0e1dc3e7 C |
130 | }) |
131 | ||
1eddc9a7 | 132 | describe('Upload', function () { |
0e1dc3e7 | 133 | |
1eddc9a7 C |
134 | it('Should upload the video with the correct token', async function () { |
135 | const videoAttributes = {} | |
136 | await uploadVideo(server.url, accessToken, videoAttributes) | |
137 | const res = await getVideosList(server.url) | |
138 | const video = res.body.data[ 0 ] | |
0e1dc3e7 | 139 | |
1eddc9a7 C |
140 | expect(video.account.name).to.equal('root') |
141 | videoId = video.id | |
142 | }) | |
143 | ||
144 | it('Should upload the video again with the correct token', async function () { | |
145 | const videoAttributes = {} | |
146 | await uploadVideo(server.url, accessToken, videoAttributes) | |
147 | }) | |
0e1dc3e7 C |
148 | }) |
149 | ||
1eddc9a7 | 150 | describe('Ratings', function () { |
22834691 | 151 | |
1eddc9a7 C |
152 | it('Should retrieve a video rating', async function () { |
153 | await rateVideo(server.url, accessToken, videoId, 'like') | |
154 | const res = await getMyUserVideoRating(server.url, accessToken, videoId) | |
155 | const rating = res.body | |
c100a614 | 156 | |
1eddc9a7 C |
157 | expect(rating.videoId).to.equal(videoId) |
158 | expect(rating.rating).to.equal('like') | |
159 | }) | |
c100a614 | 160 | |
1eddc9a7 C |
161 | it('Should retrieve ratings list', async function () { |
162 | await rateVideo(server.url, accessToken, videoId, 'like') | |
22834691 | 163 | |
1eddc9a7 | 164 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200) |
22834691 | 165 | const ratings = res.body |
0e1dc3e7 | 166 | |
1eddc9a7 C |
167 | expect(ratings.total).to.equal(1) |
168 | expect(ratings.data[ 0 ].video.id).to.equal(videoId) | |
169 | expect(ratings.data[ 0 ].rating).to.equal('like') | |
170 | }) | |
0e1dc3e7 | 171 | |
1eddc9a7 C |
172 | it('Should retrieve ratings list by rating type', async function () { |
173 | { | |
174 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') | |
175 | const ratings = res.body | |
176 | expect(ratings.data.length).to.equal(1) | |
177 | } | |
178 | ||
179 | { | |
180 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') | |
181 | const ratings = res.body | |
182 | expect(ratings.data.length).to.equal(0) | |
183 | } | |
184 | }) | |
0e1dc3e7 C |
185 | }) |
186 | ||
1eddc9a7 C |
187 | describe('Remove video', function () { |
188 | it('Should not be able to remove the video with an incorrect token', async function () { | |
189 | await removeVideo(server.url, 'bad_token', videoId, 401) | |
190 | }) | |
0e1dc3e7 | 191 | |
1eddc9a7 | 192 | it('Should not be able to remove the video with the token of another account') |
0e1dc3e7 | 193 | |
1eddc9a7 C |
194 | it('Should be able to remove the video with the correct token', async function () { |
195 | await removeVideo(server.url, accessToken, videoId) | |
196 | }) | |
0e1dc3e7 C |
197 | }) |
198 | ||
1eddc9a7 C |
199 | describe('Logout', function () { |
200 | it('Should logout (revoke token)') | |
0e1dc3e7 | 201 | |
1eddc9a7 | 202 | it('Should not be able to get the user information') |
0e1dc3e7 | 203 | |
1eddc9a7 | 204 | it('Should not be able to upload a video') |
0e1dc3e7 | 205 | |
1eddc9a7 | 206 | it('Should not be able to remove a video') |
0e1dc3e7 | 207 | |
1eddc9a7 C |
208 | it('Should not be able to rate a video', async function () { |
209 | const path = '/api/v1/videos/' | |
210 | const data = { | |
211 | rating: 'likes' | |
212 | } | |
0e1dc3e7 | 213 | |
1eddc9a7 C |
214 | const options = { |
215 | url: server.url, | |
216 | path: path + videoId, | |
217 | token: 'wrong token', | |
218 | fields: data, | |
219 | statusCodeExpected: 401 | |
220 | } | |
221 | await makePutBodyRequest(options) | |
222 | }) | |
0e1dc3e7 | 223 | |
1eddc9a7 | 224 | it('Should be able to login again') |
0e1dc3e7 | 225 | |
1eddc9a7 | 226 | it('Should have an expired access token') |
0e1dc3e7 | 227 | |
1eddc9a7 C |
228 | it('Should refresh the token') |
229 | ||
230 | it('Should be able to upload a video again') | |
0e1dc3e7 C |
231 | }) |
232 | ||
1eddc9a7 | 233 | describe('Creating a user', function () { |
ce5496d6 | 234 | |
1eddc9a7 C |
235 | it('Should be able to create a new user', async function () { |
236 | await createUser({ | |
237 | url: server.url, | |
238 | accessToken: accessToken, | |
239 | username: user.username, | |
240 | password: user.password, | |
241 | videoQuota: 2 * 1024 * 1024, | |
242 | adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST | |
243 | }) | |
244 | }) | |
a76138ff | 245 | |
1eddc9a7 C |
246 | it('Should be able to login with this user', async function () { |
247 | accessTokenUser = await userLogin(server, user) | |
248 | }) | |
a76138ff | 249 | |
1eddc9a7 C |
250 | it('Should be able to get user information', async function () { |
251 | const res1 = await getMyUserInformation(server.url, accessTokenUser) | |
252 | const userMe: User = res1.body | |
253 | ||
254 | const res2 = await getUserInformation(server.url, server.accessToken, userMe.id) | |
255 | const userGet: User = res2.body | |
256 | ||
257 | for (const user of [ userMe, userGet ]) { | |
258 | expect(user.username).to.equal('user_1') | |
259 | expect(user.email).to.equal('user_1@example.com') | |
260 | expect(user.nsfwPolicy).to.equal('display') | |
261 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
262 | expect(user.roleLabel).to.equal('User') | |
263 | expect(user.id).to.be.a('number') | |
264 | expect(user.account.displayName).to.equal('user_1') | |
265 | expect(user.account.description).to.be.null | |
266 | } | |
267 | ||
268 | expect(userMe.adminFlags).to.be.undefined | |
269 | expect(userGet.adminFlags).to.equal(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST) | |
270 | }) | |
ce5496d6 C |
271 | }) |
272 | ||
1eddc9a7 | 273 | describe('My videos & quotas', function () { |
11474c3c | 274 | |
1eddc9a7 C |
275 | it('Should be able to upload a video with this user', async function () { |
276 | this.timeout(5000) | |
0e1dc3e7 | 277 | |
1eddc9a7 C |
278 | const videoAttributes = { |
279 | name: 'super user video', | |
280 | fixture: 'video_short.webm' | |
281 | } | |
282 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | |
283 | }) | |
afffe988 | 284 | |
1eddc9a7 C |
285 | it('Should have video quota updated', async function () { |
286 | const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) | |
287 | const data = res.body | |
0e1dc3e7 | 288 | |
1eddc9a7 | 289 | expect(data.videoQuotaUsed).to.equal(218910) |
0e1dc3e7 | 290 | |
1eddc9a7 | 291 | const resUsers = await getUsersList(server.url, server.accessToken) |
0e1dc3e7 | 292 | |
1eddc9a7 C |
293 | const users: User[] = resUsers.body.data |
294 | const tmpUser = users.find(u => u.username === user.username) | |
295 | expect(tmpUser.videoQuotaUsed).to.equal(218910) | |
296 | }) | |
0e1dc3e7 | 297 | |
1eddc9a7 C |
298 | it('Should be able to list my videos', async function () { |
299 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) | |
300 | expect(res.body.total).to.equal(1) | |
0e1dc3e7 | 301 | |
1eddc9a7 C |
302 | const videos = res.body.data |
303 | expect(videos).to.have.lengthOf(1) | |
afffe988 | 304 | |
a18f275d C |
305 | const video: Video = videos[ 0 ] |
306 | expect(video.name).to.equal('super user video') | |
307 | expect(video.thumbnailPath).to.not.be.null | |
308 | expect(video.previewPath).to.not.be.null | |
1eddc9a7 | 309 | }) |
0e1dc3e7 C |
310 | }) |
311 | ||
1eddc9a7 | 312 | describe('Users listing', function () { |
0e1dc3e7 | 313 | |
1eddc9a7 C |
314 | it('Should list all the users', async function () { |
315 | const res = await getUsersList(server.url, server.accessToken) | |
316 | const result = res.body | |
317 | const total = result.total | |
318 | const users = result.data | |
afffe988 | 319 | |
1eddc9a7 C |
320 | expect(total).to.equal(2) |
321 | expect(users).to.be.an('array') | |
322 | expect(users.length).to.equal(2) | |
0e1dc3e7 | 323 | |
1eddc9a7 C |
324 | const user = users[ 0 ] |
325 | expect(user.username).to.equal('user_1') | |
326 | expect(user.email).to.equal('user_1@example.com') | |
327 | expect(user.nsfwPolicy).to.equal('display') | |
0e1dc3e7 | 328 | |
1eddc9a7 C |
329 | const rootUser = users[ 1 ] |
330 | expect(rootUser.username).to.equal('root') | |
48f07b4a | 331 | expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') |
1eddc9a7 | 332 | expect(user.nsfwPolicy).to.equal('display') |
afffe988 | 333 | |
1eddc9a7 C |
334 | userId = user.id |
335 | }) | |
0e1dc3e7 | 336 | |
1eddc9a7 C |
337 | it('Should list only the first user by username asc', async function () { |
338 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') | |
0e1dc3e7 | 339 | |
1eddc9a7 C |
340 | const result = res.body |
341 | const total = result.total | |
342 | const users = result.data | |
a7ba16b6 | 343 | |
1eddc9a7 C |
344 | expect(total).to.equal(2) |
345 | expect(users.length).to.equal(1) | |
afffe988 | 346 | |
1eddc9a7 C |
347 | const user = users[ 0 ] |
348 | expect(user.username).to.equal('root') | |
48f07b4a | 349 | expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') |
1eddc9a7 C |
350 | expect(user.roleLabel).to.equal('Administrator') |
351 | expect(user.nsfwPolicy).to.equal('display') | |
352 | }) | |
0e1dc3e7 | 353 | |
1eddc9a7 C |
354 | it('Should list only the first user by username desc', async function () { |
355 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') | |
356 | const result = res.body | |
357 | const total = result.total | |
358 | const users = result.data | |
24b9417c | 359 | |
1eddc9a7 C |
360 | expect(total).to.equal(2) |
361 | expect(users.length).to.equal(1) | |
24b9417c | 362 | |
1eddc9a7 C |
363 | const user = users[ 0 ] |
364 | expect(user.username).to.equal('user_1') | |
365 | expect(user.email).to.equal('user_1@example.com') | |
366 | expect(user.nsfwPolicy).to.equal('display') | |
367 | }) | |
24b9417c | 368 | |
1eddc9a7 C |
369 | it('Should list only the second user by createdAt desc', async function () { |
370 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') | |
371 | const result = res.body | |
372 | const total = result.total | |
373 | const users = result.data | |
24b9417c | 374 | |
1eddc9a7 | 375 | expect(total).to.equal(2) |
24b9417c C |
376 | expect(users.length).to.equal(1) |
377 | ||
1eddc9a7 C |
378 | const user = users[ 0 ] |
379 | expect(user.username).to.equal('user_1') | |
380 | expect(user.email).to.equal('user_1@example.com') | |
381 | expect(user.nsfwPolicy).to.equal('display') | |
382 | }) | |
24b9417c | 383 | |
1eddc9a7 C |
384 | it('Should list all the users by createdAt asc', async function () { |
385 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') | |
386 | const result = res.body | |
387 | const total = result.total | |
388 | const users = result.data | |
24b9417c | 389 | |
1eddc9a7 | 390 | expect(total).to.equal(2) |
24b9417c C |
391 | expect(users.length).to.equal(2) |
392 | ||
393 | expect(users[ 0 ].username).to.equal('root') | |
48f07b4a | 394 | expect(users[ 0 ].email).to.equal('admin' + server.internalServerNumber + '@example.com') |
1eddc9a7 | 395 | expect(users[ 0 ].nsfwPolicy).to.equal('display') |
24b9417c | 396 | |
1eddc9a7 C |
397 | expect(users[ 1 ].username).to.equal('user_1') |
398 | expect(users[ 1 ].email).to.equal('user_1@example.com') | |
399 | expect(users[ 1 ].nsfwPolicy).to.equal('display') | |
11ba2ab3 | 400 | }) |
0e1dc3e7 | 401 | |
1eddc9a7 C |
402 | it('Should search user by username', async function () { |
403 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') | |
404 | const users = res.body.data as User[] | |
405 | ||
406 | expect(res.body.total).to.equal(1) | |
407 | expect(users.length).to.equal(1) | |
0e1dc3e7 | 408 | |
1eddc9a7 | 409 | expect(users[ 0 ].username).to.equal('root') |
11ba2ab3 | 410 | }) |
0e1dc3e7 | 411 | |
1eddc9a7 C |
412 | it('Should search user by email', async function () { |
413 | { | |
414 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') | |
415 | const users = res.body.data as User[] | |
0e1dc3e7 | 416 | |
1eddc9a7 C |
417 | expect(res.body.total).to.equal(1) |
418 | expect(users.length).to.equal(1) | |
5c98d3bf | 419 | |
1eddc9a7 C |
420 | expect(users[ 0 ].username).to.equal('user_1') |
421 | expect(users[ 0 ].email).to.equal('user_1@example.com') | |
422 | } | |
7efe153b | 423 | |
1eddc9a7 C |
424 | { |
425 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') | |
426 | const users = res.body.data as User[] | |
7efe153b | 427 | |
1eddc9a7 C |
428 | expect(res.body.total).to.equal(2) |
429 | expect(users.length).to.equal(2) | |
7efe153b | 430 | |
1eddc9a7 C |
431 | expect(users[ 0 ].username).to.equal('root') |
432 | expect(users[ 1 ].username).to.equal('user_1') | |
433 | } | |
11ba2ab3 | 434 | }) |
5c98d3bf C |
435 | }) |
436 | ||
1eddc9a7 C |
437 | describe('Update my account', function () { |
438 | it('Should update my password', async function () { | |
439 | await updateMyUser({ | |
440 | url: server.url, | |
441 | accessToken: accessTokenUser, | |
442 | currentPassword: 'super password', | |
443 | newPassword: 'new password' | |
444 | }) | |
445 | user.password = 'new password' | |
c5911fd3 | 446 | |
1eddc9a7 | 447 | await userLogin(server, user, 200) |
c5911fd3 C |
448 | }) |
449 | ||
1eddc9a7 C |
450 | it('Should be able to change the NSFW display attribute', async function () { |
451 | await updateMyUser({ | |
452 | url: server.url, | |
453 | accessToken: accessTokenUser, | |
454 | nsfwPolicy: 'do_not_list' | |
455 | }) | |
456 | ||
457 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
458 | const user = res.body | |
459 | ||
460 | expect(user.username).to.equal('user_1') | |
461 | expect(user.email).to.equal('user_1@example.com') | |
462 | expect(user.nsfwPolicy).to.equal('do_not_list') | |
463 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
464 | expect(user.id).to.be.a('number') | |
465 | expect(user.account.displayName).to.equal('user_1') | |
466 | expect(user.account.description).to.be.null | |
467 | }) | |
c5911fd3 | 468 | |
1eddc9a7 C |
469 | it('Should be able to change the autoPlayVideo attribute', async function () { |
470 | await updateMyUser({ | |
471 | url: server.url, | |
472 | accessToken: accessTokenUser, | |
473 | autoPlayVideo: false | |
474 | }) | |
c5911fd3 | 475 | |
1eddc9a7 C |
476 | const res = await getMyUserInformation(server.url, accessTokenUser) |
477 | const user = res.body | |
478 | ||
479 | expect(user.autoPlayVideo).to.be.false | |
ed56ad11 C |
480 | }) |
481 | ||
675a8fc7 | 482 | it('Should be able to change the email attribute', async function () { |
1eddc9a7 C |
483 | await updateMyUser({ |
484 | url: server.url, | |
485 | accessToken: accessTokenUser, | |
675a8fc7 | 486 | currentPassword: 'new password', |
1eddc9a7 C |
487 | email: 'updated@example.com' |
488 | }) | |
489 | ||
490 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
491 | const user = res.body | |
492 | ||
493 | expect(user.username).to.equal('user_1') | |
494 | expect(user.email).to.equal('updated@example.com') | |
495 | expect(user.nsfwPolicy).to.equal('do_not_list') | |
496 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
497 | expect(user.id).to.be.a('number') | |
498 | expect(user.account.displayName).to.equal('user_1') | |
499 | expect(user.account.description).to.be.null | |
500 | }) | |
ed56ad11 | 501 | |
1eddc9a7 C |
502 | it('Should be able to update my avatar', async function () { |
503 | const fixture = 'avatar.png' | |
ed56ad11 | 504 | |
1eddc9a7 C |
505 | await updateMyAvatar({ |
506 | url: server.url, | |
507 | accessToken: accessTokenUser, | |
508 | fixture | |
509 | }) | |
2422c46b | 510 | |
1eddc9a7 C |
511 | const res = await getMyUserInformation(server.url, accessTokenUser) |
512 | const user = res.body | |
2422c46b | 513 | |
1eddc9a7 C |
514 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png') |
515 | }) | |
516 | ||
517 | it('Should be able to update my display name', async function () { | |
518 | await updateMyUser({ | |
519 | url: server.url, | |
520 | accessToken: accessTokenUser, | |
521 | displayName: 'new display name' | |
522 | }) | |
523 | ||
524 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
525 | const user = res.body | |
526 | ||
527 | expect(user.username).to.equal('user_1') | |
528 | expect(user.email).to.equal('updated@example.com') | |
529 | expect(user.nsfwPolicy).to.equal('do_not_list') | |
530 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
531 | expect(user.id).to.be.a('number') | |
532 | expect(user.account.displayName).to.equal('new display name') | |
533 | expect(user.account.description).to.be.null | |
534 | }) | |
2422c46b | 535 | |
1eddc9a7 C |
536 | it('Should be able to update my description', async function () { |
537 | await updateMyUser({ | |
538 | url: server.url, | |
539 | accessToken: accessTokenUser, | |
540 | description: 'my super description updated' | |
541 | }) | |
542 | ||
543 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
544 | const user = res.body | |
545 | ||
546 | expect(user.username).to.equal('user_1') | |
547 | expect(user.email).to.equal('updated@example.com') | |
548 | expect(user.nsfwPolicy).to.equal('do_not_list') | |
549 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
550 | expect(user.id).to.be.a('number') | |
551 | expect(user.account.displayName).to.equal('new display name') | |
552 | expect(user.account.description).to.equal('my super description updated') | |
553 | }) | |
0e1dc3e7 C |
554 | }) |
555 | ||
1eddc9a7 C |
556 | describe('Updating another user', function () { |
557 | ||
558 | it('Should be able to update another user', async function () { | |
559 | await updateUser({ | |
560 | url: server.url, | |
561 | userId, | |
562 | accessToken, | |
563 | email: 'updated2@example.com', | |
564 | emailVerified: true, | |
565 | videoQuota: 42, | |
566 | role: UserRole.MODERATOR, | |
567 | adminFlags: UserAdminFlag.NONE | |
568 | }) | |
569 | ||
570 | const res = await getUserInformation(server.url, accessToken, userId) | |
571 | const user = res.body | |
572 | ||
573 | expect(user.username).to.equal('user_1') | |
574 | expect(user.email).to.equal('updated2@example.com') | |
575 | expect(user.emailVerified).to.be.true | |
576 | expect(user.nsfwPolicy).to.equal('do_not_list') | |
577 | expect(user.videoQuota).to.equal(42) | |
578 | expect(user.roleLabel).to.equal('Moderator') | |
579 | expect(user.id).to.be.a('number') | |
580 | expect(user.adminFlags).to.equal(UserAdminFlag.NONE) | |
581 | }) | |
f8b8c36b | 582 | |
1eddc9a7 C |
583 | it('Should have removed the user token', async function () { |
584 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) | |
f8b8c36b | 585 | |
1eddc9a7 | 586 | accessTokenUser = await userLogin(server, user) |
b426edd4 C |
587 | }) |
588 | ||
1eddc9a7 C |
589 | it('Should be able to update another user password', async function () { |
590 | await updateUser({ | |
591 | url: server.url, | |
592 | userId, | |
593 | accessToken, | |
594 | password: 'password updated' | |
595 | }) | |
b426edd4 | 596 | |
1eddc9a7 | 597 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) |
b426edd4 | 598 | |
1eddc9a7 | 599 | await userLogin(server, user, 400) |
b426edd4 | 600 | |
1eddc9a7 C |
601 | user.password = 'password updated' |
602 | accessTokenUser = await userLogin(server, user) | |
603 | }) | |
757f0da3 C |
604 | }) |
605 | ||
1eddc9a7 C |
606 | describe('Video blacklists', function () { |
607 | it('Should be able to list video blacklist by a moderator', async function () { | |
608 | await getBlacklistedVideosList({ url: server.url, token: accessTokenUser }) | |
609 | }) | |
0e1dc3e7 C |
610 | }) |
611 | ||
1eddc9a7 C |
612 | describe('Remove a user', function () { |
613 | it('Should be able to remove this user', async function () { | |
614 | await removeUser(server.url, userId, accessToken) | |
615 | }) | |
0e1dc3e7 | 616 | |
1eddc9a7 C |
617 | it('Should not be able to login with this user', async function () { |
618 | await userLogin(server, user, 400) | |
619 | }) | |
0e1dc3e7 | 620 | |
1eddc9a7 C |
621 | it('Should not have videos of this user', async function () { |
622 | const res = await getVideosList(server.url) | |
0e1dc3e7 | 623 | |
1eddc9a7 | 624 | expect(res.body.total).to.equal(1) |
0e1dc3e7 | 625 | |
1eddc9a7 C |
626 | const video = res.body.data[ 0 ] |
627 | expect(video.account.name).to.equal('root') | |
628 | }) | |
0e1dc3e7 C |
629 | }) |
630 | ||
1eddc9a7 C |
631 | describe('Registering a new user', function () { |
632 | it('Should register a new user', async function () { | |
1f20622f | 633 | const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } |
e590b4a5 C |
634 | const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } |
635 | ||
636 | await registerUserWithChannel({ url: server.url, user, channel }) | |
1eddc9a7 | 637 | }) |
0e1dc3e7 | 638 | |
1eddc9a7 C |
639 | it('Should be able to login with this registered user', async function () { |
640 | const user15 = { | |
641 | username: 'user_15', | |
642 | password: 'my super password' | |
643 | } | |
5c98d3bf | 644 | |
1eddc9a7 C |
645 | accessToken = await userLogin(server, user15) |
646 | }) | |
5c98d3bf | 647 | |
1f20622f C |
648 | it('Should have the correct display name', async function () { |
649 | const res = await getMyUserInformation(server.url, accessToken) | |
650 | const user: User = res.body | |
651 | ||
652 | expect(user.account.displayName).to.equal('super user 15') | |
653 | }) | |
654 | ||
1eddc9a7 C |
655 | it('Should have the correct video quota', async function () { |
656 | const res = await getMyUserInformation(server.url, accessToken) | |
657 | const user = res.body | |
0e1dc3e7 | 658 | |
1eddc9a7 C |
659 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) |
660 | }) | |
92b9d60c | 661 | |
e590b4a5 C |
662 | it('Should have created the channel', async function () { |
663 | const res = await getVideoChannel(server.url, 'my_user_15_channel') | |
664 | ||
665 | expect(res.body.displayName).to.equal('my channel rocks') | |
666 | }) | |
667 | ||
1eddc9a7 C |
668 | it('Should remove me', async function () { |
669 | { | |
670 | const res = await getUsersList(server.url, server.accessToken) | |
671 | expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined | |
672 | } | |
92b9d60c | 673 | |
1eddc9a7 C |
674 | await deleteMe(server.url, accessToken) |
675 | ||
676 | { | |
677 | const res = await getUsersList(server.url, server.accessToken) | |
678 | expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined | |
679 | } | |
680 | }) | |
92b9d60c C |
681 | }) |
682 | ||
1eddc9a7 C |
683 | describe('User blocking', function () { |
684 | it('Should block and unblock a user', async function () { | |
685 | const user16 = { | |
686 | username: 'user_16', | |
687 | password: 'my super password' | |
688 | } | |
689 | const resUser = await createUser({ | |
690 | url: server.url, | |
691 | accessToken: server.accessToken, | |
692 | username: user16.username, | |
693 | password: user16.password | |
694 | }) | |
695 | const user16Id = resUser.body.user.id | |
e6921918 | 696 | |
1eddc9a7 | 697 | accessToken = await userLogin(server, user16) |
e6921918 | 698 | |
1eddc9a7 C |
699 | await getMyUserInformation(server.url, accessToken, 200) |
700 | await blockUser(server.url, user16Id, server.accessToken) | |
e6921918 | 701 | |
1eddc9a7 C |
702 | await getMyUserInformation(server.url, accessToken, 401) |
703 | await userLogin(server, user16, 400) | |
e6921918 | 704 | |
1eddc9a7 C |
705 | await unblockUser(server.url, user16Id, server.accessToken) |
706 | accessToken = await userLogin(server, user16) | |
707 | await getMyUserInformation(server.url, accessToken, 200) | |
708 | }) | |
e6921918 C |
709 | }) |
710 | ||
7c3b7976 C |
711 | after(async function () { |
712 | await cleanupTests([ server ]) | |
0e1dc3e7 C |
713 | }) |
714 | }) |