]>
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, |
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) | |
254 | const userMe: User = res1.body | |
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) | |
272 | }) | |
ce5496d6 C |
273 | }) |
274 | ||
1eddc9a7 | 275 | describe('My videos & quotas', function () { |
11474c3c | 276 | |
1eddc9a7 C |
277 | it('Should be able to upload a video with this user', async function () { |
278 | this.timeout(5000) | |
0e1dc3e7 | 279 | |
1eddc9a7 C |
280 | const videoAttributes = { |
281 | name: 'super user video', | |
282 | fixture: 'video_short.webm' | |
283 | } | |
284 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | |
285 | }) | |
afffe988 | 286 | |
1eddc9a7 C |
287 | it('Should have video quota updated', async function () { |
288 | const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) | |
289 | const data = res.body | |
0e1dc3e7 | 290 | |
1eddc9a7 | 291 | expect(data.videoQuotaUsed).to.equal(218910) |
0e1dc3e7 | 292 | |
1eddc9a7 | 293 | const resUsers = await getUsersList(server.url, server.accessToken) |
0e1dc3e7 | 294 | |
1eddc9a7 C |
295 | const users: User[] = resUsers.body.data |
296 | const tmpUser = users.find(u => u.username === user.username) | |
297 | expect(tmpUser.videoQuotaUsed).to.equal(218910) | |
298 | }) | |
0e1dc3e7 | 299 | |
1eddc9a7 C |
300 | it('Should be able to list my videos', async function () { |
301 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) | |
302 | expect(res.body.total).to.equal(1) | |
0e1dc3e7 | 303 | |
1eddc9a7 C |
304 | const videos = res.body.data |
305 | expect(videos).to.have.lengthOf(1) | |
afffe988 | 306 | |
a18f275d C |
307 | const video: Video = videos[ 0 ] |
308 | expect(video.name).to.equal('super user video') | |
309 | expect(video.thumbnailPath).to.not.be.null | |
310 | expect(video.previewPath).to.not.be.null | |
1eddc9a7 | 311 | }) |
0e1dc3e7 C |
312 | }) |
313 | ||
1eddc9a7 | 314 | describe('Users listing', function () { |
0e1dc3e7 | 315 | |
1eddc9a7 C |
316 | it('Should list all the users', async function () { |
317 | const res = await getUsersList(server.url, server.accessToken) | |
318 | const result = res.body | |
319 | const total = result.total | |
320 | const users = result.data | |
afffe988 | 321 | |
1eddc9a7 C |
322 | expect(total).to.equal(2) |
323 | expect(users).to.be.an('array') | |
324 | expect(users.length).to.equal(2) | |
0e1dc3e7 | 325 | |
1eddc9a7 C |
326 | const user = users[ 0 ] |
327 | expect(user.username).to.equal('user_1') | |
328 | expect(user.email).to.equal('user_1@example.com') | |
329 | expect(user.nsfwPolicy).to.equal('display') | |
0e1dc3e7 | 330 | |
1eddc9a7 C |
331 | const rootUser = users[ 1 ] |
332 | expect(rootUser.username).to.equal('root') | |
48f07b4a | 333 | expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') |
1eddc9a7 | 334 | expect(user.nsfwPolicy).to.equal('display') |
afffe988 | 335 | |
1eddc9a7 C |
336 | userId = user.id |
337 | }) | |
0e1dc3e7 | 338 | |
1eddc9a7 C |
339 | it('Should list only the first user by username asc', async function () { |
340 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') | |
0e1dc3e7 | 341 | |
1eddc9a7 C |
342 | const result = res.body |
343 | const total = result.total | |
344 | const users = result.data | |
a7ba16b6 | 345 | |
1eddc9a7 C |
346 | expect(total).to.equal(2) |
347 | expect(users.length).to.equal(1) | |
afffe988 | 348 | |
1eddc9a7 C |
349 | const user = users[ 0 ] |
350 | expect(user.username).to.equal('root') | |
48f07b4a | 351 | expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') |
1eddc9a7 C |
352 | expect(user.roleLabel).to.equal('Administrator') |
353 | expect(user.nsfwPolicy).to.equal('display') | |
354 | }) | |
0e1dc3e7 | 355 | |
1eddc9a7 C |
356 | it('Should list only the first user by username desc', async function () { |
357 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') | |
358 | const result = res.body | |
359 | const total = result.total | |
360 | const users = result.data | |
24b9417c | 361 | |
1eddc9a7 C |
362 | expect(total).to.equal(2) |
363 | expect(users.length).to.equal(1) | |
24b9417c | 364 | |
1eddc9a7 C |
365 | const user = users[ 0 ] |
366 | expect(user.username).to.equal('user_1') | |
367 | expect(user.email).to.equal('user_1@example.com') | |
368 | expect(user.nsfwPolicy).to.equal('display') | |
369 | }) | |
24b9417c | 370 | |
1eddc9a7 C |
371 | it('Should list only the second user by createdAt desc', async function () { |
372 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') | |
373 | const result = res.body | |
374 | const total = result.total | |
375 | const users = result.data | |
24b9417c | 376 | |
1eddc9a7 | 377 | expect(total).to.equal(2) |
24b9417c C |
378 | expect(users.length).to.equal(1) |
379 | ||
1eddc9a7 C |
380 | const user = users[ 0 ] |
381 | expect(user.username).to.equal('user_1') | |
382 | expect(user.email).to.equal('user_1@example.com') | |
383 | expect(user.nsfwPolicy).to.equal('display') | |
384 | }) | |
24b9417c | 385 | |
1eddc9a7 C |
386 | it('Should list all the users by createdAt asc', async function () { |
387 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') | |
388 | const result = res.body | |
389 | const total = result.total | |
390 | const users = result.data | |
24b9417c | 391 | |
1eddc9a7 | 392 | expect(total).to.equal(2) |
24b9417c C |
393 | expect(users.length).to.equal(2) |
394 | ||
395 | expect(users[ 0 ].username).to.equal('root') | |
48f07b4a | 396 | expect(users[ 0 ].email).to.equal('admin' + server.internalServerNumber + '@example.com') |
1eddc9a7 | 397 | expect(users[ 0 ].nsfwPolicy).to.equal('display') |
24b9417c | 398 | |
1eddc9a7 C |
399 | expect(users[ 1 ].username).to.equal('user_1') |
400 | expect(users[ 1 ].email).to.equal('user_1@example.com') | |
401 | expect(users[ 1 ].nsfwPolicy).to.equal('display') | |
11ba2ab3 | 402 | }) |
0e1dc3e7 | 403 | |
1eddc9a7 C |
404 | it('Should search user by username', async function () { |
405 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') | |
406 | const users = res.body.data as User[] | |
407 | ||
408 | expect(res.body.total).to.equal(1) | |
409 | expect(users.length).to.equal(1) | |
0e1dc3e7 | 410 | |
1eddc9a7 | 411 | expect(users[ 0 ].username).to.equal('root') |
11ba2ab3 | 412 | }) |
0e1dc3e7 | 413 | |
1eddc9a7 C |
414 | it('Should search user by email', async function () { |
415 | { | |
416 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') | |
417 | const users = res.body.data as User[] | |
0e1dc3e7 | 418 | |
1eddc9a7 C |
419 | expect(res.body.total).to.equal(1) |
420 | expect(users.length).to.equal(1) | |
5c98d3bf | 421 | |
1eddc9a7 C |
422 | expect(users[ 0 ].username).to.equal('user_1') |
423 | expect(users[ 0 ].email).to.equal('user_1@example.com') | |
424 | } | |
7efe153b | 425 | |
1eddc9a7 C |
426 | { |
427 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') | |
428 | const users = res.body.data as User[] | |
7efe153b | 429 | |
1eddc9a7 C |
430 | expect(res.body.total).to.equal(2) |
431 | expect(users.length).to.equal(2) | |
7efe153b | 432 | |
1eddc9a7 C |
433 | expect(users[ 0 ].username).to.equal('root') |
434 | expect(users[ 1 ].username).to.equal('user_1') | |
435 | } | |
11ba2ab3 | 436 | }) |
5c98d3bf C |
437 | }) |
438 | ||
1eddc9a7 C |
439 | describe('Update my account', function () { |
440 | it('Should update my password', async function () { | |
441 | await updateMyUser({ | |
442 | url: server.url, | |
443 | accessToken: accessTokenUser, | |
444 | currentPassword: 'super password', | |
43d0ea7f | 445 | password: 'new password' |
1eddc9a7 C |
446 | }) |
447 | user.password = 'new password' | |
c5911fd3 | 448 | |
1eddc9a7 | 449 | await userLogin(server, user, 200) |
c5911fd3 C |
450 | }) |
451 | ||
1eddc9a7 C |
452 | it('Should be able to change the NSFW display attribute', async function () { |
453 | await updateMyUser({ | |
454 | url: server.url, | |
455 | accessToken: accessTokenUser, | |
456 | nsfwPolicy: 'do_not_list' | |
457 | }) | |
458 | ||
459 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
460 | const user = res.body | |
461 | ||
462 | expect(user.username).to.equal('user_1') | |
463 | expect(user.email).to.equal('user_1@example.com') | |
464 | expect(user.nsfwPolicy).to.equal('do_not_list') | |
465 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
466 | expect(user.id).to.be.a('number') | |
467 | expect(user.account.displayName).to.equal('user_1') | |
468 | expect(user.account.description).to.be.null | |
469 | }) | |
c5911fd3 | 470 | |
1eddc9a7 C |
471 | it('Should be able to change the autoPlayVideo attribute', async function () { |
472 | await updateMyUser({ | |
473 | url: server.url, | |
474 | accessToken: accessTokenUser, | |
475 | autoPlayVideo: false | |
476 | }) | |
c5911fd3 | 477 | |
1eddc9a7 C |
478 | const res = await getMyUserInformation(server.url, accessTokenUser) |
479 | const user = res.body | |
480 | ||
481 | expect(user.autoPlayVideo).to.be.false | |
ed56ad11 C |
482 | }) |
483 | ||
675a8fc7 | 484 | it('Should be able to change the email attribute', async function () { |
1eddc9a7 C |
485 | await updateMyUser({ |
486 | url: server.url, | |
487 | accessToken: accessTokenUser, | |
675a8fc7 | 488 | currentPassword: 'new password', |
1eddc9a7 C |
489 | email: 'updated@example.com' |
490 | }) | |
491 | ||
492 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
493 | const user = res.body | |
494 | ||
495 | expect(user.username).to.equal('user_1') | |
496 | expect(user.email).to.equal('updated@example.com') | |
497 | expect(user.nsfwPolicy).to.equal('do_not_list') | |
498 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
499 | expect(user.id).to.be.a('number') | |
500 | expect(user.account.displayName).to.equal('user_1') | |
501 | expect(user.account.description).to.be.null | |
502 | }) | |
ed56ad11 | 503 | |
1eddc9a7 C |
504 | it('Should be able to update my avatar', async function () { |
505 | const fixture = 'avatar.png' | |
ed56ad11 | 506 | |
1eddc9a7 C |
507 | await updateMyAvatar({ |
508 | url: server.url, | |
509 | accessToken: accessTokenUser, | |
510 | fixture | |
511 | }) | |
2422c46b | 512 | |
1eddc9a7 C |
513 | const res = await getMyUserInformation(server.url, accessTokenUser) |
514 | const user = res.body | |
2422c46b | 515 | |
1eddc9a7 C |
516 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png') |
517 | }) | |
518 | ||
519 | it('Should be able to update my display name', async function () { | |
520 | await updateMyUser({ | |
521 | url: server.url, | |
522 | accessToken: accessTokenUser, | |
523 | displayName: 'new display name' | |
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('new display name') | |
535 | expect(user.account.description).to.be.null | |
536 | }) | |
2422c46b | 537 | |
1eddc9a7 C |
538 | it('Should be able to update my description', async function () { |
539 | await updateMyUser({ | |
540 | url: server.url, | |
541 | accessToken: accessTokenUser, | |
542 | description: 'my super description updated' | |
543 | }) | |
544 | ||
545 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
43d0ea7f | 546 | const user: User = res.body |
1eddc9a7 C |
547 | |
548 | expect(user.username).to.equal('user_1') | |
549 | expect(user.email).to.equal('updated@example.com') | |
550 | expect(user.nsfwPolicy).to.equal('do_not_list') | |
551 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
552 | expect(user.id).to.be.a('number') | |
553 | expect(user.account.displayName).to.equal('new display name') | |
554 | expect(user.account.description).to.equal('my super description updated') | |
43d0ea7f C |
555 | expect(user.noWelcomeModal).to.be.false |
556 | expect(user.noInstanceConfigWarningModal).to.be.false | |
1eddc9a7 | 557 | }) |
9b474844 C |
558 | |
559 | it('Should be able to update my theme', async function () { | |
560 | for (const theme of [ 'background-red', 'default', 'instance-default' ]) { | |
561 | await updateMyUser({ | |
562 | url: server.url, | |
563 | accessToken: accessTokenUser, | |
564 | theme | |
565 | }) | |
566 | ||
567 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
568 | const body: User = res.body | |
569 | ||
570 | expect(body.theme).to.equal(theme) | |
571 | } | |
572 | }) | |
43d0ea7f C |
573 | |
574 | it('Should be able to update my modal preferences', async function () { | |
575 | await updateMyUser({ | |
576 | url: server.url, | |
577 | accessToken: accessTokenUser, | |
578 | noInstanceConfigWarningModal: true, | |
579 | noWelcomeModal: true | |
580 | }) | |
581 | ||
582 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
583 | const user: User = res.body | |
584 | ||
585 | expect(user.noWelcomeModal).to.be.true | |
586 | expect(user.noInstanceConfigWarningModal).to.be.true | |
587 | }) | |
0e1dc3e7 C |
588 | }) |
589 | ||
1eddc9a7 C |
590 | describe('Updating another user', function () { |
591 | ||
592 | it('Should be able to update another user', async function () { | |
593 | await updateUser({ | |
594 | url: server.url, | |
595 | userId, | |
596 | accessToken, | |
597 | email: 'updated2@example.com', | |
598 | emailVerified: true, | |
599 | videoQuota: 42, | |
600 | role: UserRole.MODERATOR, | |
601 | adminFlags: UserAdminFlag.NONE | |
602 | }) | |
603 | ||
604 | const res = await getUserInformation(server.url, accessToken, userId) | |
605 | const user = res.body | |
606 | ||
607 | expect(user.username).to.equal('user_1') | |
608 | expect(user.email).to.equal('updated2@example.com') | |
609 | expect(user.emailVerified).to.be.true | |
610 | expect(user.nsfwPolicy).to.equal('do_not_list') | |
611 | expect(user.videoQuota).to.equal(42) | |
612 | expect(user.roleLabel).to.equal('Moderator') | |
613 | expect(user.id).to.be.a('number') | |
614 | expect(user.adminFlags).to.equal(UserAdminFlag.NONE) | |
615 | }) | |
f8b8c36b | 616 | |
1eddc9a7 C |
617 | it('Should have removed the user token', async function () { |
618 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) | |
f8b8c36b | 619 | |
1eddc9a7 | 620 | accessTokenUser = await userLogin(server, user) |
b426edd4 C |
621 | }) |
622 | ||
1eddc9a7 C |
623 | it('Should be able to update another user password', async function () { |
624 | await updateUser({ | |
625 | url: server.url, | |
626 | userId, | |
627 | accessToken, | |
628 | password: 'password updated' | |
629 | }) | |
b426edd4 | 630 | |
1eddc9a7 | 631 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) |
b426edd4 | 632 | |
1eddc9a7 | 633 | await userLogin(server, user, 400) |
b426edd4 | 634 | |
1eddc9a7 C |
635 | user.password = 'password updated' |
636 | accessTokenUser = await userLogin(server, user) | |
637 | }) | |
757f0da3 C |
638 | }) |
639 | ||
1eddc9a7 C |
640 | describe('Video blacklists', function () { |
641 | it('Should be able to list video blacklist by a moderator', async function () { | |
642 | await getBlacklistedVideosList({ url: server.url, token: accessTokenUser }) | |
643 | }) | |
0e1dc3e7 C |
644 | }) |
645 | ||
1eddc9a7 C |
646 | describe('Remove a user', function () { |
647 | it('Should be able to remove this user', async function () { | |
648 | await removeUser(server.url, userId, accessToken) | |
649 | }) | |
0e1dc3e7 | 650 | |
1eddc9a7 C |
651 | it('Should not be able to login with this user', async function () { |
652 | await userLogin(server, user, 400) | |
653 | }) | |
0e1dc3e7 | 654 | |
1eddc9a7 C |
655 | it('Should not have videos of this user', async function () { |
656 | const res = await getVideosList(server.url) | |
0e1dc3e7 | 657 | |
1eddc9a7 | 658 | expect(res.body.total).to.equal(1) |
0e1dc3e7 | 659 | |
1eddc9a7 C |
660 | const video = res.body.data[ 0 ] |
661 | expect(video.account.name).to.equal('root') | |
662 | }) | |
0e1dc3e7 C |
663 | }) |
664 | ||
1eddc9a7 C |
665 | describe('Registering a new user', function () { |
666 | it('Should register a new user', async function () { | |
1f20622f | 667 | const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } |
e590b4a5 C |
668 | const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } |
669 | ||
670 | await registerUserWithChannel({ url: server.url, user, channel }) | |
1eddc9a7 | 671 | }) |
0e1dc3e7 | 672 | |
1eddc9a7 C |
673 | it('Should be able to login with this registered user', async function () { |
674 | const user15 = { | |
675 | username: 'user_15', | |
676 | password: 'my super password' | |
677 | } | |
5c98d3bf | 678 | |
1eddc9a7 C |
679 | accessToken = await userLogin(server, user15) |
680 | }) | |
5c98d3bf | 681 | |
1f20622f C |
682 | it('Should have the correct display name', async function () { |
683 | const res = await getMyUserInformation(server.url, accessToken) | |
684 | const user: User = res.body | |
685 | ||
686 | expect(user.account.displayName).to.equal('super user 15') | |
687 | }) | |
688 | ||
1eddc9a7 C |
689 | it('Should have the correct video quota', async function () { |
690 | const res = await getMyUserInformation(server.url, accessToken) | |
691 | const user = res.body | |
0e1dc3e7 | 692 | |
1eddc9a7 C |
693 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) |
694 | }) | |
92b9d60c | 695 | |
e590b4a5 C |
696 | it('Should have created the channel', async function () { |
697 | const res = await getVideoChannel(server.url, 'my_user_15_channel') | |
698 | ||
699 | expect(res.body.displayName).to.equal('my channel rocks') | |
700 | }) | |
701 | ||
1eddc9a7 C |
702 | it('Should remove me', async function () { |
703 | { | |
704 | const res = await getUsersList(server.url, server.accessToken) | |
705 | expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined | |
706 | } | |
92b9d60c | 707 | |
1eddc9a7 C |
708 | await deleteMe(server.url, accessToken) |
709 | ||
710 | { | |
711 | const res = await getUsersList(server.url, server.accessToken) | |
712 | expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined | |
713 | } | |
714 | }) | |
92b9d60c C |
715 | }) |
716 | ||
1eddc9a7 C |
717 | describe('User blocking', function () { |
718 | it('Should block and unblock a user', async function () { | |
719 | const user16 = { | |
720 | username: 'user_16', | |
721 | password: 'my super password' | |
722 | } | |
723 | const resUser = await createUser({ | |
724 | url: server.url, | |
725 | accessToken: server.accessToken, | |
726 | username: user16.username, | |
727 | password: user16.password | |
728 | }) | |
729 | const user16Id = resUser.body.user.id | |
e6921918 | 730 | |
1eddc9a7 | 731 | accessToken = await userLogin(server, user16) |
e6921918 | 732 | |
1eddc9a7 C |
733 | await getMyUserInformation(server.url, accessToken, 200) |
734 | await blockUser(server.url, user16Id, server.accessToken) | |
e6921918 | 735 | |
1eddc9a7 C |
736 | await getMyUserInformation(server.url, accessToken, 401) |
737 | await userLogin(server, user16, 400) | |
e6921918 | 738 | |
1eddc9a7 C |
739 | await unblockUser(server.url, user16Id, server.accessToken) |
740 | accessToken = await userLogin(server, user16) | |
741 | await getMyUserInformation(server.url, accessToken, 200) | |
742 | }) | |
e6921918 C |
743 | }) |
744 | ||
7c3b7976 C |
745 | after(async function () { |
746 | await cleanupTests([ server ]) | |
0e1dc3e7 C |
747 | }) |
748 | }) |