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