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