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