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