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