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