]>
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, |
0c1a77e9 | 14 | follow, |
c100a614 | 15 | getAccountRatings, |
a890d1e0 | 16 | getBlacklistedVideosList, |
e1c55031 | 17 | getCustomConfig, |
a890d1e0 C |
18 | getMyUserInformation, |
19 | getMyUserVideoQuotaUsed, | |
20 | getMyUserVideoRating, | |
0c1a77e9 | 21 | getMyVideos, |
a890d1e0 C |
22 | getUserInformation, |
23 | getUsersList, | |
24 | getUsersListPaginationAndSort, | |
1f20622f | 25 | getVideoChannel, |
a1587156 C |
26 | getVideosList, |
27 | installPlugin, | |
f43db2f4 | 28 | killallServers, |
a890d1e0 | 29 | login, |
0c1a77e9 | 30 | logout, |
a890d1e0 C |
31 | makePutBodyRequest, |
32 | rateVideo, | |
0c1a77e9 | 33 | refreshToken, |
1f20622f | 34 | registerUserWithChannel, |
a890d1e0 C |
35 | removeUser, |
36 | removeVideo, | |
f43db2f4 | 37 | reRunServer, |
a890d1e0 | 38 | ServerInfo, |
0c1a77e9 | 39 | setAccessTokensToServers, |
f43db2f4 | 40 | setTokenField, |
a890d1e0 C |
41 | testImage, |
42 | unblockUser, | |
e1c55031 | 43 | updateCustomSubConfig, |
a890d1e0 C |
44 | updateMyAvatar, |
45 | updateMyUser, | |
46 | updateUser, | |
47 | uploadVideo, | |
76314386 | 48 | userLogin, |
e1c55031 | 49 | waitJobs |
0c1a77e9 C |
50 | } from '@shared/extra-utils' |
51 | import { AbuseState, CustomConfig, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' | |
0e1dc3e7 | 52 | |
afffe988 C |
53 | const expect = chai.expect |
54 | ||
0e1dc3e7 C |
55 | describe('Test users', function () { |
56 | let server: ServerInfo | |
57 | let accessToken: string | |
58 | let accessTokenUser: string | |
59 | let videoId: number | |
60 | let userId: number | |
f8b8c36b C |
61 | const user = { |
62 | username: 'user_1', | |
63 | password: 'super password' | |
64 | } | |
0e1dc3e7 C |
65 | |
66 | before(async function () { | |
e212f887 | 67 | this.timeout(30000) |
e1c55031 C |
68 | |
69 | server = await flushAndRunServer(1, { | |
70 | rates_limit: { | |
71 | login: { | |
72 | max: 30 | |
73 | } | |
74 | } | |
75 | }) | |
86d13ec2 C |
76 | |
77 | await setAccessTokensToServers([ server ]) | |
9b474844 C |
78 | |
79 | await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' }) | |
0e1dc3e7 C |
80 | }) |
81 | ||
1eddc9a7 C |
82 | describe('OAuth client', function () { |
83 | it('Should create a new client') | |
0e1dc3e7 | 84 | |
1eddc9a7 | 85 | it('Should return the first client') |
0e1dc3e7 | 86 | |
1eddc9a7 | 87 | it('Should remove the last client') |
0e1dc3e7 | 88 | |
1eddc9a7 C |
89 | it('Should not login with an invalid client id', async function () { |
90 | const client = { id: 'client', secret: server.client.secret } | |
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 | 98 | |
1eddc9a7 C |
99 | it('Should not login with an invalid client secret', async function () { |
100 | const client = { id: server.client.id, secret: 'coucou' } | |
2d53be02 | 101 | const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) |
0e1dc3e7 | 102 | |
81628e50 | 103 | expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) |
3866ea02 RK |
104 | expect(res.body.error).to.contain('client is invalid') |
105 | expect(res.body.type.startsWith('https://')).to.be.true | |
81628e50 | 106 | expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) |
1eddc9a7 | 107 | }) |
0e1dc3e7 C |
108 | }) |
109 | ||
1eddc9a7 | 110 | describe('Login', function () { |
0e1dc3e7 | 111 | |
1eddc9a7 C |
112 | it('Should not login with an invalid username', async function () { |
113 | const user = { username: 'captain crochet', password: server.user.password } | |
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 login with an invalid password', async function () { |
123 | const user = { username: server.user.username, password: 'mew_three' } | |
2d53be02 | 124 | const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) |
0e1dc3e7 | 125 | |
81628e50 | 126 | expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) |
3866ea02 RK |
127 | expect(res.body.error).to.contain('credentials are invalid') |
128 | expect(res.body.type.startsWith('https://')).to.be.true | |
81628e50 | 129 | expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) |
1eddc9a7 | 130 | }) |
0e1dc3e7 | 131 | |
1eddc9a7 C |
132 | it('Should not be able to upload a video', async function () { |
133 | accessToken = 'my_super_token' | |
0e1dc3e7 | 134 | |
1eddc9a7 | 135 | const videoAttributes = {} |
2d53be02 | 136 | await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401) |
1eddc9a7 | 137 | }) |
0e1dc3e7 | 138 | |
1eddc9a7 C |
139 | it('Should not be able to follow', async function () { |
140 | accessToken = 'my_super_token' | |
2d53be02 | 141 | await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401) |
1eddc9a7 | 142 | }) |
0e1dc3e7 | 143 | |
1eddc9a7 | 144 | it('Should not be able to unfollow') |
0e1dc3e7 | 145 | |
1eddc9a7 | 146 | it('Should be able to login', async function () { |
2d53be02 | 147 | const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200) |
0e1dc3e7 | 148 | |
1eddc9a7 C |
149 | accessToken = res.body.access_token |
150 | }) | |
50b4dcce NB |
151 | |
152 | it('Should be able to login with an insensitive username', async function () { | |
153 | const user = { username: 'RoOt', password: server.user.password } | |
2d53be02 | 154 | await login(server.url, server.client, user, HttpStatusCode.OK_200) |
50b4dcce NB |
155 | |
156 | const user2 = { username: 'rOoT', password: server.user.password } | |
2d53be02 | 157 | await login(server.url, server.client, user2, HttpStatusCode.OK_200) |
50b4dcce NB |
158 | |
159 | const user3 = { username: 'ROOt', password: server.user.password } | |
2d53be02 | 160 | await login(server.url, server.client, user3, HttpStatusCode.OK_200) |
50b4dcce | 161 | }) |
0e1dc3e7 C |
162 | }) |
163 | ||
1eddc9a7 | 164 | describe('Upload', function () { |
0e1dc3e7 | 165 | |
1eddc9a7 C |
166 | it('Should upload the video with the correct token', async function () { |
167 | const videoAttributes = {} | |
168 | await uploadVideo(server.url, accessToken, videoAttributes) | |
169 | const res = await getVideosList(server.url) | |
a1587156 | 170 | const video = res.body.data[0] |
0e1dc3e7 | 171 | |
1eddc9a7 C |
172 | expect(video.account.name).to.equal('root') |
173 | videoId = video.id | |
174 | }) | |
175 | ||
176 | it('Should upload the video again with the correct token', async function () { | |
177 | const videoAttributes = {} | |
178 | await uploadVideo(server.url, accessToken, videoAttributes) | |
179 | }) | |
0e1dc3e7 C |
180 | }) |
181 | ||
1eddc9a7 | 182 | describe('Ratings', function () { |
22834691 | 183 | |
1eddc9a7 C |
184 | it('Should retrieve a video rating', async function () { |
185 | await rateVideo(server.url, accessToken, videoId, 'like') | |
186 | const res = await getMyUserVideoRating(server.url, accessToken, videoId) | |
187 | const rating = res.body | |
c100a614 | 188 | |
1eddc9a7 C |
189 | expect(rating.videoId).to.equal(videoId) |
190 | expect(rating.rating).to.equal('like') | |
191 | }) | |
c100a614 | 192 | |
1eddc9a7 C |
193 | it('Should retrieve ratings list', async function () { |
194 | await rateVideo(server.url, accessToken, videoId, 'like') | |
22834691 | 195 | |
2d53be02 | 196 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200) |
22834691 | 197 | const ratings = res.body |
0e1dc3e7 | 198 | |
1eddc9a7 | 199 | expect(ratings.total).to.equal(1) |
a1587156 C |
200 | expect(ratings.data[0].video.id).to.equal(videoId) |
201 | expect(ratings.data[0].rating).to.equal('like') | |
1eddc9a7 | 202 | }) |
0e1dc3e7 | 203 | |
1eddc9a7 C |
204 | it('Should retrieve ratings list by rating type', async function () { |
205 | { | |
206 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') | |
207 | const ratings = res.body | |
208 | expect(ratings.data.length).to.equal(1) | |
209 | } | |
210 | ||
211 | { | |
212 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') | |
213 | const ratings = res.body | |
214 | expect(ratings.data.length).to.equal(0) | |
215 | } | |
216 | }) | |
0e1dc3e7 C |
217 | }) |
218 | ||
1eddc9a7 C |
219 | describe('Remove video', function () { |
220 | it('Should not be able to remove the video with an incorrect token', async function () { | |
2d53be02 | 221 | await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401) |
1eddc9a7 | 222 | }) |
0e1dc3e7 | 223 | |
1eddc9a7 | 224 | it('Should not be able to remove the video with the token of another account') |
0e1dc3e7 | 225 | |
1eddc9a7 C |
226 | it('Should be able to remove the video with the correct token', async function () { |
227 | await removeVideo(server.url, accessToken, videoId) | |
228 | }) | |
0e1dc3e7 C |
229 | }) |
230 | ||
1eddc9a7 | 231 | describe('Logout', function () { |
7fed6375 C |
232 | it('Should logout (revoke token)', async function () { |
233 | await logout(server.url, server.accessToken) | |
234 | }) | |
0e1dc3e7 | 235 | |
7fed6375 | 236 | it('Should not be able to get the user information', async function () { |
2d53be02 | 237 | await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) |
7fed6375 | 238 | }) |
0e1dc3e7 | 239 | |
7fed6375 | 240 | it('Should not be able to upload a video', async function () { |
2d53be02 | 241 | await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401) |
7fed6375 | 242 | }) |
0e1dc3e7 | 243 | |
1eddc9a7 C |
244 | it('Should not be able to rate a video', async function () { |
245 | const path = '/api/v1/videos/' | |
246 | const data = { | |
247 | rating: 'likes' | |
248 | } | |
0e1dc3e7 | 249 | |
1eddc9a7 C |
250 | const options = { |
251 | url: server.url, | |
252 | path: path + videoId, | |
253 | token: 'wrong token', | |
254 | fields: data, | |
2d53be02 | 255 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 |
1eddc9a7 C |
256 | } |
257 | await makePutBodyRequest(options) | |
258 | }) | |
0e1dc3e7 | 259 | |
e1c55031 | 260 | it('Should be able to login again', async function () { |
f43db2f4 C |
261 | const res = await login(server.url, server.client, server.user) |
262 | server.accessToken = res.body.access_token | |
263 | server.refreshToken = res.body.refresh_token | |
264 | }) | |
265 | ||
266 | it('Should be able to get my user information again', async function () { | |
267 | await getMyUserInformation(server.url, server.accessToken) | |
268 | }) | |
269 | ||
270 | it('Should have an expired access token', async function () { | |
271 | this.timeout(15000) | |
272 | ||
273 | await setTokenField(server.internalServerNumber, server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) | |
274 | await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) | |
275 | ||
276 | killallServers([ server ]) | |
277 | await reRunServer(server) | |
278 | ||
279 | await getMyUserInformation(server.url, server.accessToken, 401) | |
280 | }) | |
281 | ||
282 | it('Should not be able to refresh an access token with an expired refresh token', async function () { | |
283 | await refreshToken(server, server.refreshToken, 400) | |
e1c55031 | 284 | }) |
0e1dc3e7 | 285 | |
f43db2f4 C |
286 | it('Should refresh the token', async function () { |
287 | this.timeout(15000) | |
288 | ||
289 | const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString() | |
290 | await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', futureDate) | |
0e1dc3e7 | 291 | |
f43db2f4 C |
292 | killallServers([ server ]) |
293 | await reRunServer(server) | |
294 | ||
295 | const res = await refreshToken(server, server.refreshToken) | |
296 | server.accessToken = res.body.access_token | |
297 | server.refreshToken = res.body.refresh_token | |
298 | }) | |
1eddc9a7 | 299 | |
e1c55031 C |
300 | it('Should be able to get my user information again', async function () { |
301 | await getMyUserInformation(server.url, server.accessToken) | |
302 | }) | |
0e1dc3e7 C |
303 | }) |
304 | ||
1eddc9a7 | 305 | describe('Creating a user', function () { |
ce5496d6 | 306 | |
1eddc9a7 C |
307 | it('Should be able to create a new user', async function () { |
308 | await createUser({ | |
309 | url: server.url, | |
310 | accessToken: accessToken, | |
311 | username: user.username, | |
312 | password: user.password, | |
313 | videoQuota: 2 * 1024 * 1024, | |
3487330d | 314 | adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST |
1eddc9a7 C |
315 | }) |
316 | }) | |
a76138ff | 317 | |
1eddc9a7 C |
318 | it('Should be able to login with this user', async function () { |
319 | accessTokenUser = await userLogin(server, user) | |
320 | }) | |
a76138ff | 321 | |
1eddc9a7 C |
322 | it('Should be able to get user information', async function () { |
323 | const res1 = await getMyUserInformation(server.url, accessTokenUser) | |
ac0868bc | 324 | const userMe: MyUser = res1.body |
1eddc9a7 | 325 | |
76314386 | 326 | const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true) |
1eddc9a7 C |
327 | const userGet: User = res2.body |
328 | ||
329 | for (const user of [ userMe, userGet ]) { | |
330 | expect(user.username).to.equal('user_1') | |
331 | expect(user.email).to.equal('user_1@example.com') | |
332 | expect(user.nsfwPolicy).to.equal('display') | |
333 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
334 | expect(user.roleLabel).to.equal('User') | |
335 | expect(user.id).to.be.a('number') | |
336 | expect(user.account.displayName).to.equal('user_1') | |
337 | expect(user.account.description).to.be.null | |
338 | } | |
339 | ||
340 | expect(userMe.adminFlags).to.be.undefined | |
3487330d | 341 | expect(userGet.adminFlags).to.equal(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST) |
29128b2f RK |
342 | |
343 | expect(userMe.specialPlaylists).to.have.lengthOf(1) | |
ac0868bc | 344 | expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER) |
76314386 RK |
345 | |
346 | // Check stats are included with withStats | |
347 | expect(userGet.videosCount).to.be.a('number') | |
348 | expect(userGet.videosCount).to.equal(0) | |
349 | expect(userGet.videoCommentsCount).to.be.a('number') | |
350 | expect(userGet.videoCommentsCount).to.equal(0) | |
4f32032f C |
351 | expect(userGet.abusesCount).to.be.a('number') |
352 | expect(userGet.abusesCount).to.equal(0) | |
353 | expect(userGet.abusesAcceptedCount).to.be.a('number') | |
354 | expect(userGet.abusesAcceptedCount).to.equal(0) | |
1eddc9a7 | 355 | }) |
ce5496d6 C |
356 | }) |
357 | ||
1eddc9a7 | 358 | describe('My videos & quotas', function () { |
11474c3c | 359 | |
1eddc9a7 | 360 | it('Should be able to upload a video with this user', async function () { |
5600def4 | 361 | this.timeout(10000) |
0e1dc3e7 | 362 | |
1eddc9a7 C |
363 | const videoAttributes = { |
364 | name: 'super user video', | |
365 | fixture: 'video_short.webm' | |
366 | } | |
367 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | |
368 | }) | |
afffe988 | 369 | |
1eddc9a7 C |
370 | it('Should have video quota updated', async function () { |
371 | const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) | |
372 | const data = res.body | |
0e1dc3e7 | 373 | |
1eddc9a7 | 374 | expect(data.videoQuotaUsed).to.equal(218910) |
0e1dc3e7 | 375 | |
1eddc9a7 | 376 | const resUsers = await getUsersList(server.url, server.accessToken) |
0e1dc3e7 | 377 | |
1eddc9a7 C |
378 | const users: User[] = resUsers.body.data |
379 | const tmpUser = users.find(u => u.username === user.username) | |
380 | expect(tmpUser.videoQuotaUsed).to.equal(218910) | |
381 | }) | |
0e1dc3e7 | 382 | |
1eddc9a7 C |
383 | it('Should be able to list my videos', async function () { |
384 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) | |
385 | expect(res.body.total).to.equal(1) | |
0e1dc3e7 | 386 | |
1eddc9a7 C |
387 | const videos = res.body.data |
388 | expect(videos).to.have.lengthOf(1) | |
afffe988 | 389 | |
a1587156 | 390 | const video: Video = videos[0] |
a18f275d C |
391 | expect(video.name).to.equal('super user video') |
392 | expect(video.thumbnailPath).to.not.be.null | |
393 | expect(video.previewPath).to.not.be.null | |
1eddc9a7 | 394 | }) |
cca1e13b C |
395 | |
396 | it('Should be able to search in my videos', async function () { | |
397 | { | |
398 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video') | |
399 | expect(res.body.total).to.equal(1) | |
400 | ||
401 | const videos = res.body.data | |
402 | expect(videos).to.have.lengthOf(1) | |
403 | } | |
404 | ||
405 | { | |
406 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto') | |
407 | expect(res.body.total).to.equal(0) | |
408 | ||
409 | const videos = res.body.data | |
410 | expect(videos).to.have.lengthOf(0) | |
411 | } | |
412 | }) | |
5600def4 C |
413 | |
414 | it('Should disable webtorrent, enable HLS, and update my quota', async function () { | |
415 | this.timeout(60000) | |
416 | ||
417 | { | |
418 | const res = await getCustomConfig(server.url, server.accessToken) | |
419 | const config = res.body as CustomConfig | |
420 | config.transcoding.webtorrent.enabled = false | |
421 | config.transcoding.hls.enabled = true | |
422 | config.transcoding.enabled = true | |
423 | await updateCustomSubConfig(server.url, server.accessToken, config) | |
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 | }) |